Login  Register

Re: How to get the color information?? (isColorLut and isPseudoColorLut do not help)

Posted by Joris FA Meys on Feb 05, 2009; 9:35pm
URL: http://imagej.273.s1.nabble.com/How-to-get-the-image-information-tp3693833p3693837.html

Hi Xin,

The only thing I can think about is pick some random pixels and check if the
values in different channels are the same. If they differ, then you have a
color image. If they don't, you have a grey image.

it would be something like

     boolean grey = true;
     int x = 0; in y = 0;
     in count=0
     while (grey & count<100){
          x = Round(Math.random()*img.getWidth());
          y = Round(Math.random()*img.getHeight());
          red=img.getPixel(x,y)[0];
          green=img.getPixel(x,y)[1];
          blue=img.getPixel(x,y)[2];
          if(red!=green | red !=blue | green=!blue) grey=false;
          count++;
     }

I use the random method as I believe that in quite some images the first x
rows will be the same, as they're often black. If the values are the same
for 100 random pixels, it should be a grey image.

Hope this works.

Kind regards
Joris

On Thu, Feb 5, 2009 at 9:56 PM, Xin ZHOU <[hidden email]> wrote:

> Hi, thanks a lot Joris.
>
> Unfortunately this only solve half of my problem.
> The question is : some grey-level images are saved as color_RGB. That's
> awful.
> So getType() shows that they are color images. But they are not.
> The three values for each pixel are the same.
>
> It there any clever way to identify the image type?
>
> cheers, Xin
>
> joris meys a écrit :
>
>  try getType() from ImagePlus. If the return is 3 or 4, your image is in
>> color.
>> Kind regards
>> Joris
>>
>> On Thu, Feb 5, 2009 at 5:31 PM, Xin ZHOU <[hidden email]> wrote:
>>
>>
>>
>>> Wayne Rasband a écrit :
>>>
>>>
>>>
>>>> I'm using ij.jar for programming.
>>>>
>>>>
>>>>> How can I know one image is in color so that I can separate it from the
>>>>> others??
>>>>>
>>>>>
>>>>>
>>>> Dear Xin,
>>>>
>>>> RGB color images use a ColorProcessor. The getRGB() of the
>>>> ColorProcessor
>>>> class returns the image as three byte arrays, which can be easily
>>>> converted
>>>> into three ByteProcessors.
>>>>
>>>> -wayne
>>>>
>>>>
>>>>
>>> Hello, Wayne, and the others
>>>
>>> Thanks a lot for your answers.
>>> But my question is GreyLevel images are mixed with color ones.
>>> How can I separate them? If I use ColorProcessor, this means I know
>>> already
>>> they are color ones.
>>> I've tried the methods : isColorLut and isPseudoColorLut.
>>> Surprisingly it doesn't work. It return false to all images, even color
>>> ones.
>>>
>>> Any idea for that ??
>>>
>>> cheers, Xin
>>>
>>>
>>>
>>
>>
>>
>