Login  Register

Re: Color Pixel Counter - plugin

Posted by Jacqueline Ross on May 18, 2011; 6:49am
URL: http://imagej.273.s1.nabble.com/Color-Pixel-Counter-plugin-tp3683486p3683490.html

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/
>