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

Using imread for Ophys Projections automatically casts them to floats #2672

Open Ahad-Allen opened 1 year ago

Ahad-Allen commented 1 year ago

Describe the bug 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.

To Reproduce Calling the from_lims() function of the projections.py file of the sdk will cause this problem. The offending code is in line 53: img = mpimg.imread(filepath)

Expected behavior The SDK should probably use the Image class from PIL to handle this instead: img = PILImage.open(filepath) This will preserve the integer representation of the new projection files, and should still work with the older floating point projection files.

Actual Behavior The returned image is represented as a 0-1 floating point number.

Environment (please complete the following information):

Additional context This likely affects newer Ophys projects internally exclusively, as the older ones still rely on projections with a 0-1 floating point representation.

Do you want to work on this issue? I have no problems working on the issue.