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:
convert to binary image

Subject: convert to binary image

From: Ibtesam Saleh

Date: 21 Jun, 2010 17:34:22

Message: 1 of 6

Hi all...

I have colored image and I want to convert it to binary (I mean matrix of zeros and ones)
please how can I do that? Its very urgent issue...

thanks...

Subject: convert to binary image

From: Sean

Date: 21 Jun, 2010 19:03:06

Message: 2 of 6

"Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <hvo7qu$2br$1@fred.mathworks.com>...
> Hi all...
>
> I have colored image and I want to convert it to binary (I mean matrix of zeros and ones)
> please how can I do that? Its very urgent issue...
>
> thanks...


threshold = some_value; %Threshold that above is 1 below is 0
Igray = rgb2gray(Irgb); %Convert colors to gray
Ibw = Igray>threshold; %Set everything greater than threshold to 1 and less to 0.
Good luck

Subject: convert to binary image

From: Walter Roberson

Date: 21 Jun, 2010 19:02:41

Message: 3 of 6

Ibtesam Saleh wrote:

> I have colored image and I want to convert it to binary (I mean matrix
> of zeros and ones)
> please how can I do that? Its very urgent issue...

BWImage = double(rgb2gray(YourImage) > 0.5);

Subject: convert to binary image

From: Ibtesam Saleh

Date: 21 Jun, 2010 19:12:22

Message: 4 of 6

> threshold = some_value; %Threshold that above is 1 below is 0
> Igray = rgb2gray(Irgb); %Convert colors to gray
> Ibw = Igray>threshold; %Set everything greater than threshold to 1 and less to 0.
> Good luck

Thanks Sean...
but how can I select the best threshold value for my images?

Subject: convert to binary image

From: Sean

Date: 21 Jun, 2010 19:21:44

Message: 5 of 6

"Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <hvodim$b62$1@fred.mathworks.com>...
> > threshold = some_value; %Threshold that above is 1 below is 0
> > Igray = rgb2gray(Irgb); %Convert colors to gray
> > Ibw = Igray>threshold; %Set everything greater than threshold to 1 and less to 0.
> > Good luck
>
> Thanks Sean...
> but how can I select the best threshold value for my images?

imtool(Igray) %View Igray
%Click on the black and white circle on the menu bar and move the red lines defining the thresholds
%Adjust them to find one that meets you application

Subject: convert to binary image

From: us

Date: 21 Jun, 2010 19:26:21

Message: 6 of 6

"Ibtesam Saleh" <bossy_4me@yahoo.com> wrote in message <hvodim$b62$1@fred.mathworks.com>...
> > threshold = some_value; %Threshold that above is 1 below is 0
> > Igray = rgb2gray(Irgb); %Convert colors to gray
> > Ibw = Igray>threshold; %Set everything greater than threshold to 1 and less to 0.
> > Good luck
>
> Thanks Sean...
> but how can I select the best threshold value for my images?

a hint:
- requires the img proc tbx...

     help imhist;

us

Tags for 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