Plot Profile from Line ROIs

Hi everyone,

This is my first post here. First, I want to thank everyone for all the info and troubleshooting available in this forum. It has helped me tremendously to learn some basics of writing macros and automating some basic image analysis.

I’m putting together a small macro to identify lines along some structures and add each to the ROI manager (I’m using “Ridge Detection” from Biomedgroup"). I get this:

lines

I then want to cycle through each ROI (a line) and get a plot profile on a second channel, get some peaks information (I’m using Find Peaks, from BAR) and go on from there.

The problem I’m having is that to transfer the ROI to the second channel I do:

for (j=0 ; j<roiManager("count"); j++) {
    roiManager("select", j);
    run("Create Mask");
    selectWindow("Mask");
    run("Create Selection");
    run("Make Inverse");
    selectWindow("MAX_" + "C1-" + a);
    run("Restore Selection");
    // and so on with my analysis
}

But, the run(“Create Selection”); command creates a line around the pixels I want to measure, instead of maintaining a line. See below, the image on the left. This is incompatible with the “Plot Profile” function, which requires either a line or a rectangle:

Untitled%202

I’ve spent the last couple of days trying to find out how to apply a ROI Line to another channel, without it becoming an area, but I’ve been completely defeated…

Any help is much appreciated.

Thanks!

So I think you are doing a lot of extra work that you don’t need to do…

ROIs and selections are essentially interchangeable in ImageJ. Once you select an ROI that IS a selection on your image that you can use to plot profile. Additionally ROIs are automatically transferable - as soon as you select another channel or image, the ROI will measure there instead of the image it was created on.

So I think you should just be having to do something like below:

for (j = 0 ; j < roiManager(“count”); j++) {
selectWindow(“MAX_” + “C1-” + a);
roiManager(“select”, j);
run("Plot Profile");
}

Sorry if i’m misinterpreted your problem but hopefully it’s helpful!

Good luck,
Laura

2 Likes

Yup, that totally solves my problem. I’m amazed how I kept on insisting on the wrong workaround.

Still, not sure why a “line ROI” becomes the area defined by the pixels it crosses when converting it to a mask, but I guess that is a problem that won’t haunt me anymore.

Thanks so much!

1 Like