Mark only ROI with threshold intensity

imagej

#1

Hello everyone,

I can’t find a solution for the following:

I have a slices with one to two ROIs. I would like to depict it with a determined threshold.
My problem is, that a certain threshold of intensities always colours the whole
slice. I only want the region inside the ROI in this slice to be coloured. (see image attached: only the region inside the yellow ROI should appear red)

Do you have an idea how to illustrate it?

Looking forward hearing from you all, have a nice evening,

tarantina


#2

Do you want to measure the the thresholded area in the ROI only or do you want to illustrate the selections?

ImageJ does restrict the measurements to an selected area, e.g., if a selection in the image is active.

But with a particle analysis (Analyze->Analyze Particles…) ImageJ will only measure thresholded sections in a selection or seperate it further by size and roundness if you like (below you see a selected thresholded area and the outlined result from a particle measurement):


#4

Hey Bio7,
thanks for your fast answer.

I do not want to measure, I only want to get an illustration to demonstrate the extension of colouring.
For this purpose, I want to show a first picture before applying the threshold value (just grey values) and then a second picture with the threshold (appears here in red). In this second image, I’m looking for a way to let only the region inside the yellow ROI appear red.

Hope I got my idea across you guys, looking forward hearing from you,

tarantina


#5

Hey Praveen,
I think you gave the first step to the solution, thank you!
Do you have an idea, how to merge the two pictures?

Cheers,

tarantina

PS: Praveens suggestion: Edit > Clear Outside, then merge. I get the picture below on the right side by pressing Clear Outside after applying the threshold


#6

Create the selection, then press F for filling it in the foreground colour.

If you want to fill it in colour, not greyscale, convert the image first to RGB then select the colour with the colour picker and press F (assuming that the ROI is set).


#7

@tarantina
Sorry,i deleted my post as i was not sure if that is what you wanted. But you can try what Gabriel suggested to merge your thresholded image on your original image.


#8

To complement the previous answers you can also create an Overlay from your selection:

Image->Overlay->Add Selection.

The Overlay is non destructive and can be enabled and disabled in an image.

In the properties dialog you have some options to fill or outline the shape with a specific color:

Image->Overlay->Overlay Options… (press Apply)

With the command

Image->Overlay->Flatten

you can “burn” the result into a new image and remove the overlay from the default image with:

Image->Overlay->Remove Overlay

Documentation Overlays:

https://imagej.net/docs/guide/146-11.html


#9

Hey Gabriel and everyone else,

I tried your suggestions thank you. Unfortunately, both possibilities don’t show what I intend to show (=merging the two pictures from my third post):

When I create the selection (=ROI?) in a normal 16 bit image slide, then apply the threshold and then press “F” I get the picture on the left side.
When I convert the image before into RBG Color (Image > Type > RBG Color) and then create the ROI and press “F”, I get the picture on the right side. It’s not possible to depict the threshold here.

I would like apply the threshold and then create a picture where the threshold is only displayed inside the ROI, not outside.

Thank you all,

tarantina


#10

Hey Bio7 and everybody,
thanks for your answer. I’m still struggling to implement it:

I mark one ROI that includes some coloured pixels due to the threshold
-> I press Image->Overlay->Add Selection
-> I can’t find a way to fill it in the same ROI without marked threshold values.

When I press “Flatten”, there only opens a new slide with the ROI with a fatter border,

When I press “Add” in the ROI Manager and then Image ->Overlay ->From ROI Manager i get the picture below, without colours and the subdivision is also not exactely correct (seen below in the right picture
)

I could image that I already make a mistake with the “selection”? What do you mean by it? The ROI?

Cheers,

tarantina


#11

The picture in the right is what I understood you wanted: the ROI has the threshold inside it. What else do you want?


#12

Hey,

no, the right picture I put in my reply post to you doesn’t show the threshold inside it. The ROI is completely filled out with red but doesn’t depict the threshold intensity value that I want to present.
Below again the example I want to put in a totally uncoloured sourrounding.
Furthermore, I can’t apply the threshold tool as soon as I convert the picture to RBG Color.

The right picture I posted in my reply post to BIO7 doesn’t illustrate the threshold neither. The inside borders don’t correlate with the red marks on the left image.

Cheers,
tarantina


#13

I see, a picture is still worth 1000 words.
To do that you can do something like:

run("Bridge (174K)");
makeRectangle(29, 91, 39, 33);
setAutoThreshold("Default dark");
run("Make Inverse");
setForegroundColor(0, 0, 0);
run("Fill", "slice");
run("Make Inverse");

#14

Hey gabriel,

I don’t get this script running, I’m sorry, I’m not so experienced in prgramming, don’t know which language, what to write before etc.
If no one has other suggestions I give photoshop2 a try.

Cheers,
tarantina


#15

It is a macro script. Go to Plugins>New>Macro and copy in that new window the text in the script.
Crtl+R runs the macro or use the commands in the menu bar.


#16

Just a quick follow up. You do not need to write a script, but I showed there what is needed.
Once the ROI is set, then “Make inverse” the selection (which now contains everything except the original ROI pixels) and fill it with black. Then Make Inverse again.


#17

Hi Tarantina,

I was kind of looking for a similar macro to measure and save the analysis of collagen content of atherosclerotic lesions. I could not find it, so I made a macro for it. I can imagine you don’t need it anymore since your post was some time ago, but for other people that need to do similar analysis it might be useful. So what the macro does is:

  • First you can select the area you are interested in. For me that is first the vessel area that I want to measure and make it a ROI (ROI 0) and give it a red line (everything outside of it I don’t need, so in the macro the outside of this ROI is cleared).

  • Then I only want the plaque, so I select everything with the freehand tool outside the plaque area but inside the red line and delete with backspace, and select the plaque area based on the green background color filter and make it a ROI (ROI 1) and measure it. (magenta, a bit sloppy but you get the idea)

  • Then I want to know the collagen content (blue) of the plaque and select that with another color filter, and make it a ROI (ROI 2), and measure it.

  • So then I have all the ROIs I need but my original picture is green except for the plaque area. So the macro closes the image and reopens it so the original image is there. The ROIs are still present in the ROI editor, then the macro displays all on the image, then the image is flattened and safed in the same folder as " original image name analyzed.tif". So this is then my before analysis and after analysis picture.

For you, you probably don’t need all of the selection steps. So make your ROIs and clear everything outside, then select all (this is important so your’re ROIs are eventually ending up at the same spot in your picture) and do your thresholding and make a ROI from that and fill with some color. Then close your image window and reopen, select the ROIs you want to display and flatten. You can also modify the macro below to your needs.

title = "Trichrome macro"
msg = "Open image file, image area is calculated in pixels to calculate area size multiply with pixel size."
waitForUser(title, msg);
run("Open...");
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
run("Set Measurements...", "area area_fraction display scientific redirect=None decimal=3");
setBackgroundColor(0, 255, 0)
roiManager("show none")
//setTool("freehand");
title = "Vessel outline"
msg = "Trace the outline of the vessel and press OK."
waitForUser(title, msg)
roiManager("Add");
roiManager("Select", 0);
roiManager("Rename", "Vessel outline");
roiManager("Set Color", "red");
roiManager("Set Line Width", 2);
roiManager("measure");
roiManager("Select", 0);
setBackgroundColor(0, 255, 0);
roiManager("Deselect");
roiManager("show all")
title = "Delete non plaque"
msg = "Use selection tools and backspace to remove all non plaque tissue"
waitForUser(title, msg)
roiManager("Select", 0);
run("Clear Outside");
//setTool("freehand");
imgName=getTitle(); 
selectWindow(imgName); 
run("Select All");
run("Duplicate...", "title=2.tif")
run("Color Threshold...");
// Deselect background
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("RGB Stack");
run("Convert Stack to Images");
selectWindow("Red");
rename("0");
selectWindow("Green");
rename("1");
selectWindow("Blue");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=255;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=255;
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-------------

run("8-bit"); 
run("Create Selection"); 
selectWindow(imgName); 
run("Restore Selection"); 
roiManager("Add");
roiManager("Select", 1);
roiManager("Rename", "plaque");
run("Make Inverse");
roiManager("measure");
setBackgroundColor(0, 255, 0)
close("Color Threshold...")
close("2.tif")

//setTool("rectangle");
imgName=getTitle(); 
selectWindow(imgName); 
run("Select All");
run("Duplicate...", "title=3.tif")
selectWindow("3.tif")
run("Color Threshold...");
// Filter Settings trichrome
// 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]=134;
max[0]=211;
filter[0]="pass";
min[1]=39;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=144;
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-------------

run("8-bit"); 
run("Create Selection"); 
selectWindow(imgName); 
run("Restore Selection"); 
roiManager("Add");
roiManager("Select", 2);
roiManager("Rename", "Trichrome");
roiManager("measure");
setBackgroundColor(0, 255, 0)
close ("3.tif")
close("Color Threshold...")
title = "Check analysis"
msg = "An image of the analysis is automatically saved, change filter settings if needed"
waitForUser(title, msg)
roiManager("select", 1)
Roi.setFillColor(255,0,255);
roiManager("select", 2)
Roi.setFillColor(0, 0, 255)
selectWindow(imgName)
close();
open(imgName)
Path=getDirectory(imgName)
NoExt=File.nameWithoutExtension
roiManager("show all without labels");
run("Flatten");
rename(NoExt + "analyzed.tif");
close(imgName);
save(Path + NoExt + "analyzed.tif");
close(NoExt + "analyzed.tif");
roiManager("Select", newArray(0,1,2));
roiManager("delete")

#18

Hi Tarantina!

Maybe it’s a little late for a quick answer, but it could help someone else with the same issue.
Here’s my take on the problem:

  1. Starting point: you have one or more ROIs created in the RoiManager.

  2. Set the threshold as desired.

  3. Run the command “Create Selection” and add the resulting ROI to the RoiManager. This will create a ROI of the red thresholded part of the image.

  4. Select in the RoiManager both one of your ROIs and the new threshold ROI

  5. From the “More” drop-down menu in the RoiManger run the “AND” command, then add the resulting ROI to the RoiManager. This ROI will contain the thresholded area within your original ROI.

  6. Select this new ROI in the manager, press “Properties” and set the fill color to red (or whatever you like).

  7. Repeat for all of your ROIs, then delete the threshold ROI from step 2, and reset the threshold of the image.

  8. Finally, run a “Select None” command to deselect everything and then run the “Flatten” command, to create a new image with the ROIs drawn permanently.

It goes without saying that this new image is useless for any quantification purposes, and is only useful for illustration.

Cheers!
Nico