AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
333 stars 149 forks source link

Bugfix/im read #2682

Closed Ahad-Allen closed 1 year ago

Ahad-Allen commented 1 year ago

Overview:

Currently, the projections.py code for ophys projections uses imread to process the image paths it receives from LIMS. This is problematic, as the images are were changed to be integer representations for newer experiments are normalized from 0-255. Because the images are png files, imread will automatically cast them to float32 values ranging from 0-1.

Addresses:

Issue https://github.com/AllenInstitute/AllenSDK/issues/2672

Sample inputs/outputs

For experiment 1194754135 , here is a comparison of the table generated in an NWB file for the average image.

Using imread: image

With the updated code: image

Note the change from floating points to unsigned ints.

Type of Fix:

Solution:

Using img = PILImage.open(filepath) preserves the integer representation of the new projection files, and should still work with the older floating point projection files.

Changes:

replaced imread for projections to PILImage

Validation:

Generated an NWB file that passes validation by dandi

aamster commented 1 year ago

@Ahad-Allen can you please show example inputs/outputs in the description of the PR that shows that the current code normalizes to range [0,1] and coerces dtype to float whereas Image.open keeps uint8 dtype?

Can you add a unit test that tests your expected behavior, that an image file saved as uint8 and read using Projection._from_filepath keeps the range/dtype the same?

It looks like there's changes unrelated to this in the PR. Can you please remove those changes?