Colour thresholding

Hi all,

I was looking at ways to do colour thresholding inside KNIME, however I found no suitable method. Therefore I turned to FIJI for help. I set the colour threshold there, and let FIJI make a macro from that. The produced macro I entered into KNIME using the macro node. However this throws the error that not all plug-ins are available. Any thoughts on which ones are missing, otherwise I would be forced to dig through the entire folders. Something I'm not really looking forward too ;).

Here is the Macro:

// Color Thresholder 2.0.0-rc-43/1.50e
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=25;
max[0]=255;
filter[0]="pass";
min[1]=84;
max[1]=190;
filter[1]="pass";
min[2]=107;
max[2]=211;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Colour Thresholding-------------

 

PS. a way to do this in KNIME is also welcome ofcourse ;)

Hi,

honestly, I didn't look into how to get the Fiji-Macro running, but I assembled a KNIME-workflow that hopefully does a similar thing (see attachment).

One remark: Since our Global Thresholder-node unfortunately doesn't allow one to specify min-max-thresholds, yet (it can only configured with one threshold -> but I opened an issue and maybe it's going to be possible in the future). But I worked around it. So don't be surprised to see these Wrapped Metanodes called 'Min-Max-Value-Threshold'. They do what they should, but they are actually subworkflows that you can configure like a normal node.

Just let us know if that doesn't work out for you or you need further help.

Best,

Martin

Hi Martin,

Thanks a lot, it works like a charm.

Luuk

Hi Martin,

Is there also a way to combine the three channels back to a single image again?

Luuk

"Merger" might be the node of choice.

Hi Christian,

I was also looking into that, but I think that only works for RGB channels. My channels are HSB, is there perhaps a setting I am missing?

 

Luuk

Ah, to render it? Currently, we can't render HSB.

 

Until there will be an HSB to RGB Image node, you could probably use an ImageJ macro just for the conversion back to RGB. The complex thing is that you have to create a new image in ImageJ, convert it to an HSB stack, paste your channels in there, and convert it back to RGB:

run("Stack to RGB");
run("RGB Stack");
inputID = getImageID();
getDimensions(width, height, channels, slices, frames);
newImage("Output", "RGB black", width, height, 1);
run("HSB Stack");

resultID = getImageID();
selectImage(inputID);
setSlice(1);
run("Copy");
selectImage(resultID);
setSlice(1);
run("Paste");
selectImage(inputID);
setSlice(2);
run("Copy");
selectImage(resultID);
setSlice(2);
run("Paste");
selectImage(inputID);
setSlice(3);
run("Copy");
selectImage(resultID);
setSlice(3);
run("Paste");

run("RGB Color");
run("Make Composite");

I attached a workflow that illustrates this.


Hope that helps,

Jan

Thanks for your effort, I'll take a look at it after the weekend.

The 'Colorspace Converter' node also allows you to convert HSB back to RGB.

Oh sure, I missed that (was just taking Christians "we can't render HSB" fro granted ;-).

And it's of course much better than ImageJ because its working on FloatType instead of ImageJ 1.x's 8-bit per channel :)

Thanks

I gave it a propper test today, but the results are quiet disappointing. Attached are screenshots of how my thresholding works in FIJI and in KNIME. Results are far from comparable. Any suggestion on how to improve?

Also I attached the workflow.

Hi Luuk,

could you please also attach the two images your workflow is working on?

(or alternatively attach the workflow with the image reader executed and the data exported)

I found them, they are not to big, so I attached them here.

Hi Luuk,

 

when using the same setting as in your ImageJ screenshot (70-130, 70-255, 90-255), I get pretty much the same result after calculating `min(H, min(S, B))` with the Image Calculator (see attached screenshot).

I would actually recommend to not convert to UnsignedByteType but instead use the threshold on the raw float channels instead (meaning the you'd have to use different numbers, of course).

 

Cheers,

Jan

 

Hi Jan, that looks just like I wanted it to be. I forgot the calculation step. However if I build the formula it gives an error regarding empty strings. Could you provide me with your formula from the image calculator node?

Luuk

 

PS. Never mind, I forgot to enter a name for the output table. The error message was a bit ambiguous.

pps. Do you happen to know a formula to convert the values, to avoid recalculating the image?

Do you happen to know a formula to convert the values, to avoid recalculating the image?

Do you mean the values to use as thresholds on the float image? As far as I can see, the Color Space Converter returns channel in the range of 0.0-1.0, whereas in ImageJ (and on UnsignedByteImages) you are using 8-bit per channel, so a 0-255 range. It should be sufficient to divide your numbers by 255 to get the desired ranges.

Thanks Jan
 

Hi Martin,

I updated this workflow to avoid converting to Unsinged Byte Type. Instead I devide the inserted values by 255 using Java edit variable within all meta nodes.

Luuk

Hi Luuklag,

Looks like you did, almost exactly what I'm trying to do.  Create a workflow to analyze plant growth over time.  Any chance you want to share your finished workflow?  It would be much appreciated!