Login  Register

Re: How to use line selection and count the number of specific colored pixels on either sides of the line?

Posted by Brandon Hurr on Jan 08, 2016; 6:42pm
URL: http://imagej.273.s1.nabble.com/How-to-use-line-selection-and-count-the-number-of-specific-colored-pixels-on-either-sides-of-the-lin-tp5015347p5015351.html

Do you already have a method for counting yellow and brown/black pixels
within an ROI?

When you draw a line, you can use getLine(x1, y1, x2, y2, lineWidth); to
get the attributes of that line.

Then compute the slope and intercept of your line and create a selection
from that.

run("Select None"); //Selecting nothing just in case
setTool(4);                     //Line Tool
message= "Line Selection Required\n Please create a break line";
waitForUser(message);

getLine(x1, y1, x2, y2, lineWidth);

dx = x2-x1; // change in x
dy = y2-y1; // change in y

if (dx == 0) {
slope = 1; // can't divide by 0
} else {
slope = dy / dx;
}

intercept = slope * x1 - y1;

print(x1 + ", " + y1);
print(x2 + ", " + y2);
print(intercept);
print(slope);

hgt = getHeight();
wth = getWidth();

print(hgt);
print(wth);

xAty0point = abs((0-intercept) / slope); // -y = 0
xAtyMaxpoint = wth + (hgt-intercept) / slope; // -y = hgt

print(xAty0point + ", " + 0);
print(xAtyMaxpoint + ", " + hgt);

makePolygon(xAty0point, 0, xAtyMaxpoint, hgt, wth, hgt, wth, 0);

print(xAty0point+ ", " + 0+ "  " + xAtyMaxpoint+ ", " + hgt+ "  " + wth+ ",
" + hgt+ "  " + wth+ ", " + 0);

roiManager("Add");
run("Make Inverse");
roiManager("Add");
run("Make Inverse");

// ROI[0] should be right side of line
// ROI[1] should be left side


HTH,
B




On Fri, Jan 8, 2016 at 7:03 AM, ram prasad <[hidden email]> wrote:

> Dear All,
>
> I would like to know how to do the following in imageJ.
>
> I'm trying to get the number of yellow and black coloured pixels on either
> sides of a line, which will be drawn by me using the line selection tool.
> I'm attaching one such image wherein I have drawn the line for your
> reference.
>
> I know how to how use the thresholder to get at the counts of yellow and
> black pixels in the whole image but I don't know how to go about this. I
> googled to see if anyone else had done something similar but the examples I
> found usually involved splitting the whole image into two equal halves
> based on the image dimensions. I don't think it is possible in my case as
> the coordinates of the line cannot be deduced from the image dimensions.
>
> I'd really appreciate it if you could let me know how to go about this or
> if you can suggest a different approach.
>
> Let me know if you need any more details from my side.
>
> Thank you very much.
>
> Cheers,
> Ram
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html