Skip to content
Snippets Groups Projects
Commit 677d1402 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Used more universal meta field for pixel scale, now a dict

parent 60a3e66e
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ class GenericImageDataAccessor(ABC): ...@@ -48,7 +48,7 @@ class GenericImageDataAccessor(ABC):
@property @property
def pixel_scale_in_micrometers(self): def pixel_scale_in_micrometers(self):
return None return {}
@property @property
def dtype(self): def dtype(self):
...@@ -176,15 +176,12 @@ class CziImageFileAccessor(GenericImageFileAccessor): ...@@ -176,15 +176,12 @@ class CziImageFileAccessor(GenericImageFileAccessor):
@property @property
def pixel_scale_in_micrometers(self): def pixel_scale_in_micrometers(self):
meta_sc_str = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['ImageScaling']['ImagePixelSize'] scale_meta = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['Scaling']['Items']['Distance']
meta_mags = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['ImageScaling']['ScalingComponent'] sc = {}
sc_xy = list(map( for m in scale_meta:
float, if m['DefaultUnitFormat'].encode() == b'\xc2\xb5m' and m['Id'] in self.shape_dict.keys(): # literal mu-m
meta_sc_str.split(',') sc[m['Id']] = m['Value'] * 1e6
)) return sc
assert sc_xy[0] == sc_xy[1]
mags = [float(m['Magnification']) for m in meta_mags]
return sc_xy[0] / np.product(mags)
def write_accessor_data_to_file(fpath: Path, accessor: GenericImageDataAccessor, mkdir=True) -> bool: def write_accessor_data_to_file(fpath: Path, accessor: GenericImageDataAccessor, mkdir=True) -> bool:
......
...@@ -114,4 +114,5 @@ class TestCziImageFileAccess(unittest.TestCase): ...@@ -114,4 +114,5 @@ class TestCziImageFileAccess(unittest.TestCase):
def test_read_in_pixel_scale_from_czi(self): def test_read_in_pixel_scale_from_czi(self):
cf = CziImageFileAccessor(czifile['path']) cf = CziImageFileAccessor(czifile['path'])
self.assertAlmostEqual(cf.pixel_scale_in_micrometers, czifile['um_per_pixel'], places=3) pxs = cf.pixel_scale_in_micrometers
\ No newline at end of file self.assertAlmostEqual(pxs['X'], czifile['um_per_pixel'], places=3)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment