Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Physical Pixel Size from SEM TIFF metadata. #558

Open
gyger opened this issue May 21, 2024 · 1 comment
Open

Extract Physical Pixel Size from SEM TIFF metadata. #558

gyger opened this issue May 21, 2024 · 1 comment

Comments

@gyger
Copy link

gyger commented May 21, 2024

Use Case

I use the library to open TIFF images create by SEM systems, in my Case FEI or now ThermoFischer. The tifffile library extracts the metadata but in AICSImageIO the metadata is only available in the numeric index {34680, 34682, 34683} depending on the tool.

For Zeiss this key would be {34118,}.

I am wondering if there is a wish to extract the physical pixel size from this metadata automatically and perhaps provide the metadata.

Solution

The physical pixel size is automatically read from the metadata in the TIFF file.

Alternatives

Create a new class basing on AICSImage, that sets the Physical Pixel size.

class SPMImage (aicsimageio.AICSImage):
   """
   """
   def __init__(self,         
               image: aicsimageio.types.ImageLike,
               reader: Optional[Type[aicsimageio.readers.reader.Reader]] = aicsimageio.readers.TiffReader,
               reconstruct_mosaic: bool = True,
               mask_nonvalid_data: bool = False,
               fs_kwargs: Dict[str, Any] = {},
               **kwargs: Any,):
      
      # Load Image
      super().__init__(image, reader, reconstruct_mosaic, fs_kwargs, **kwargs)
      self.mask_nonvalid_data = mask_nonvalid_data

      #FEI.
      fei_keys = {34680, 34682, 34683} & self.metadata.keys() # FEI_SFEG or FEI_HELIOS or FEI_TITAN
      if len(fei_keys) == 1: 
         self.metadata['FEI'] = self.metadata.pop(fei_keys.pop())
         self.reader._physical_pixel_sizes = aicsimageio.types.PhysicalPixelSizes(None, 
                                                                                  self.metadata['FEI']['Scan']['PixelHeight'], 
                                                                                  self.metadata['FEI']['Scan']['PixelWidth'])
         
      zeiss_keys = {34118,} & self.metadata.keys() # Carl Zeiss SEM
      if len(zeiss_keys) == 1: 
         self.metadata['ZEISS'] = self.metadata.pop(zeiss_keys.pop())

      self.metadata['DatabarHeight'] = self.metadata['FEI']['PrivateFei']['DatabarHeight']
@toloudis
Copy link
Collaborator

Thank you for this issue. I suggest looking at
https://github.com/bioio-devs/bioio-tifffile/blob/main/bioio_tifffile/reader.py#L579
and maybe you can make a pull request that modifies that file to add a check for these specific fields.
If it is possible for you, we suggest migrating to bioio as aicsimageio is in maintenance mode.
The api is basically the same and migration should be fairly easy.

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

No branches or pull requests

2 participants