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 11, 2016; 3:58pm
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-tp5015347p5015361.html

Sure, but I don't have the time this week to implement so it's up to you or
someone else.

I would select none, then duplicate your image twice (LEFT and RIGHT).

Select LEFT
select ROI 0
Set foreground color 0,0,255
Fill
select none
run your segmentation as normal

Repeat for RIGHT, selecting ROI1 and filling it.

HTH,
B


On Mon, Jan 11, 2016 at 2:17 AM, ram prasad <[hidden email]> wrote:

> Thank you very much for your reply guys. I really appreciate it.
>
> Many thanks for the macro, Brandon. It does exactly what I wanted to do.
> However, I do not know how to get the number of pixels of a specific colour
> within an ROI. If I was doing the same on the whole image, then I would
> open thresholder and use hue slider to select the yellow pixels and inverse
> the selection to capture the black pixels. And then do a measure to get the
> area. Simple. But I just tried it and realized that I can't employ the same
> approach for an ROI selection. I googled to see if I could find something
> on that but I had no luck there. Could you give me some pointers on how to
> go about it?
>
> Cheers,
> Ram
>
> On Fri, Jan 8, 2016 at 7:51 PM, Brandon Hurr <[hidden email]>
> wrote:
>
> > 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
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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