Thread Subject: How to check pixel value in bmp image is of red color?

Subject: How to check pixel value in bmp image is of red color?

From: Rinachi Garg

Date: 21 Jun, 2008 15:24:02

Message: 1 of 10

I have an image of a circle red in color. Its boundary os
black in color. I have to find out whether a particular
pixel value is red in color. How can i do this?

Subject: How to check pixel value in bmp image is of red color?

From: Matt Fig

Date: 21 Jun, 2008 15:34:01

Message: 2 of 10

If I remember correctly, a bitmap (bmp) is stored in a mxnx3
matrix, where mxn is the image size and the third dimension
is the color information (rgb). For red, a the pixel data
in an image im would look like this:

im(16,35,1:3)

ans(:,:,1) =

  255


ans(:,:,2) =

    0


ans(:,:,3) =

    0



And for black, all values should be zero.

Subject: How to check pixel value in bmp image is of red color?

From: Rinachi Garg

Date: 21 Jun, 2008 16:33:01

Message: 3 of 10

"Matt Fig" <spamanon@yahoo.com> wrote in message <g3j719
$qvn$1@fred.mathworks.com>...
> If I remember correctly, a bitmap (bmp) is stored in a
mxnx3
> matrix, where mxn is the image size and the third
dimension
> is the color information (rgb). For red, a the pixel data
> in an image im would look like this:
>
> im(16,35,1:3)
>
> ans(:,:,1) =
>
> 255
>
>
> ans(:,:,2) =
>
> 0
>
>
> ans(:,:,3) =
>
> 0
>
>
>
> And for black, all values should be zero.

thanks a lot!!!!
Actually I have to find the coordinates of this image. How
can I do that???

Subject: How to check pixel value in bmp image is of red color?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 Jun, 2008 20:19:55

Message: 4 of 10

In article <g3j6eh$mpo$1@fred.mathworks.com>,
Rinachi Garg <rinachi_garg@yahoo.co.in> wrote:
>I have an image of a circle red in color. Its boundary os
>black in color. I have to find out whether a particular
>pixel value is red in color. How can i do this?

When does a colour stop being red and start being a different
colour? in RGB-255, we agree that [255 0 0] is red, but
is [255 0 1] "not red"? Is [128 0 0] red? Is [32 0 0] red? Is
[1 0 0] red?

--
Current spam load: 750-800 messages per day (March 4, 2008)

Subject: How to check pixel value in bmp image is of red color?

From: John D'Errico

Date: 21 Jun, 2008 21:03:02

Message: 5 of 10

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message
<g3jnpb$p03$1@canopus.cc.umanitoba.ca>...
> In article <g3j6eh$mpo$1@fred.mathworks.com>,
> Rinachi Garg <rinachi_garg@yahoo.co.in> wrote:
> >I have an image of a circle red in color. Its boundary os
> >black in color. I have to find out whether a particular
> >pixel value is red in color. How can i do this?
>
> When does a colour stop being red and start being a different
> colour? in RGB-255, we agree that [255 0 0] is red, but
> is [255 0 1] "not red"? Is [128 0 0] red? Is [32 0 0] red? Is
> [1 0 0] red?

This is why I wrote fuzzycolor. It uses a lookup
table that identifies most colors in the range
you show as being red. A quick test shows that
it accepts anything down to roughly [.18 0 0]
(0-1 RGB units) as red. Too far down to zero
in the red channel, and the color is better
described as black.

The tables themselves were defined by a visual
test that I did, on my own monitor, but a user
can redefine those tables.

fuzzycolor([.18 0 0],'red')
ans =
     1

fuzzycolor([.17 0 0],'red')
ans =
         0.67

fuzzycolor([.16 0 0],'red')
ans =
         0.16

fuzzycolor([.15 0 0],'red')
ans =
     0

The problem is that the definition of "red"
is highly subjective. As well, the set of
colors that any one person will choose to
define that way is probably not even a
convex set in RGB space.

John

Subject: How to check pixel value in bmp image is of red color?

From: Rinachi Garg

Date: 22 Jun, 2008 09:24:03

Message: 6 of 10

"Matt Fig" <spamanon@yahoo.com> wrote in message <g3j719
$qvn$1@fred.mathworks.com>...
> If I remember correctly, a bitmap (bmp) is stored in a
mxnx3
> matrix, where mxn is the image size and the third
dimension
> is the color information (rgb). For red, a the pixel data
> in an image im would look like this:
>
> im(16,35,1:3)
>
> ans(:,:,1) =
>
> 255
>
>
> ans(:,:,2) =
>
> 0
>
>
> ans(:,:,3) =
>
> 0
>
>
>
> And for black, all values should be zero.


hiii
I have written the following code and tried to find out the
pixel values which store red color by inserting them in
another array. I have tried to find the position of column
and row seperately.
But i am not getting desired result.
>> I = imread('circle.bmp');
>> J = rgb2gray(I);
>> a;b;
>> [m,n] = size(j);
>> for i = 1:1:m
      for j = 1:1:n
         if (I(i,j,1) == 255)
           if(I(i,j,2) == 0)
             if(I(i,j,3) == 0)
                  a(i)=i;
                  b(j)=j;
              end;
           end;
          end;
       end;
     end;
I think I am doing some mistake in declaring arrays a and
b . And then assigning the values of positions os row and
columns 2 a and b.
How can I correct it?

Subject: How to check pixel value in bmp image is of red color?

From: Rinachi Garg

Date: 22 Jun, 2008 09:33:01

Message: 7 of 10

"Rinachi Garg" <rinachi_garg@yahoo.co.in> wrote in message
<g3l5nj$a2c$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message <g3j719
> $qvn$1@fred.mathworks.com>...
> > If I remember correctly, a bitmap (bmp) is stored in a
> mxnx3
> > matrix, where mxn is the image size and the third
> dimension
> > is the color information (rgb). For red, a the pixel
data
> > in an image im would look like this:
> >
> > im(16,35,1:3)
> >
> > ans(:,:,1) =
> >
> > 255
> >
> >
> > ans(:,:,2) =
> >
> > 0
> >
> >
> > ans(:,:,3) =
> >
> > 0
> >
> >
> >
> > And for black, all values should be zero.
>
>
> hiii
> I have written the following code and tried to find out
the
> pixel values which store red color by inserting them in
> another array. I have tried to find the position of
column
> and row seperately.
> But i am not getting desired result.
> >> I = imread('circle.bmp');
> >> J = rgb2gray(I);
> >> a;b;
> >> [m,n] = size(j);
> >> for i = 1:1:m
> for j = 1:1:n
> if (I(i,j,1) == 255)
> if(I(i,j,2) == 0)
> if(I(i,j,3) == 0)
> a(i)=i;
> b(j)=j;
> end;
> end;
> end;
> end;
> end;
> I think I am doing some mistake in declaring arrays a and
> b . And then assigning the values of positions os row and
> columns 2 a and b.
> How can I correct it?

I have solved this problem.
By declaring a = zeros(1,m);
b = zeros(1,n);

Rinachi

Subject: How to check pixel value in bmp image is of red color?

From: Image Analyst

Date: 22 Jun, 2008 14:43:03

Message: 8 of 10

"Rinachi Garg" <rinachi_garg@yahoo.co.in> wrote in message
<g3l5nj$a2c$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message <g3j719
> $qvn$1@fred.mathworks.com>...
> > If I remember correctly, a bitmap (bmp) is stored in a
> mxnx3
> > matrix, where mxn is the image size and the third
> dimension
> > is the color information (rgb). For red, a the pixel
data
> > in an image im would look like this:
> >
> > im(16,35,1:3)
> >
> > ans(:,:,1) =
> >
> > 255
> >
> >
> > ans(:,:,2) =
> >
> > 0
> >
> >
> > ans(:,:,3) =
> >
> > 0
> >
> >
> >
> > And for black, all values should be zero.
>
>
> hiii
> I have written the following code and tried to find out
the
> pixel values which store red color by inserting them in
> another array. I have tried to find the position of
column
> and row seperately.
> But i am not getting desired result.
> >> I = imread('circle.bmp');
> >> J = rgb2gray(I);
> >> a;b;
> >> [m,n] = size(j);
> >> for i = 1:1:m
> for j = 1:1:n
> if (I(i,j,1) == 255)
> if(I(i,j,2) == 0)
> if(I(i,j,3) == 0)
> a(i)=i;
> b(j)=j;
> end;
> end;
> end;
> end;
> end;
> I think I am doing some mistake in declaring arrays a and
> b . And then assigning the values of positions os row and
> columns 2 a and b.
> How can I correct it?
----------------------------------------------------------
Rinachi:
You're not yet familiar with MATLAB, right? You could do
this faster with just 3 lines to extract out the individual
color bands from the color image and two lines to get the
coordinates of the pure red pixels. Why not try this:

clc; % Clear command window.
% Make up some arbitrary data for this demo.
redBand = uint8(255*rand(6,6));
greenBand = uint8(255*rand(6,6));
blueBand = uint8(255*rand(6,6));
redPixels = rand(6,6) > 0.75
redBand(redPixels(:)) = 255;
greenBand(redPixels(:)) = 0;
blueBand(redPixels(:)) = 0;
colorImage = cat(3, redBand, greenBand, blueBand);
imshow(colorImage); % Display it.
% Done making up demo image.

% Now, here's the crucial part that Rinachi needs:
% Extract the 3 color bands out of the color image.
redBand = colorImage(:,:, 1)
greenBand = colorImage(:,:, 2)
blueBand = colorImage(:,:, 3)

% Find x,y of pixels that are pure red.
reds = (redBand == 255) & (greenBand == 0) & (blueBand == 0)
[redRows redColumns] = find(reds)
% Check out the command window for results.

And like Walter pointed out, checking for 255,0,0 will only
find pure, brightest reds as would be created from computer
graphics or annotation, not necessarily for other arbitrary
reds that you might find in real world images snapped with,
say, a digital camera. For that, there's other methods.
Let us know if that applies to you.
Regards,
ImageAnalyst
---------------------------------------------------

Subject: How to check pixel value in bmp image is of red color?

From: Rinachi Garg

Date: 22 Jun, 2008 15:57:02

Message: 9 of 10

"Image Analyst" <imageanalyst@mailinator.com> wrote in
message <g3lodn$c90$1@fred.mathworks.com>...
> "Rinachi Garg" <rinachi_garg@yahoo.co.in> wrote in
message
> <g3l5nj$a2c$1@fred.mathworks.com>...
> > "Matt Fig" <spamanon@yahoo.com> wrote in message <g3j719
> > $qvn$1@fred.mathworks.com>...
> > > If I remember correctly, a bitmap (bmp) is stored in
a
> > mxnx3
> > > matrix, where mxn is the image size and the third
> > dimension
> > > is the color information (rgb). For red, a the pixel
> data
> > > in an image im would look like this:
> > >
> > > im(16,35,1:3)
> > >
> > > ans(:,:,1) =
> > >
> > > 255
> > >
> > >
> > > ans(:,:,2) =
> > >
> > > 0
> > >
> > >
> > > ans(:,:,3) =
> > >
> > > 0
> > >
> > >
> > >
> > > And for black, all values should be zero.
> >
> >
> > hiii
> > I have written the following code and tried to find out
> the
> > pixel values which store red color by inserting them in
> > another array. I have tried to find the position of
> column
> > and row seperately.
> > But i am not getting desired result.
> > >> I = imread('circle.bmp');
> > >> J = rgb2gray(I);
> > >> a;b;
> > >> [m,n] = size(j);
> > >> for i = 1:1:m
> > for j = 1:1:n
> > if (I(i,j,1) == 255)
> > if(I(i,j,2) == 0)
> > if(I(i,j,3) == 0)
> > a(i)=i;
> > b(j)=j;
> > end;
> > end;
> > end;
> > end;
> > end;
> > I think I am doing some mistake in declaring arrays a
and
> > b . And then assigning the values of positions os row
and
> > columns 2 a and b.
> > How can I correct it?
> ----------------------------------------------------------
> Rinachi:
> You're not yet familiar with MATLAB, right? You could do
> this faster with just 3 lines to extract out the
individual
> color bands from the color image and two lines to get the
> coordinates of the pure red pixels. Why not try this:
>
> clc; % Clear command window.
> % Make up some arbitrary data for this demo.
> redBand = uint8(255*rand(6,6));
> greenBand = uint8(255*rand(6,6));
> blueBand = uint8(255*rand(6,6));
> redPixels = rand(6,6) > 0.75
> redBand(redPixels(:)) = 255;
> greenBand(redPixels(:)) = 0;
> blueBand(redPixels(:)) = 0;
> colorImage = cat(3, redBand, greenBand, blueBand);
> imshow(colorImage); % Display it.
> % Done making up demo image.
>
> % Now, here's the crucial part that Rinachi needs:
> % Extract the 3 color bands out of the color image.
> redBand = colorImage(:,:, 1)
> greenBand = colorImage(:,:, 2)
> blueBand = colorImage(:,:, 3)
>
> % Find x,y of pixels that are pure red.
> reds = (redBand == 255) & (greenBand == 0) & (blueBand ==
0)
> [redRows redColumns] = find(reds)
> % Check out the command window for results.
>
> And like Walter pointed out, checking for 255,0,0 will
only
> find pure, brightest reds as would be created from
computer
> graphics or annotation, not necessarily for other
arbitrary
> reds that you might find in real world images snapped
with,
> say, a digital camera. For that, there's other methods.
> Let us know if that applies to you.
> Regards,
> ImageAnalyst
> ---------------------------------------------------

I have a bitmap image which contain red, blue and green
coloured filled contous. I have to find the coordinates of
the boundary pixels of these three contours.
How to do this?

Subject: How to check pixel value in bmp image is of red color?

From: ImageAnalyst

Date: 22 Jun, 2008 16:15:13

Message: 10 of 10

On Jun 22, 11:57=A0am, "Rinachi Garg" <rinachi_g...@yahoo.co.in> wrote:
> "Image Analyst" <imageanal...@mailinator.com> wrote in
> message <g3lodn$c9...@fred.mathworks.com>...
>
>
>
>
>
> > "Rinachi Garg" <rinachi_g...@yahoo.co.in> wrote in
> message
> > <g3l5nj$a2...@fred.mathworks.com>...
> > > "Matt Fig" <spama...@yahoo.com> wrote in message <g3j719
> > > $qv...@fred.mathworks.com>...
> > > > If I remember correctly, a bitmap (bmp) is stored in
> a
> > > mxnx3
> > > > matrix, where mxn is the image size and the third
> > > dimension
> > > > is the color information (rgb). =A0For red, a the pixel
> > data
> > > > in an image im would look like this:
>
> > > > im(16,35,1:3)
>
> > > > ans(:,:,1) =3D
>
> > > > =A0 255
>
> > > > ans(:,:,2) =3D
>
> > > > =A0 =A0 0
>
> > > > ans(:,:,3) =3D
>
> > > > =A0 =A0 0
>
> > > > And for black, all values should be zero. =A0
>
> > > hiii
> > > I have written the following code and tried to find out
> > the
> > > pixel values which store red color by inserting them in
> > > another array. I have tried to find the position of
> > column
> > > and row seperately.
> > > But i am not getting desired result.
> > > >> I =3D imread('circle.bmp');
> > > >> J =3D rgb2gray(I);
> > > >> a;b;
> > > >> [m,n] =3D size(j);
> > > >> for i =3D 1:1:m
> > > =A0 =A0 =A0 for j =3D 1:1:n
> > > =A0 =A0 =A0 =A0 =A0if (I(i,j,1) =3D=3D 255)
> > > =A0 =A0 =A0 =A0 =A0 =A0if(I(i,j,2) =3D=3D 0)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0if(I(i,j,3) =3D=3D 0)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 a(i)=3Di;
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 b(j)=3Dj;
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 end;
> > > =A0 =A0 =A0 =A0 =A0 =A0end;
> > > =A0 =A0 =A0 =A0 =A0 end;
> > > =A0 =A0 =A0 =A0end;
> > > =A0 =A0 =A0end;
> > > I think I am doing some mistake in declaring arrays a
> and
> > > b . And then assigning the values of positions os row
> and
> > > columns 2 a and b.
> > > How can I correct it?
> > ----------------------------------------------------------
> > Rinachi:
> > You're not yet familiar with MATLAB, right? =A0You could do
> > this faster with just 3 lines to extract out the
> individual
> > color bands from the color image and two lines to get the
> > coordinates of the pure red pixels. =A0Why not try this:
>
> > clc; % Clear command window.
> > % Make up some arbitrary data for this demo.
> > redBand =3D uint8(255*rand(6,6));
> > greenBand =3D uint8(255*rand(6,6));
> > blueBand =3D uint8(255*rand(6,6));
> > redPixels =3D rand(6,6) > 0.75
> > redBand(redPixels(:)) =3D 255;
> > greenBand(redPixels(:)) =3D 0;
> > blueBand(redPixels(:)) =3D 0;
> > colorImage =3D cat(3, redBand, greenBand, blueBand);
> > imshow(colorImage); % Display it.
> > % Done making up demo image.
>
> > % Now, here's the crucial part that Rinachi needs:
> > % Extract the 3 color bands out of the color image.
> > redBand =3D colorImage(:,:, 1)
> > greenBand =3D colorImage(:,:, 2)
> > blueBand =3D colorImage(:,:, 3)
>
> > % Find x,y of pixels that are pure red.
> > reds =3D (redBand =3D=3D 255) & (greenBand =3D=3D 0) & (blueBand =3D=3D
> 0)
> > [redRows redColumns] =3D find(reds)
> > % Check out the command window for results.
>
> > And like Walter pointed out, checking for 255,0,0 will
> only
> > find pure, brightest reds as would be created from
> computer
> > graphics or annotation, not necessarily for other
> arbitrary
> > reds that you might find in real world images snapped
> with,
> > say, a digital camera. =A0For that, there's other methods. =A0
> > Let us know if that applies to you.
> > Regards,
> > ImageAnalyst
> > ---------------------------------------------------
>
> I have a bitmap image which contain red, blue and green
> coloured filled contous. I have to find the coordinates of
> the boundary pixels of these three contours.
> How to do this?- Hide quoted text -
>
> - Show quoted text -

-------------------------------------------------------------------
Rinachi:
Well now, you've totally changed the situation. This is what you
should have said in the first place, because just getting the
coordinates of the red pixels may have seemed like what you should
need to do but it's not. If you have filled contours, basically solid
blobs of uniform color, then what you need to do is call bwboundaries
in the image processing toolikt (which hopefully you already have
since you're dealing with images). (It finds the boundaries, like if
you had eroded the binary image and subtracted that from the original
binary image.) If you have nested contours (colored blobs inside of
other blobs) then it gets a bit tricker but you can still do it.
Good luck,
ImageAnalyst

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
pixel value MarcoM 2 Jul, 2008 06:32:39
image processing Rinachi Garg 21 Jun, 2008 11:25:04
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com