Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
steps to convert RGB (colored image) to binary?

Subject: steps to convert RGB (colored image) to binary?

From: Ibtesam Saleh

Date: 20 May, 2010 13:15:22

Message: 1 of 12

What the steps to do that? is convert it directly to binary OR convert it to gray then to binary?
I have confused I want black/white image
I try
img= im2bw(imageName);
but it is became gray scale not black/white
Please help me with the steps to get binary image from colored one

Ibtesam

Subject: steps to convert RGB (colored image) to binary?

From: Sean

Date: 20 May, 2010 13:46:04

Message: 2 of 12

"Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <ht3cla$3e8$1@fred.mathworks.com>...
> What the steps to do that? is convert it directly to binary OR convert it to gray then to binary?
> I have confused I want black/white image
> I try
> img= im2bw(imageName);
> but it is became gray scale not black/white
> Please help me with the steps to get binary image from colored one
>
> Ibtesam

-"Gray" it (rgb2gray)
-Pick a threshold
-Ibw = Igray > threshold;

Subject: steps to convert RGB (colored image) to binary?

From: Ibtesam Saleh

Date: 20 May, 2010 14:32:20

Message: 3 of 12

> -"Gray" it (rgb2gray)
> -Pick a threshold
> -Ibw = Igray > threshold;

thanks sean for quick response, are you mean like this:
gray= rgb2gray(image);
bw= im2bw(gray);

I don't know what is the second and third steps mean?
 

Subject: steps to convert RGB (colored image) to binary?

From: Ibtesam Saleh

Date: 20 May, 2010 14:41:06

Message: 4 of 12

how pick the suitable threshold?
I did as you advise me..
Igray= rgb2gray(img);
threshold= 70;
Ibw= Igray> threshold;

Subject: steps to convert RGB (colored image) to binary?

From: Royi Avital

Date: 20 May, 2010 14:47:04

Message: 5 of 12

"Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <ht3h5k$53e$1@fred.mathworks.com>...
> > -"Gray" it (rgb2gray)
> > -Pick a threshold
> > -Ibw = Igray > threshold;
>
> thanks sean for quick response, are you mean like this:
> gray= rgb2gray(image);
> bw= im2bw(gray);
>
> I don't know what is the second and third steps mean?
>

Once you have a gray image you must chose a threshold.
A value which above it all pixels will be assigned to 1 and beneath to 0.
You may do that in various ways.

In my example, I is a gray scale image:

Threshold = 128;
I(I < 128) = 0;
I(I >= 128) = 1; % Pay attention to the order
I = logical(I); % Casting

I hope that helps.

Subject: steps to convert RGB (colored image) to binary?

From: Sean

Date: 20 May, 2010 14:58:04

Message: 6 of 12

"Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <ht3i18$31b$1@fred.mathworks.com>...
> "Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <ht3h5k$53e$1@fred.mathworks.com>...
> > > -"Gray" it (rgb2gray)
> > > -Pick a threshold
> > > -Ibw = Igray > threshold;
> >
> > thanks sean for quick response, are you mean like this:
> > gray= rgb2gray(image);
> > bw= im2bw(gray);
> >
> > I don't know what is the second and third steps mean?
> >
>
> Once you have a gray image you must chose a threshold.
> A value which above it all pixels will be assigned to 1 and beneath to 0.
> You may do that in various ways.
>
> In my example, I is a gray scale image:
>


> Threshold = 128;
> I(I < 128) = 0;
> I(I >= 128) = 1; % Pay attention to the order
> I = logical(I); % Casting

That is 2 more steps than necessary. Just using the logical operator on the whole image will convert everything below to logical 0 and above to true 1.
>>Ibw = Igray > threshold;

Original Poster's question; one way to pick a threshold:
>>imtool(Igray);
Then click on the black and white circle which will pull up the histogram. You can adjust the lines to see what various thresholds will do. Pick the one that well suits you.

Good Luck!

Subject: steps to convert RGB (colored image) to binary?

From: Ibtesam Saleh

Date: 20 May, 2010 15:19:04

Message: 7 of 12

> That is 2 more steps than necessary. Just using the logical operator on the whole image will convert everything below to logical 0 and above to true 1.
> >>Ibw = Igray > threshold;
>
> Original Poster's question; one way to pick a threshold:
> >>imtool(Igray);
> Then click on the black and white circle which will pull up the histogram. You can adjust the lines to see what various thresholds will do. Pick the one that well suits you.
>
> Good Luck!

I face error when try imtool(Igray);
??? Undefined command/function 'imtool'.

I try "help imtool" and I get
imtool.m not found.
Use the Help browser Search tab to search the documentation, or
type "help help" for help command options, such as help for methods.

I am using Matlab7,

Subject: steps to convert RGB (colored image) to binary?

From: clemency

Date: 23 Feb, 2011 08:30:19

Message: 8 of 12

sir please provide the idl syntax for convert the binary image to RGB image

Subject: steps to convert RGB (colored image) to binary?

From: Rune Allnor

Date: 23 Feb, 2011 08:35:02

Message: 9 of 12

On Feb 23, 9:30 am, clemency <u...@compgroups.net/> wrote:
> sir please provide the idl syntax for convert the binary image to RGB image

Something like

[N,M] = size(x);
X = zeros(N,M,3);
for n=1:3
   X(:,:,n) = x;
end

where x is the binary image, ought to do.

Of course, it remains to fill in any non-B&W colors...

Rune

Subject: steps to convert RGB (colored image) to binary?

From: ImageAnalyst

Date: 23 Feb, 2011 11:34:22

Message: 10 of 12

On Feb 23, 3:30 am, clemency <u...@compgroups.net/> wrote:
> sir please provide the idl syntax for convert the binary image to RGB image
----------------------------------------------------------------------------------------
rgbImage = cat(3, binaryImage, binaryImage, binaryImage);
It will appear black and white even though it will be a "color" image.

Subject: steps to convert RGB (colored image) to binary?

From: Steven_Lord

Date: 23 Feb, 2011 14:29:45

Message: 11 of 12



"clemency" <user@compgroups.net/> wrote in message
news:UpmdnavVlJMGWPnQnZ2dnUVZ_uidnZ2d@giganews.com...
> sir please provide the idl syntax for convert the binary image to RGB
> image

If you wanted the "ideal" syntax for performing this conversion (but just
missed typing the ea part of the word) use the suggestions that Rune and
ImageAnalyst made.

If you want to know how to do this in IDL rather than in MATLAB, you will
need to ask that in a newsgroup or forum specific to IDL. If you're not
sure where there is such a forum, I recommend searching Google Groups
(http://groups.google.com)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: steps to convert RGB (colored image) to binary?

From: clemency

Date: 24 Feb, 2011 05:54:23

Message: 12 of 12

thankusirgodblessuall

Tags for this Thread

No tags are associated with this thread.

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.

Contact us