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 binary to gray

Subject: convert binary to gray

From: u-ingenieria bd

Date: 26 Jan, 2012 18:53:22

Message: 1 of 8

how to convert a logical binary image into same size gray image?

I have tried y=bin2gray(x,'qam',16) function but here for x this
function does not take the binary image directly. all I need to
convert the binary image into grayscale image.

Subject: convert binary to gray

From: ImageAnalyst

Date: 26 Jan, 2012 20:31:47

Message: 2 of 8

On Jan 26, 10:53 am, u-ingenieria bd <u.ingenieria...@gmail.com>
wrote:
> how to convert a logical binary image into same size gray image?
>
> I have tried y=bin2gray(x,'qam',16) function but here for x this
> function does not take the binary image directly. all I need to
> convert the binary image into grayscale image.

------------------------------------------------
I never heard of that function. Simply do this:
grayImage = uint8(binaryImage);

or, if you want the true (1) to be mapped to 255 instead of 1, do
this:
grayImage = 255 * uint8(binaryImage);

Subject: convert binary to gray

From: Steven_Lord

Date: 26 Jan, 2012 21:39:58

Message: 3 of 8



"ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
news:9a257a26-211e-4107-8516-dc45e4d65373@iu7g2000pbc.googlegroups.com...
> On Jan 26, 10:53 am, u-ingenieria bd <u.ingenieria...@gmail.com>
> wrote:
>> how to convert a logical binary image into same size gray image?
>>
>> I have tried y=bin2gray(x,'qam',16) function but here for x this
>> function does not take the binary image directly. all I need to
>> convert the binary image into grayscale image.
>
> ------------------------------------------------
> I never heard of that function. Simply do this:

*snip*

FYI, it's part of Communications System Toolbox:

http://www.mathworks.com/help/toolbox/comm/ref/bin2gray.html

and doesn't really appear, to my eyes, to be related to image processing.

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

Subject: convert binary to gray

From: u-ingenieria bd

Date: 27 Jan, 2012 01:41:40

Message: 4 of 8

On Jan 27, 3:39 am, "Steven_Lord" <sl...@mathworks.com> wrote:
> "ImageAnalyst" <imageanal...@mailinator.com> wrote in message
>
> news:9a257a26-211e-4107-8516-dc45e4d65373@iu7g2000pbc.googlegroups.com...
>
> > On Jan 26, 10:53 am, u-ingenieria bd <u.ingenieria...@gmail.com>
> > wrote:
> >> how to convert a logical binary image into same size gray image?
>
> >> I have tried y=bin2gray(x,'qam',16) function but here for x this
> >> function does not take the binary image directly. all I need to
> >> convert the binary image into grayscale image.
>
> > ------------------------------------------------
> > I never heard of that function.  Simply do this:
>
> *snip*
>
> FYI, it's part of Communications System Toolbox:
>
> http://www.mathworks.com/help/toolbox/comm/ref/bin2gray.html
>
> and doesn't really appear, to my eyes, to be related to image processing.
>
> --
> Steve Lord
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link onhttp://www.mathworks.com

Ya the 255multiply is a must option to use when someone wants to see
the output with imshow() function. Its more interesting that if
someone wants to write that binary image into rgb format or png format
then he/she does not need to even convert the binary image into
grayscale or rgb. all it needs to use imwrite() function. Its
interesting.

Subject: convert binary to gray

From: ImageAnalyst

Date: 27 Jan, 2012 04:15:01

Message: 5 of 8

On Jan 26, 5:41 pm, u-ingenieria bd <u.ingenieria...@gmail.com> wrote:
> Ya the 255multiply is a must option to use when someone wants to see
> the output with imshow() function. Its more interesting that if
> someone wants to write that binary image into rgb format or png format
> then he/she does not need to even convert the binary image into
> grayscale or rgb. all it needs to use imwrite() function. Its
> interesting.
----------------------------------------------------------
That's not correct. imshow will show a logical image automatically
scaled so that the true (1) pixels will appear bright (255). No
scaling is necessary to see it.

Subject: convert binary to gray

From: Yumnam Kirani

Date: 27 Jan, 2012 08:25:10

Message: 6 of 8

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9a257a26-211e-4107-8516-dc45e4d65373@iu7g2000pbc.googlegroups.com>...
> On Jan 26, 10:53 am, u-ingenieria bd <u.ingenieria...@gmail.com>
> wrote:
> > how to convert a logical binary image into same size gray image?
> >
> > I have tried y=bin2gray(x,'qam',16) function but here for x this
> > function does not take the binary image directly. all I need to
> > convert the binary image into grayscale image.
>
> ------------------------------------------------
> I never heard of that function. Simply do this:
> grayImage = uint8(binaryImage);
>
> or, if you want the true (1) to be mapped to 255 instead of 1, do
> this:
> grayImage = 255 * uint8(binaryImage);

It is not possible to convert a binary image to a gray image, irrespective of whether we use uint8 or multiply by 255 or both. The resulted values will only have two distinct values, that is, binary values.

Yumnam Kirani Singh
Tronglaobi Awang Leikai

Subject: convert binary to gray

From: Carl S.

Date: 27 Dec, 2012 17:42:06

Message: 7 of 8

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9a257a26-211e-4107-8516-dc45e4d65373@iu7g2000pbc.googlegroups.com>...
> On Jan 26, 10:53 am, u-ingenieria bd <u.ingenieria...@gmail.com>
> wrote:
> > how to convert a logical binary image into same size gray image?
> >
> > I have tried y=bin2gray(x,'qam',16) function but here for x this
> > function does not take the binary image directly. all I need to
> > convert the binary image into grayscale image.
>
> ------------------------------------------------
> I never heard of that function. Simply do this:
> grayImage = uint8(binaryImage);
>
> or, if you want the true (1) to be mapped to 255 instead of 1, do
> this:
> grayImage = 255 * uint8(binaryImage);

Hi,

I have two images. They are;
tempBinaryImg : 320x320 double
GrayscaleImg : 320x320 double

When I write that
temp2 = tempBinaryImg.*(GrayscaleImg>0);
PreprocessedGrayscaleImg = uint8(Img).*uint8(temp2);

then I am getting PreprocessedGrayscaleImg as uint8. But I want to get the PreprocessedGrayscaleImg as double. So, I write

PgrayImg = double(PreprocessedGrayscaleImg);

but the PgrayImg is binary, it is not gray. How can I get the PreprocessedGrayscaleImg as double and gray ?

Subject: convert binary to gray

From: Image Analyst

Date: 27 Dec, 2012 22:08:08

Message: 8 of 8

"Carl S." wrote in message <kbi19e$f3q$1@newscl01ah.mathworks.com>...
> I have two images. They are;
> tempBinaryImg : 320x320 double
> GrayscaleImg : 320x320 double
>
> When I write that
> temp2 = tempBinaryImg.*(GrayscaleImg>0);
> PreprocessedGrayscaleImg = uint8(Img).*uint8(temp2);
>
> then I am getting PreprocessedGrayscaleImg as uint8. But I want to get the PreprocessedGrayscaleImg as double. So, I write
>
> PgrayImg = double(PreprocessedGrayscaleImg);
>
> but the PgrayImg is binary, it is not gray. How can I get the PreprocessedGrayscaleImg as double and gray ?
----------------------------------------------------------------------------------------------------------

It's not binary. It's a gray scale image of type "double". Why? Do "whos PgrayImg" to see the data type of PgrayImg, or else look in the Workspace panel. But why does it have values of only 0.0 and 1.0? Well let's take it a step at a time:
(GrayscaleImg>0) is a logical (0's and 1's), but gets converted to double to do the multiplication.
tempBinaryImg is double, but judging from the name, it also has values of 0's and 1's.
So the product temp2, will also be a double but have values of 0.0 and 1.0 only.
So now you cast temp2 to uint8 which means it's now unsigned 8 bit integer and will have integer (not floating point) values of 0 and 1.
Then you have some array "img" and I have no idea what values it has, but after you cast it to uint8, it will have integer values of 0, 1, 2, 3, ....255, or whatever it actually contains.
So you do uint8(Img).*uint8(temp2) and you will get PreprocessedGrayscaleImg as a uint8 also, and it will have values of 0, 2, 3, 4, ... 255 or the same values that img, masked by temp2, would have. And now you do this:
PgrayImg = double(PreprocessedGrayscaleImg);
which means that PgrayImg has the same values as PreprocessedGrayscaleImg but they are double instead of integer, in other words floating point 0.0, 1.0, 2.0, 3.0, ...255.0, or whatever values the masked version of tempBinaryImg has.
You said you think it's binary (type logical), but it's not - it's double, though it might have floating point values of 0.0 and 1.0 only, if that's what tempBinaryImg had.

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