labsyspharm / ashlar

ASHLAR: Alignment by Simultaneous Harmonization of Layer/Adjacency Registration
https://labsyspharm.github.io/ashlar/
MIT License
118 stars 42 forks source link

Ashlar fails if ome.tiff data is float32 #172

Open joaomamede opened 1 year ago

joaomamede commented 1 year ago

In the ome.tiff metadata the pixel type is "float" while numpy conversion is np.float32.

$ ashlar Cycle0.companion.ome Cycle1.companion.ome -c0

Stitching and registering input images
Cycle 0:
    reading Cycle0.companion.ome
WARNING: Stage coordinates' measurement unit is undefined; assuming μm.
    assembling thumbnail 1/439Traceback (most recent call last):
  File "/home/jmamede/anaconda3/envs/tensorflow/bin/ashlar", line 8, in <module>
    sys.exit(main())
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 212, in main
    return process_single(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 243, in process_single
    edge_aligner.run()
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 486, in run
    self.make_thumbnail()
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 497, in make_thumbnail
    self.reader.thumbnail = thumbnail.make_thumbnail(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/thumbnail.py", line 20, in make_thumbnail
    img = reader.read(c=channel, series=i)
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 431, in read
    img = self.reader.read(series, c)
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 405, in read
    dtype = self.metadata.pixel_dtype
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 304, in pixel_dtype
    return self._pixel_dtypes[self._metadata.getPixelsType(0).value]
KeyError: 'float'

I tried to comment line 405 in reg.py

# dtype = self.metadata.pixel_dtype to
dtype = np.float32

and the error goes away. if I try to do something like

        if dtype == 'float':
            dtype = np.float32
            print('manually changing dtype')

It still fails as the error happens at the moment of the self.metadata_pixel_dtype call.

joaomamede commented 1 year ago

Same later when appending the mosaic:

Traceback (most recent call last):
  File "/home/jmamede/anaconda3/envs/tensorflow/bin/ashlar", line 8, in <module>
    sys.exit(main())
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 212, in main
    return process_single(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 250, in process_single
    mosaics.append(reg.Mosaic(edge_aligner, mshape, **mosaic_args_final))
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 996, in __init__
    self.dtype = aligner.metadata.pixel_dtype
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 304, in pixel_dtype
    return self._pixel_dtypes[self._metadata.getPixelsType(0).value]
KeyError: 'float'
joaomamede commented 1 year ago

By modifying line 200-203 to:

class BioformatsMetadata(PlateMetadata):

    _pixel_dtypes = {
        'uint8': np.dtype(np.uint8),
        'uint16': np.dtype(np.uint16),
        'float' : np.dtype(np.float32),
    }

made it go through.

However, the output is between 0 and 1 and very saturated. I believe it to be the light correction. I also tried pushing the 'float' be assume to be a uint32 or uint16 dtype and the same happens.