I’m trying to do color thresholding of DAB stained image to measure the blue and brown areas. I am able to use the color threshold in Fiji, but because I have other pre and post scripts I’m trying to replicate in opencv how color threshold works.
I have code that comes close to what the plugin does, but am probably some key step that would make it simpler. Here is the sequence I’ve tried:
- convert to float32 before converting to lab space (without this the roundtrip bgr–>lab–>bgr gets lots of differences)
- transform to lab space
- normalize to 0-255 l/a/b, like imagej UI shows
- apply thresholds in lab space. This is where it gets tricky. The opencv methods for threshold set values to 0/255. However we need value to be say 127 since 0 and 255 are blue/yellow or green/red extremes. Also for pixels outside threshold I would like them to be white, like imagej has an option, so L is set to 255. So all this requires some convoluted code.
- renormalize back to -127 +126 range and convert to bgr and then to greyscale
- use thresholding in grayscale to get back to BW image
At this point I expect a roughly matching output, but its either fully white or black or has strange colors which tells me something didnt go right!
In step 4, if I iterate over each pixel in code and set them appropriately, and some additional masking, I get matching output. But there must be a better way?