dzsave How to preserve fluorescent image color #4431
Replies: 5 comments
-
Hello @gracezheng9, Deepzoom doesn't have a way to tag one-band images as being in a colour, so you need to generate your own RGB image from the mono fluorescence channel. The best way to do this is to make a look-up table which maps the 0-255 values from the mono file to a set of RGBs forming the colour gradient you want. For example: #!/usr/bin/env python
import sys
import pyvips
tint = [0, 255, 127]
# turn to CIELAB
tint = (pyvips.Image.black(1, 1) + tint).colourspace("lab", source_space="srgb")
tint = [x.avg() for x in tint.bandsplit()]
# start with an RGB greyscale, then go to LAB
lab = pyvips.Image.identity(bands=3).colourspace("lab", source_space="srgb")
# scale to 0-1 and make a weighting function
x = lab[0] / 100
weight = 1 - 4.0 * ((x - 0.5) * (x - 0.5))
# we want L to stay the same, we just weight ab
lab = lab[0].bandjoin((weight * tint)[1:])
# and turn to sRGB
lut = lab.colourspace("srgb", source_space="lab")
image = pyvips.Image.new_from_file(sys.argv[1], access="sequential")
image = image.maplut(lut)
image.write_to_file(sys.argv[2]) If I have this test image: I can run:
To make: In your case, you'd need to use |
Beta Was this translation helpful? Give feedback.
-
Hi @jcupitt Thank you so much for your quick response! I tried your method, and it appears that the resulting image is a "lighter" green and the bright spots became brighter compared to what QuPath renders. Whereas I performed some really crude transformations via:
and the resulting images look much more similar to what QuPath renders, basically identical. Would you know why this is the case? The .ome.tiff image we have only has 1 band: Apologies we cannot share our images as they are microscopy images. |
Beta Was this translation helpful? Give feedback.
-
The code I posted is probably closer to the "right" way to colourize a monochrome image, and should be closer to what you'd see looking down a microscope. If you need to match the output from QuPath, a simpler approach might be better (as you say). pyvips supports constants like image = pyvips.Image.new_from_file(filename)
image *= [0.0, 1.0, 127.0 / 255.0]
image.dzsave(...) For each pixel, that'll cast to float, do three float multiplies, then cast back during the save. You can make it a lot quicker with perhaps: lut = pyvips.Image.identity(bands=3).copy(interpretation="srgb")
lut *= [0.0, 1.0, 127.0 / 255.0]
lut = lut.cast("uchar")
image = pyvips.Image.new_from_file(filename)
image.maplut(lut).dzsave(...) Now it's just a table lookup for each pixel and there's no casting to and from float. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the help! Will do that! Another question I had - I used
on an 16026 x 27735 image, and I get levels 0 - 5 which corresponds to the entire pyramid levels of 10-15. However, upon inspecting the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am new to vips, looking for guidance on conversion from .ome.tiff to deepzoom for fluorescent images.
I was able to easily do so via
However, the original .ome.tiff image included a tag in the xml,
<Channel Color="16744447" </Channel>
which translates to (0, 255, 127) rgb according to https://forum.image.sc/t/color-tag-in-ome-tiff-xml/48106/2. But the converted AVIF files are greyscale instead of the fluorescent green color.How can I make
dzsave
preserve the green color?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions