Skip to content

improvment of the cellvizio reader: reading meta informations from hexcode directly#150

Merged
maubreville merged 6 commits intomasterfrom
improvment_cellvizio.py
Feb 5, 2026
Merged

improvment of the cellvizio reader: reading meta informations from hexcode directly#150
maubreville merged 6 commits intomasterfrom
improvment_cellvizio.py

Conversation

@stabiloSlin
Copy link
Collaborator

directly reading meta informations from hex code.
Also added more informations of the MKT file to the UI info panel.

exact_improvment

Copilot AI review requested due to automatic review settings February 5, 2026 12:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request improves the CellVizio MKT file reader by extracting metadata information directly from the file content rather than using hardcoded values. The changes enable reading image dimensions, frame rate, field of view, and patient ID from embedded metadata, and expose this information through properties for display in the UI.

Changes:

  • Replaced hardcoded width/height/fps values with dynamic metadata extraction from MKT file content
  • Added getMetaInfo() and getMostRelevantMetaInfo() methods to parse metadata from file
  • Added meta_data and meta_data_dict properties to expose metadata for UI display

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +82
self.mpp_x = self.fovx/self.fi.width # approximate number for gastroflex, 250 ym field of view, 576 px
self.mpp_y = self.fovy/self.fi.height
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential division by zero if width or height metadata is missing or zero. The mpp_x and mpp_y calculations will fail if self.fi.width or self.fi.height is 0 (which would happen if the metadata keys are not found, since the default is 0). Add validation to ensure width and height are non-zero before performing these calculations, or provide sensible fallback values.

Copilot uses AI. Check for mistakes.
Comment on lines 101 to 103
metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=')
metaEnd = fileContent.find(b'<CEND', metaStart)
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8')
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the '<CEND' marker is not found, find() will return -1, resulting in an incorrect slice that includes content from the start position to near the beginning of the file. Add validation to check if metaEnd is -1 and handle this case appropriately.

Suggested change
metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=')
metaEnd = fileContent.find(b'<CEND', metaStart)
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8')
metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=')
if metaStart == -1:
# expected metadata start marker not found
self.fileHandle.close()
print("Meta information start marker 'allowed_egain_eoffset_pairs=' not found.")
return ""
metaEnd = fileContent.find(b'<CEND', metaStart)
if metaEnd == -1:
# expected metadata end marker not found
self.fileHandle.close()
print("Meta information end marker '<CEND' not found.")
return ""
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8')
self.fileHandle.close()

Copilot uses AI. Check for mistakes.

self.fovx = float(meta.get('fovx', 250))
self.fovy = float(meta.get('fovy', 250))
print(f"fovx: {self.fovx}, fovy: {self.fovy}")
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This print statement should be removed or replaced with proper logging. Use logger.debug() instead for debug output in production code.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, let's do this with the next commit.

# find start position with fileContent.find(b'allowed_egain_eoffset_pairs=') that searches for the byte sequence
metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=')
metaEnd = fileContent.find(b'<CEND', metaStart)
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8')
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decode operation assumes UTF-8 encoding but provides no error handling if the metadata contains invalid UTF-8 sequences. Consider adding error handling with errors='ignore' or errors='replace' parameter, or catching UnicodeDecodeError to handle corrupted metadata gracefully.

Suggested change
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8')
metaInfo = fileContent[metaStart:metaEnd].decode('utf-8', errors='replace')

Copilot uses AI. Check for mistakes.
Comment on lines 115 to 128
key, value = line.split('=')
if key == 'framerate':
relevantInfo['framerate'] = value
relevantInfo['duration_seconds'] = self.fi.nImages / float(relevantInfo['framerate'])
elif key == 'width':
relevantInfo['width'] = value
elif key == 'height':
relevantInfo['height'] = value
elif key == 'fovx':
relevantInfo['fovx'] = value
elif key == 'fovy':
relevantInfo['fovy'] = value
elif key == 'patient_id':
relevantInfo['patient_id'] = value
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key from the split operation is not stripped of whitespace, which could cause comparison failures if there's any leading or trailing whitespace in the metadata. Consider using key.strip() when comparing against expected key names to make the parsing more robust.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally not a problem in MKT File format.

@stabiloSlin
Copy link
Collaborator Author

With this code, we now have a better functionality of different MKT image sizes, because we now have access to the correct image width and height of the MKT file, instead of hard coding the size.

maubreville and others added 5 commits February 5, 2026 14:08
See copilot comment, it's sensible to close the filehandle after using it.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed print statement

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Maybe not essential, but also doesn't hurt.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added caching for meta_data

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
remove old code

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@maubreville
Copy link
Collaborator

Nice feature :-)

@maubreville maubreville merged commit 485d085 into master Feb 5, 2026
1 check passed
@maubreville maubreville deleted the improvment_cellvizio.py branch February 5, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants