Closed DirkRemmers closed 4 years ago
Hi Dirk,
Thanks for the info! As far as I can tell, you aren't missing anything.. I only had a handful of lif files (from only a few microscopes) to test this software on. Would you be able to send me that lif file so I can try to find the bug? If you don't want to post it publicly, you can message me on twitter (listed in my profile).
It's possible that this is related to the bit depth of the images. I know that lif files can be 16-bit, but I didn't have any images to test that on. Do you happen to know the bit-depth of the image? I would still need to fix the code, but it would be a place to start.
-Nick
Hey Nick,
I sent you a message on Twitter, thank you for the help! I don't know the bit-depth of the image at the moment. Hopefully you can see something in the file I sent you :).
Thanks, Dirk
Hi Dirk,
I got the image, thanks for sending it along. It looks like a 16-bit image, which would explain why the output looks so strange. I'll try to have a fix in a few days, I think this should be pretty straightforward!
-Nick
Hi Nick,
Sounds good, I'm looking forwards to it!
Thank you, Dirk
Hi Dirk,
I had some time today to work on this, good timing!
I think I've fixed the issue in the new release, 0.3.0 (it should be up on pypi now). You'll need to update Pillow to >= 7.2.0 for this version. One of the challenges here is that your image is a 12 bit image (max value 4096), inside a 16-bit container (max value 65,536). If you're just dealing with the numbers, it's not a big deal, but if you try to display the image it'll look really dim.
I didn't want this software to try to silently do any scaling of the data, so you'll have to do it after the fact if you want. An example is below. The readme has been updated with this example. You'll need numpy to do the scaling.
from readlif.reader import LifFile
import numpy as np
from PIL import Image
new = LifFile(filename)
img_0 = new.get_image(5)
# Assumes all channels have the same bit depth
scale_factor = (16 - img_0.bit_depth[0]) ** 2
frame = img_0.get_frame(z=6, t=0, c=1)
img_array = np.uint16(np.array(frame) * scale_factor)
Image.fromarray(img_array).show()
Would I be able to include a stripped-down version of your file (a single frame of a two-channel image) in the test suite of a future release? If you would rather not, that's fine too! I won't share any part of the file without your permission.
-Nick
Hey Nick,
Thank you very much for solving the issue! Of course you can use this stripped down version!
Cheers, Dirk
Hello Nick,
I'm trying to open a lif file and look at the image afterwards, but some strange lines appear on the image. Is this incompatibility with the image format/version or am I missing something else? I added an example of what I'm seeing. The used code is posted below.
Thank you, Dirk