Outlining certain peri-lesion region

imagej

#1

How can I outline a peri-lesion region with a distance of 200µm from the lesion?
Thanks in advance


#2

Good day,

I fear that without a typical raw image in the original TIF- or PNG-format*, you won’t get any helpful replies …

*No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.

Regards

Herbie


#3

Hi there,

You can make a ROI of your lesion region and add it to the ROI Manager. You then go to Edit>Selection>Enlarge… and enlarge it by 200 microns (depending on the calibration of your image it may not let you do it in one step and you may have to repeat the process with smaller increases, for example 50 microns four times). Add this ROI to the Manager and then select both ROIs, click More>XOR to subtract the lesion area from the enlarged ROI and the result should be your peri-lesion area. You can then add it to the Manager and save it.

I hope this helps


#4

Dear,

The TIF file I want to upload is to big, so unfortunately it isn’t possible to post this image.
The result I become when I try your method (@jmazario), isn’t the one I expected. So maybe I do something wrong or maybe the method isn’t good for this kind of counting.

Regards,
Kaat


#5

Good day Kaat,

then please post an image with reduced spatial resolution and clearly indicate what you wish to obtain, otherwise we can’t help.

Are your images RGB or multicolor/multichannel images and what size in pixel^2 do they have?

Regards

Herbie


#6

Dear,

I finally could upload it via PNG format. So I hope someone can help me now.

Regards,
Kaat


#7

Please do us a favour and post a copy of this image and draw onto it what you like to see.

Presently, I have no idea

Herbie


#8

Black is the lesion and red the peri-lesion. I would like to have a peri-lesion distance of exact 200µm from the lesion, but I don’t know how to do it in the most precise way.

Regards


#9

Thanks for the details!

The first step should be to trace the lesion contour which won’t be easy and I suppose that it isn’t drawn by hand. Please confirm!

The second step concerns the peri-lesion line at 200µm distance to the lesion contour which should pose to many problems, given the first step is done.

Did you already succeed in setting the scale to your image according to the scale-bar?

I shall try to find a way for step one.

Regards

Herbie


#10

Dear,

What I have drawn now is done by hand. I don’t see another option. I think I’ve done that. I just put a scale of 5mm on the figure (which is 1380 pixels) and convert it to 276 pixels/mm.

Regards,
Kaat


#11

Hi Kaat,

Here is how you can do it:

Lesion area:

Enlarged:

Peri-lesion area step 1:

This is what you should get if you follow the instructions I gave you. Now you have to clear the part of the ROI that is outside the tissue. To do that, just draw a ROI that overlaps with the part you want to remove while pressing the Alt key (that subtracts that part from the ROI). And then you get:

Of course, the first thing you should do is to calibrate the image.

I used jpeg files because I don’t think it’s necessary for this to upload such big files. I hope it is not a problem.

Hope this helps


#12

Here is what I’ve got by automatic tracing:
3-1-a-1_traces

The trace in cyan was generated by a commercial ImageJ-plugin without any pre-processing of the image. One has to define the starting x-position only and some parameters that define the smoothing and thresholding.

The yellow line was produce by shifting the cyan contour by 55.32 pixels that correspond to 200µm.

Regards

Herbie


#13

Dear,

@jmazario: my outlined area does not enlarge. If I do it like you said, I have to fill in via edit>selection>enlarge 0,2mm (200µm), but it doesn’t enlarge with that number.

Regards,
Kaat


#14

Kaat,

here is the result of a better approach which doesn’t shift the traced contour but enlarges it.
3-1-a_tracesX

The smoothing observed with the yellow line may be tolerable.

Regards

Herbie


#15

Hi Kaat,

For this to work you need the outline of the lesion region to be a closed profile, not just an open line. Look at the first picture I sent. Could that be the problem?


#16

Kaat,

if you have an excerpt of the lesion area similar to the one I used before (outside to the top of the image), and if you have a hand-drawn “Freehand Line”-selection of the lesion contour, then you can use the following ImageJ-macro to get the peri-lesion contour:

setBatchMode(true);
drawOverlay( "cyan" );
getSelectionCoordinates(xpoints, ypoints);
xpoints = Array.concat(xpoints,xpoints[xpoints.length-1],xpoints[0]);
ypoints = Array.concat(ypoints,0,0);
makeSelection("polygon", xpoints, ypoints);
run("Enlarge...", "enlarge=55"); // 200µm = 55.32pel
drawOverlay( "yellow" );
run("Select None");
setBatchMode(false);
exit();
function drawOverlay( color ) {
	roiManager("Add");
	roiManager("Set Color", color);
	roiManager("Set Line Width", 2);
	run("Add Selection...");
}

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

HTH

Herbie


#17

Hi Herbie,

That’s a nice piece of code but it doesn’t work that well in the whole image. I’ve run it several times in the test image and this is the result:

It would be great if you could get it to work properly. It would be a great macro to add to our library. I’ll give it a shot too, but I think I’ve failed when I tried before. I can’t find a way to automatically remove the part of the ROI that falls outside the tissue.

Thank you,

Javi


#18

Good day Javi,

please read carefully!

[…] if you have an excerpt of the lesion area similar to the one I used before (outside to the top of the image) […]

This requirement is essential!

That’s a nice piece of code but it doesn’t work that well in the whole image.

Of course!

Perhaps you try it as I’ve described …

Regards

Herbie

PS:
As I’ve written as well, the original lesion contour must not be a closed selection (polygon) but a Freehand line.

PPS:
For those who like to test my macro, here

3-1-a_excerptLesionContour.tif.zip (132.7 KB)

is the excerpt from the sample image with the lesion contour as polyline selection.
(Just un-zip this file and open the image in ImageJ. Make sure the selection is visible in the image. Then paste my macro code to an empty macro window “Plugins >> New >> Macro” and run it.)


#19

Hi there,

Sorry, Herbie. I was so eager to test the macro that I didn’t realize that you had already said that it would only work under that very specific set of conditions. My bad.

As I said before, I’ve previously tried (and failed) to write a macro that would enlarge the edge of a lesion to incorporate a peri-lesion area. I’ve given it a go again and came out with a code that will, if not fix the problem completely, at least reduce the amount of interaction that it requires to just a couple of steps. It should work in images acquired under similar conditions than the sample image and with the same magnification (BEWARE: the macro will calibrate the images to 0.2766 px/µm).

For the macro to work properly, it’s necessary to follow some rules:

  1. The image you want to work with should be open before you run the macro.

  2. When it prompts you to draw the lesion area, draw it as precisely as you can in the lesion/peri-lesion interface but close it back by going through an area free of tissue (see the first image I sent in a previous post). Use the Polygon selection tool or the Freehand selection tool. Do not use Segmented line or Freehand line because it will not work.

The result should be a ROI encircling the peri-lesion area. This ROI could be containing some parts outside the tissue. It should be easy enough to prune them out by drawing an overlapping ROI on the parts you want to remove while pressing the “Alt” key (that, will subtract the ROI you are drawing from the peri-lesion ROI).

Once you are happy with the result you can add it to the ROI manager (Ctrl+t) and/or draw it into the image (Edit>Draw).

I haven’t been able to make it work better than this. Any insights on how to improve it would be very welcome.

I am aware there are some code lines that are unnecessary, but they will only increase the running time of the macro by a few milliseconds.

Well, and after all this writing, here is the code:

title = getTitle;
run("Set Scale...", "distance=55.32 known=200 unit=µm"); //Calibrates the image in µm
setTool("polygon");	// Sets the "Polygon selections" tool. "Freehand selecions" should work too. Not "Freehand line"
waitForUser ("Draw the lesion area and THEN press OK. \nMake sure it is a closed region");
roiManager("Add");
roiManager("Select", 0);
roiManager("Rename", "Lesion");
run("Enlarge...", "enlarge=200");
roiManager("Add");
roiManager("Select", 1);
roiManager("Rename", "Enlarged");
roiManager("Select", newArray(0,1));
roiManager("XOR");
roiManager("Delete");
roiManager("Add");
roiManager("Select", 0);
roiManager("Rename", "Peri-lesion big");
roiManager("Add");
roiManager("Delete");
selectWindow(title); 
run("Duplicate...", " ");
run("8-bit");
setAutoThreshold("Huang");
run("Analyze Particles...", "size=1000000-Infinity include add in_situ"); //Creates a ROI with all the tissue area
roiManager("Select", 1);
run("Make Inverse");
roiManager("Add");
roiManager("Delete");
roiManager("Select", 1);
roiManager("Rename", "Outside");
roiManager("Select", newArray(0,1));
roiManager("XOR");
roiManager("Add");
roiManager("Select", 2);
roiManager("Select", newArray(0,2));
roiManager("AND");
roiManager("Add");
roiManager("Select", 3);
roiManager("Rename", "Peri-lesion");
roiManager("Select", 2);
roiManager("Select", 0);
roiManager("Delete");
close();
selectWindow(title);
roiManager("Select", 0);
roiManager("Delete");
roiManager("Select", 0);
roiManager("Delete");
roiManager("Select", 0);
//setForegroundColor(255, 255, 0);  //These three last lines are commented out because the final ROI may need some "prunning" before drawing it
//run("Line Width...", "line=2");
//roiManager("Draw");

Just copy it and paste it into an empty macro window (Plugins>New>Macro) and run it after opening the image to analyze.

I hope this is useful.

Cheers,

Javi


#20

[…] under that very specific set of conditions.

Nothing specific, from my point of view, you only need to turn the original sample image by 90 degrees and that’s it.
Did you have a look at the example image excerpt that I’ve posted as zip-file?
Try my macro with this image!

If you prefer the whole image, here is the result as JPG:

Please note that the lesion contour (cyan) is not hand-drawn.

Regards

Herbie