From f81612af25281d1f073700d4cb89cc93cc2082cf Mon Sep 17 00:00:00 2001 From: stabiloSlin Date: Thu, 5 Feb 2026 13:55:02 +0100 Subject: [PATCH 1/6] improvment cellvizio reader: reading meta informations from hexcode directly --- exact/util/cellvizio.py | 86 +++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/exact/util/cellvizio.py b/exact/util/cellvizio.py index cb0bc1b7..49fe1500 100644 --- a/exact/util/cellvizio.py +++ b/exact/util/cellvizio.py @@ -52,27 +52,21 @@ def __init__(self,filename): self.fi = fileinfo() self.fileHandle = open(filename, 'rb'); self.fileHandle.seek(5) # we find the FPS at position 05 - fFPSByte = self.fileHandle.read(4) - self.fps = struct.unpack('>f', fFPSByte)[0] - - + # fFPSByte = self.fileHandle.read(4) + # self.fps = struct.unpack('>f', fFPSByte)[0] self.fileHandle.seek(10) # we find the image size at position 10 fSizeByte = self.fileHandle.read(4) self.fi.size = int.from_bytes(fSizeByte, byteorder='big', signed=True) - self.fi.nImages=1000 - - self.fi.width = 576 - if ((self.fi.size/(2*self.fi.width))%2!=0): - self.fi.width=512 - self.fi.height=int(self.fi.size/(2*self.fi.width)) - else: - self.fi.height=int(self.fi.size/(2*self.fi.width)) - self.filestats = stat(self.fileName) + self.fi.nImages=1000 self.fi.nImages = int((self.filestats.st_size-self.fi.offset) / (self.fi.size+self.fi.gapBetweenImages)) - self.numberOfFrames = self.fi.nImages - + + meta = self.getMostRelevantMetaInfo() + self.fi.width = int(meta.get('width', 0)) + self.fi.height = int(meta.get('height', 0)) + self.fps = float(meta.get('framerate', 0)) + self.geometry_imsize = [self.fi.height, self.fi.width] self.imsize = [self.fi.height, self.fi.width] self.geometry_tilesize = [(self.fi.height, self.fi.width)] @@ -80,8 +74,13 @@ def __init__(self,filename): self.geometry_columns = [1] self.levels = [1] self.channels = 1 - self.mpp_x = 250/576 # approximate number for gastroflex, 250 ym field of view, 576 px - self.mpp_y = 250/576 + + self.fovx = float(meta.get('fovx', 250)) + self.fovy = float(meta.get('fovy', 250)) + print(f"fovx: {self.fovx}, fovy: {self.fovy}") + 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 + # generate circular mask for this file self.circMask = circularMask(self.fi.width,self.fi.height, self.fi.width-2).mask @@ -91,6 +90,44 @@ def __init__(self,filename): openslide.PROPERTY_NAME_MPP_Y: self.mpp_y, openslide.PROPERTY_NAME_OBJECTIVE_POWER:20, openslide.PROPERTY_NAME_VENDOR: 'MKT'} + + + def getMetaInfo(self): + # the meta information at the MKT file always starts with "00616C6C 6F776564 5F656761 696E5F65 6F666673 65745F70 61697273 3D" or allowed_egain_eoffset_pairs= in the hex code + self.fileHandle = open(self.fileName, 'rb'); + # we need to read the whole file to find the meta information + fileContent = self.fileHandle.read() + # 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' Date: Thu, 5 Feb 2026 14:10:10 +0100 Subject: [PATCH 3/6] Update exact/util/cellvizio.py Removed print statement Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- exact/util/cellvizio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exact/util/cellvizio.py b/exact/util/cellvizio.py index d63ace4d..65b1d596 100644 --- a/exact/util/cellvizio.py +++ b/exact/util/cellvizio.py @@ -101,10 +101,9 @@ def getMetaInfo(self): metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=') metaEnd = fileContent.find(b' Date: Thu, 5 Feb 2026 14:11:11 +0100 Subject: [PATCH 4/6] Update exact/util/cellvizio.py Maybe not essential, but also doesn't hurt. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- exact/util/cellvizio.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/exact/util/cellvizio.py b/exact/util/cellvizio.py index 65b1d596..90110d53 100644 --- a/exact/util/cellvizio.py +++ b/exact/util/cellvizio.py @@ -113,8 +113,17 @@ def getMostRelevantMetaInfo(self): continue key, value = line.split('=') if key == 'framerate': - relevantInfo['framerate'] = value - relevantInfo['duration_seconds'] = self.fi.nImages / float(relevantInfo['framerate']) + value_str = value.strip() + try: + framerate = float(value_str) + except ValueError: + print(f"Warning: invalid framerate value in metadata: {value_str!r}") + continue + if framerate <= 0: + print(f"Warning: non-positive framerate value in metadata: {framerate}") + continue + relevantInfo['framerate'] = value_str + relevantInfo['duration_seconds'] = self.fi.nImages / framerate elif key == 'width': relevantInfo['width'] = value elif key == 'height': From 797b2e73acb005a83aad8231b6646865027566cd Mon Sep 17 00:00:00 2001 From: Marc Aubreville Date: Thu, 5 Feb 2026 14:21:29 +0100 Subject: [PATCH 5/6] Update exact/util/cellvizio.py Added caching for meta_data Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- exact/util/cellvizio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exact/util/cellvizio.py b/exact/util/cellvizio.py index 90110d53..9d211590 100644 --- a/exact/util/cellvizio.py +++ b/exact/util/cellvizio.py @@ -184,7 +184,10 @@ def _2_init__(self, filename): @property def meta_data(self) -> dict: - return self.getMostRelevantMetaInfo() + # Cache metadata to avoid repeated file I/O and parsing. + if not hasattr(self, "_meta_data_cache"): + self._meta_data_cache = self.getMostRelevantMetaInfo() + return self._meta_data_cache @property def meta_data_dict(self) -> dict: From abbe9181a35d698a9b17dc22b00a0bfb95594227 Mon Sep 17 00:00:00 2001 From: Marc Aubreville Date: Thu, 5 Feb 2026 14:21:56 +0100 Subject: [PATCH 6/6] Update exact/util/cellvizio.py remove old code Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- exact/util/cellvizio.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exact/util/cellvizio.py b/exact/util/cellvizio.py index 9d211590..92a424eb 100644 --- a/exact/util/cellvizio.py +++ b/exact/util/cellvizio.py @@ -52,8 +52,6 @@ def __init__(self,filename): self.fi = fileinfo() self.fileHandle = open(filename, 'rb'); self.fileHandle.seek(5) # we find the FPS at position 05 - # fFPSByte = self.fileHandle.read(4) - # self.fps = struct.unpack('>f', fFPSByte)[0] self.fileHandle.seek(10) # we find the image size at position 10 fSizeByte = self.fileHandle.read(4) self.fi.size = int.from_bytes(fSizeByte, byteorder='big', signed=True)