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 ed_10-1-2.jpg (502K) Download Attachment |
Dear Ram,
there are several solutions... 1. Use the polygon tool and select one of its sides like the separating line and the others according to the image borders. Count the pixels in this selection, then invert the selection and count again. 2. Do the math, i.e. determine the co-ordinates of the separating line and with them create the above polygon selection by a macro. HTH Herbie :::::::::::::::::::::::::::::::::::::::: Am 08.01.16 um 16:03 schrieb ram prasad: > 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 |
In reply to this post by ram prasad
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 |
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 |
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 |
Hi Ram,
the attached simple macro demonstrates how yellow and black pixels can be 'classified' and counted based on a simple color conversion and thresholding. Use it as a starting point. Use the <Image/Color/Split Channels> command and the <Image Calculator...> to create an R*G Image to see the effect and to determined the threshold. To run the following macro a straight line must be selected in the image. Adjust the parameters shift, thresh and the value in "Enlarge..." according to your needs. Maybe this helps .. Peter // ******************* Counting Pixels in LineArea selection by color value ******************************* shift = 30; thresh = 125; yI = 0; bI = 0; yII = 0; bII = 0; if ( selectionType() == 5 ){ // is straight line run("Line to Area"); run("Enlarge...", "enlarge=1"); getSelectionBounds(x, y, width, height); // Line I setSelectionLocation(x-shift, y); // Shift LineArea selection to the left getSelectionCoordinates(xC, yC); for (i=0; i<xC.length; i++){ v = getPixel(xC[i], yC[i]); red = (v>>16)&0xff; // extract red byte (bits 23-17) green = (v>>8)&0xff; // extract green byte (bits 15-8) //blue = v&0xff; // extract blue byte (bits 7-0) tmp = red*green/255; if (tmp > thresh) // Compare product RG with threshold yI++; else bI++; } // Line II setSelectionLocation(x+shift, y); // Shift LineArea selection to the right getSelectionCoordinates(xC, yC); for (i=0; i<xC.length; i++){ v = getPixel(xC[i], yC[i]); red = (v>>16)&0xff; // extract red byte (bits 23-17) green = (v>>8)&0xff; // extract green byte (bits 15-8) //blue = v&0xff; // extract blue byte (bits 7-0) tmp = red*green/255; if (tmp > thresh) // Compare product RG with threshold yII++; else bII++; } print("yI : " + yI); print("bI : " + bI); print("yII : " + yII); print("bII : " + bII); } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |