Hi All,
I have a person wanting to count the numbers of coloured pixels in her images. She has green, red and yellow and black. It's not colocalisation analysis that she is looking for. There seems to be a useful Plugin in development by Ben Pichette here: http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:start but no plugin as such yet. Just wondering if Ben is able to let me know if this plugin is soon to be released or alternatively, whether there is another plugin that can do this? The other option I was looking at to assist her was Threshold Colour. Any assistance would be very welcome. Kind regards, Jacqui Jacqueline Ross Biomedical Imaging Microscopist Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical & Health Sciences The University of Auckland Private Bag 92019 Auckland, NEW ZEALAND Tel: 64 9 373 7599 Ext 87438 Fax: 64 9 373 7484 http://www.fmhs.auckland.ac.nz/sms/biru/ |
Hi Jacqui,
It should be straightforward with a simple macro. You just have to decide what the cutoff is for a pixel to be "red" etc. Here is a quick macro: lower = 100; upper = 150; green = 0; red = 0; yellow = 0; black = 0; other = 0; for (y = 0; y < getHeight; y++) { for (x = 0; x < getWidth; x++) { v = getPixel(x,y); r = (v>>16)&0xff; // extract red byte (bits 23-17) g = (v>>8)&0xff; // extract green byte (bits 15-8) b = v&0xff; // extract blue byte (bits 7-0) if (r > upper && g > upper && b < lower) yellow++; else if (r < lower && g > upper && b < lower) green++; else if (r > upper && g < lower && b < lower) red++; else if (r < lower && g < lower && b < lower) black++; else other++; } } showMessage("Green = " + green + ", Red = " + red + ", Yellow = " + yellow + ", Black = " + black + ", Other = " + other); Regards, Curtis On Tue, May 17, 2011 at 2:01 AM, Jacqui Ross <[hidden email]>wrote: > Hi All, > > I have a person wanting to count the numbers of coloured pixels in her > images. She has green, red and yellow and black. It's not colocalisation > analysis that she is looking for. > > There seems to be a useful Plugin in development by Ben Pichette here: > http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:startbut no plugin as such yet. > > Just wondering if Ben is able to let me know if this plugin is soon to be > released or alternatively, whether there is another plugin that can do this? > The other option I was looking at to assist her was Threshold Colour. > > Any assistance would be very welcome. > > Kind regards, > > Jacqui > > Jacqueline Ross > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ > |
In reply to this post by Jacqueline Ross
Hi,
if you like to count only pixels of exactly defined colors, you could use my colorMask_.java plugin (code below). It operates on RGB images and will simply turn the selected color (by default the current drawing color) into white, all other colors into black. It is helpful, i.e. if you have drawn a set of non-overlapping ROIs using different colors onto a background image and want to create masks from it. Be careful, it operates directly on the current image (duplicate first)! Convert the resulting mask image into 8-bit, measure integrated density over the whole image and divide by 256 - you should get the number of pixels with your particular color by then. Best regards, Daniel import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; public class colorMask_ implements PlugInFilter { ImagePlus imp; Color maskCol; public int setup(String arg, ImagePlus imp) { this.imp = imp; maskCol = Toolbar.getForegroundColor(); return DOES_RGB; } public void run(ImageProcessor ip) { GenericDialog gd = new GenericDialog("Choose Mask Color"); gd.addNumericField("R", maskCol.getRed(), 0); gd.addNumericField("G", maskCol.getGreen(), 0); gd.addNumericField("B", maskCol.getBlue(), 0); gd.showDialog(); if (! gd.wasCanceled()) { // retrieve color maskCol = new Color( (int)gd.getNextNumber(), (int)gd.getNextNumber(), (int)gd.getNextNumber() ); for (int iSlice=1; iSlice <= imp.getNSlices(); iSlice++) { int[] px = (int[]) imp.getStack().getProcessor(iSlice).getPixels(); for (int iPx = 0; iPx < ip.getWidth() * ip.getHeight(); iPx++) { if (px[iPx] == maskCol.getRGB()) px[iPx] = 0xffffff; else px[iPx] = 0x000000; } } imp.updateAndDraw(); } } } On 17.05.2011, at 09:01, Jacqui Ross wrote: > Hi All, > > I have a person wanting to count the numbers of coloured pixels in her images. She has green, red and yellow and black. It's not colocalisation analysis that she is looking for. > > There seems to be a useful Plugin in development by Ben Pichette here: http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:start but no plugin as such yet. > > Just wondering if Ben is able to let me know if this plugin is soon to be released or alternatively, whether there is another plugin that can do this? The other option I was looking at to assist her was Threshold Colour. > > Any assistance would be very welcome. > > Kind regards, > > Jacqui > > Jacqueline Ross > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ |
Hi Daniel,
Thanks for your reply to my query. Unfortunately, the colours aren't rigidly defined so I'm not sure that the plugin will work for this analysis although it sounds like it will be useful for other applications. That's if I understand correctly, i.e. you need to know what the pixel values will be? Basically, the pixels will be red, green, yellow or black but the red and green combinations will vary, i.e. the grey values will be variable. However, I did try to create your plugin to try it out and got an error as below; C:\Program Files\ImageJ\plugins\Daniel.java:7: class colorMask_ is public, should be declared in a file named colorMask_.java public class colorMask_ implements PlugInFilter { ^ 1 error Is there something that I have done wrong? I thought perhaps there was a bracket missing. If you could check this and let me know, I would be interested in trying it out. Thanks. Kind regards, Jacqui Jacqueline Ross Biomedical Imaging Microscopist Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical & Health Sciences The University of Auckland Private Bag 92019 Auckland, NEW ZEALAND Tel: 64 9 373 7599 Ext 87438 Fax: 64 9 373 7484 http://www.fmhs.auckland.ac.nz/sms/biru/ -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Daniel Kalthoff Sent: Wednesday, 18 May 2011 5:18 a.m. To: [hidden email] Subject: Re: Color Pixel Counter - plugin Hi, if you like to count only pixels of exactly defined colors, you could use my colorMask_.java plugin (code below). It operates on RGB images and will simply turn the selected color (by default the current drawing color) into white, all other colors into black. It is helpful, i.e. if you have drawn a set of non-overlapping ROIs using different colors onto a background image and want to create masks from it. Be careful, it operates directly on the current image (duplicate first)! Convert the resulting mask image into 8-bit, measure integrated density over the whole image and divide by 256 - you should get the number of pixels with your particular color by then. Best regards, Daniel import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; public class colorMask_ implements PlugInFilter { ImagePlus imp; Color maskCol; public int setup(String arg, ImagePlus imp) { this.imp = imp; maskCol = Toolbar.getForegroundColor(); return DOES_RGB; } public void run(ImageProcessor ip) { GenericDialog gd = new GenericDialog("Choose Mask Color"); gd.addNumericField("R", maskCol.getRed(), 0); gd.addNumericField("G", maskCol.getGreen(), 0); gd.addNumericField("B", maskCol.getBlue(), 0); gd.showDialog(); if (! gd.wasCanceled()) { // retrieve color maskCol = new Color( (int)gd.getNextNumber(), (int)gd.getNextNumber(), (int)gd.getNextNumber() ); for (int iSlice=1; iSlice <= imp.getNSlices(); iSlice++) { int[] px = (int[]) imp.getStack().getProcessor(iSlice).getPixels(); for (int iPx = 0; iPx < ip.getWidth() * ip.getHeight(); iPx++) { if (px[iPx] == maskCol.getRGB()) px[iPx] = 0xffffff; else px[iPx] = 0x000000; } } imp.updateAndDraw(); } } } On 17.05.2011, at 09:01, Jacqui Ross wrote: > Hi All, > > I have a person wanting to count the numbers of coloured pixels in her images. She has green, red and yellow and black. It's not colocalisation analysis that she is looking for. > > There seems to be a useful Plugin in development by Ben Pichette here: http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:start but no plugin as such yet. > > Just wondering if Ben is able to let me know if this plugin is soon to be released or alternatively, whether there is another plugin that can do this? The other option I was looking at to assist her was Threshold Colour. > > Any assistance would be very welcome. > > Kind regards, > > Jacqui > > Jacqueline Ross > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ |
In reply to this post by ctrueden
Hi Curtis,
Thanks for your reply and for sending through the macro. It seems straightforward expect that I'm not sure how you determine the cutoff. I had a bunch of pixels that were classified as "other" so I need to adjust the cutoffs so that other = 0. I don't understand how you determine the bit values as below; r = (v>>16)&0xff; // extract red byte (bits 23-17) If you could explain this to me or refer me to an article/site, it would be very helpful. Kind regards, Jacqui Jacqueline Ross Biomedical Imaging Microscopist Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical & Health Sciences The University of Auckland Private Bag 92019 Auckland, NEW ZEALAND Tel: 64 9 373 7599 Ext 87438 Fax: 64 9 373 7484 http://www.fmhs.auckland.ac.nz/sms/biru/ -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Curtis Rueden Sent: Wednesday, 18 May 2011 3:04 a.m. To: [hidden email] Subject: Re: Color Pixel Counter - plugin Hi Jacqui, It should be straightforward with a simple macro. You just have to decide what the cutoff is for a pixel to be "red" etc. Here is a quick macro: lower = 100; upper = 150; green = 0; red = 0; yellow = 0; black = 0; other = 0; for (y = 0; y < getHeight; y++) { for (x = 0; x < getWidth; x++) { v = getPixel(x,y); r = (v>>16)&0xff; // extract red byte (bits 23-17) g = (v>>8)&0xff; // extract green byte (bits 15-8) b = v&0xff; // extract blue byte (bits 7-0) if (r > upper && g > upper && b < lower) yellow++; else if (r < lower && g > upper && b < lower) green++; else if (r > upper && g < lower && b < lower) red++; else if (r < lower && g < lower && b < lower) black++; else other++; } } showMessage("Green = " + green + ", Red = " + red + ", Yellow = " + yellow + ", Black = " + black + ", Other = " + other); Regards, Curtis On Tue, May 17, 2011 at 2:01 AM, Jacqui Ross <[hidden email]>wrote: > Hi All, > > I have a person wanting to count the numbers of coloured pixels in her > images. She has green, red and yellow and black. It's not colocalisation > analysis that she is looking for. > > There seems to be a useful Plugin in development by Ben Pichette here: > http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:startbut no plugin as such yet. > > Just wondering if Ben is able to let me know if this plugin is soon to be > released or alternatively, whether there is another plugin that can do this? > The other option I was looking at to assist her was Threshold Colour. > > Any assistance would be very welcome. > > Kind regards, > > Jacqui > > Jacqueline Ross > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ > |
In reply to this post by Jacqueline Ross
Hi Jacqui,
you have to either put the code into a file with the exact class name (colorMask_.java) or rename the class according to the file name. Colors in RGB images are iternally stored as one integer per pixel. To extract the red, green and blue values you have to use those bit operations (check the color picker macro on the ImageJ website). Best regards, Daniel Am 18.05.2011 um 08:44 schrieb Jacqui Ross <[hidden email]>: > Hi Daniel, > > Thanks for your reply to my query. Unfortunately, the colours aren't rigidly defined so I'm not sure that the plugin will work for this analysis although it sounds like it will be useful for other applications. That's if I understand correctly, i.e. you need to know what the pixel values will be? > > Basically, the pixels will be red, green, yellow or black but the red and green combinations will vary, i.e. the grey values will be variable. > > However, I did try to create your plugin to try it out and got an error as below; > > C:\Program Files\ImageJ\plugins\Daniel.java:7: class colorMask_ is public, should be declared in a file named colorMask_.java > public class colorMask_ implements PlugInFilter { > ^ > 1 error > > Is there something that I have done wrong? I thought perhaps there was a bracket missing. If you could check this and let me know, I would be interested in trying it out. > > Thanks. > > Kind regards, > > Jacqui > > Jacqueline Ross > > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ > > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Daniel Kalthoff > Sent: Wednesday, 18 May 2011 5:18 a.m. > To: [hidden email] > Subject: Re: Color Pixel Counter - plugin > > Hi, > > if you like to count only pixels of exactly defined colors, you could use my colorMask_.java plugin (code below). > > It operates on RGB images and will simply turn the selected color (by default the current drawing color) into white, all other colors into black. It is helpful, i.e. if you have drawn a set of non-overlapping ROIs using different colors onto a background image and want to create masks from it. Be careful, it operates directly on the current image (duplicate first)! > > Convert the resulting mask image into 8-bit, measure integrated density over the whole image and divide by 256 - you should get the number of pixels with your particular color by then. > > Best regards, > > Daniel > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.filter.*; > > public class colorMask_ implements PlugInFilter { > ImagePlus imp; > Color maskCol; > > public int setup(String arg, ImagePlus imp) { > this.imp = imp; > maskCol = Toolbar.getForegroundColor(); > return DOES_RGB; > } > > public void run(ImageProcessor ip) { > GenericDialog gd = new GenericDialog("Choose Mask Color"); > gd.addNumericField("R", maskCol.getRed(), 0); > gd.addNumericField("G", maskCol.getGreen(), 0); > gd.addNumericField("B", maskCol.getBlue(), 0); > gd.showDialog(); > if (! gd.wasCanceled()) { > // retrieve color > maskCol = new Color( (int)gd.getNextNumber(), (int)gd.getNextNumber(), (int)gd.getNextNumber() ); > for (int iSlice=1; iSlice <= imp.getNSlices(); iSlice++) { > int[] px = (int[]) imp.getStack().getProcessor(iSlice).getPixels(); > for (int iPx = 0; iPx < ip.getWidth() * ip.getHeight(); iPx++) { > if (px[iPx] == maskCol.getRGB()) px[iPx] = 0xffffff; else px[iPx] = 0x000000; > } > } > imp.updateAndDraw(); > } > } > } > > > On 17.05.2011, at 09:01, Jacqui Ross wrote: > >> Hi All, >> >> I have a person wanting to count the numbers of coloured pixels in her images. She has green, red and yellow and black. It's not colocalisation analysis that she is looking for. >> >> There seems to be a useful Plugin in development by Ben Pichette here: http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:start but no plugin as such yet. >> >> Just wondering if Ben is able to let me know if this plugin is soon to be released or alternatively, whether there is another plugin that can do this? The other option I was looking at to assist her was Threshold Colour. >> >> Any assistance would be very welcome. >> >> Kind regards, >> >> Jacqui >> >> Jacqueline Ross >> Biomedical Imaging Microscopist >> Biomedical Imaging Research Unit >> School of Medical Sciences >> Faculty of Medical & Health Sciences >> The University of Auckland >> Private Bag 92019 >> Auckland, NEW ZEALAND >> >> Tel: 64 9 373 7599 Ext 87438 >> Fax: 64 9 373 7484 >> >> http://www.fmhs.auckland.ac.nz/sms/biru/ |
In reply to this post by Jacqueline Ross
Hi Jacqui,
Every pixel of an RGB image is packed as an int, but contains 8 bits of "red," 8 bits of "green" and 8 bits of "blue." The macro extracts these components from the int (I copied the code from this example: http://imagej.nih.gov/ij/macros/tools/ColorPickerTool.txt), and stores them as r, g and b respectively. Then it checks whether the r, g and b components fit into certain ranges. The cutoffs I used in the macro (stored as "upper" and "lower") are totally arbitrary—I made them wide enough so that a lot of pixels would be classified as each color. For example, yellow is defined in computer color space as R+G, but without much B. The perfect yellow is R=255, G=255, B=0. But of course you want things that are merely "yellowish" so the macro checks for R>200, G>200, B<50. That's a range of yellows. It does the same thing for red (perfect red is R=255, G=0, B=0), and green (perfect green is R=0, G=255, B=0), and black (perfect black is R=0, G=0, B=0). But what if the pixel doesn't fall into any of the ranges? Then the macro classifies as "Other." If you have e.g. R=128, G=128, B=128 it would be disingenuous to call it anything else. However, if by "black" you mean "not red, yellow or green" then you could get rid of the "black" label and just have red, yellow, green and other. HTH, Curtis On Wed, May 18, 2011 at 1:49 AM, Jacqui Ross <[hidden email]>wrote: > Hi Curtis, > > Thanks for your reply and for sending through the macro. It seems > straightforward expect that I'm not sure how you determine the cutoff. I had > a bunch of pixels that were classified as "other" so I need to adjust the > cutoffs so that other = 0. > > I don't understand how you determine the bit values as below; > > r = (v>>16)&0xff; // extract red byte (bits 23-17) > > If you could explain this to me or refer me to an article/site, it would be > very helpful. > > Kind regards, > > Jacqui > > Jacqueline Ross > > Biomedical Imaging Microscopist > Biomedical Imaging Research Unit > School of Medical Sciences > Faculty of Medical & Health Sciences > The University of Auckland > Private Bag 92019 > Auckland, NEW ZEALAND > > Tel: 64 9 373 7599 Ext 87438 > Fax: 64 9 373 7484 > > http://www.fmhs.auckland.ac.nz/sms/biru/ > > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of > Curtis Rueden > Sent: Wednesday, 18 May 2011 3:04 a.m. > To: [hidden email] > Subject: Re: Color Pixel Counter - plugin > > Hi Jacqui, > > It should be straightforward with a simple macro. You just have to decide > what the cutoff is for a pixel to be "red" etc. > > Here is a quick macro: > > lower = 100; > upper = 150; > green = 0; > red = 0; > yellow = 0; > black = 0; > other = 0; > for (y = 0; y < getHeight; y++) { > for (x = 0; x < getWidth; x++) { > v = getPixel(x,y); > r = (v>>16)&0xff; // extract red byte (bits 23-17) > g = (v>>8)&0xff; // extract green byte (bits 15-8) > b = v&0xff; // extract blue byte (bits 7-0) > if (r > upper && g > upper && b < lower) yellow++; > else if (r < lower && g > upper && b < lower) green++; > else if (r > upper && g < lower && b < lower) red++; > else if (r < lower && g < lower && b < lower) black++; > else other++; > } > } > showMessage("Green = " + green + > ", Red = " + red + > ", Yellow = " + yellow + > ", Black = " + black + > ", Other = " + other); > > Regards, > Curtis > > On Tue, May 17, 2011 at 2:01 AM, Jacqui Ross <[hidden email] > >wrote: > > > Hi All, > > > > I have a person wanting to count the numbers of coloured pixels in her > > images. She has green, red and yellow and black. It's not colocalisation > > analysis that she is looking for. > > > > There seems to be a useful Plugin in development by Ben Pichette here: > > > http://imagejdocu.tudor.lu/doku.php?id=plugin:color:color_pixel_counter:startbutno plugin as such yet. > > > > Just wondering if Ben is able to let me know if this plugin is soon to be > > released or alternatively, whether there is another plugin that can do > this? > > The other option I was looking at to assist her was Threshold Colour. > > > > Any assistance would be very welcome. > > > > Kind regards, > > > > Jacqui > > > > Jacqueline Ross > > Biomedical Imaging Microscopist > > Biomedical Imaging Research Unit > > School of Medical Sciences > > Faculty of Medical & Health Sciences > > The University of Auckland > > Private Bag 92019 > > Auckland, NEW ZEALAND > > > > Tel: 64 9 373 7599 Ext 87438 > > Fax: 64 9 373 7484 > > > > http://www.fmhs.auckland.ac.nz/sms/biru/ > > > |
In reply to this post by Jacqueline Ross
Hi all,
I have problem regarding color pixel counter. Actually I have an image that is in three differect states i.e in red, in green, and the last one is the overlap of the 1st and the 2nd one. I have to check the amount of yellow color that is there in the last image. Can you help me in this regard... Thanks in advance. D. Ayyappa Raja |
In reply to this post by Jacqueline Ross
Hi all,
I have problem regarding color pixel counter. Actually I have an image that is in three differect states i.e in red, in green, and the last one is the overlap of the 1st and the 2nd one. I have to check the amount of yellow color that is there in the last image. Can you help me in this regard... Thanks in advance. D. Ayyappa Raja |
Free forum by Nabble | Edit this page |