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

Add support for 32-bit float images. #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions readlif/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,32 @@ def _get_item(self, n):
else:
data = image.read(image_len)

# LIF files can be either 8-bit of 16-bit.
# LIF files can be either 8-bit, 16-bit or 32-bit.
# Because of how the image is read in, all of the raw
# data is already in 'data', we just need to tell Pillow
# how to set the bit depth
# 'L' is 8-bit, 'I;16' is 16 bit
# 'L' is 8-bit, 'I;16' is 16-bit, 'F' is 32-bit float.

# len(data) is the number of bytes (8-bit)
# However, it is safer to let the lif file tell us the resolution
if self.bit_depth[0] == 8:
return Image.frombytes("L",
(self.dims_n[self.display_dims[0]],
self.dims_n[self.display_dims[1]]),
data)
data_type = "L"
elif self.bit_depth[0] <= 16:
return Image.frombytes("I;16",
(self.dims_n[self.display_dims[0]],
self.dims_n[self.display_dims[1]]),
data)
data_type = "I;16"
elif self.bit_depth[0] == 32:
data_type = "F"
else:
raise ValueError("Unknown bit-depth, please submit a bug report"
" on Github")
raise ValueError(
"Unknown bit-depth, please submit a bug report on Github"
)

return Image.frombytes(
data_type,
(self.dims_n[self.display_dims[0]], self.dims_n[self.display_dims[1]]),
data,
)



def get_plane(self, display_dims=None, c=0, requested_dims=None):
"""
Expand Down