Hello, I am working on Image processing.Can anyone tell me how can we convert a binary image to a gray scale image such that it leads to elimination of background which is unwanted content for the given image.
Thanks in advance

3 件のコメント

Rekha B
Rekha B 2023 年 2 月 23 日
How to convert a logical binary image to a gray scale image?
same question how to convert logical binary image to gray scale image plz help me regard this.
Walter Roberson
Walter Roberson 2023 年 2 月 23 日
grayscaleimage = 0 + logicalimage;
or
grayscaleimage = uint8(255).*uint8(logicalimage);
or
grayscaleimage = zeros(size(logicalimage), 'uint8') ;
grayscaleimage(logicalimage) = uint8(255) ;
DGM
DGM 2023 年 2 月 23 日
Or just
mask = im2uint8(mask);
or
mask = im2double(mask);
that way the class of the input doesn't matter.
Of course, the original question wasn't actually about converting a binary mask into a grayscale image, but about some notion of background removal, which isn't clear was necessary.
% a grayscale (MxNx1) uint8 image and a logical mask
inpict = imread('cameraman.tif');
mask = imread('cmantifmk.png')>128;
% apply the mask to the image using logical addressing
% this requires the mask to be a proper logical-class image
outpict = inpict;
outpict(~mask) = 0;
imshow(outpict)
% apply the mask to the image using multiplicative composition
% mask can be logical or numeric class, so long as it's properly-scaled
% mask can be binarized (hard) or any antialiased/graduated mask
% inpict can be grayscale (I) or RGB (assuming we're using R2016b+)
outpict = im2uint8(im2double(inpict).*im2double(mask));
imshow(outpict)
There are other ways to do the same or similar, but maybe that's enough to drive a search query.

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2014 年 4 月 23 日

2 投票

Assuming you meant a color image, there is an rgb2gray() function but it won't get rid of background. There are many, many types of backgrounds (uniform, colored, textured, gradient, etc.). So to give you a good answer, we'll need to see your image. Please attach it.
If you really meant a binary image, like a true/false, 1/0, logical image, then you can convert it to a uint8 gray scale image just by doing
uint8Image = uint8(255 * binaryImage);
Though that won't get rid of any background.

11 件のコメント

Rageeni sah
Rageeni sah 2014 年 4 月 23 日
Thank you for your previous consideration.
I have attached the image.I want to get image in the left from image in the right. Can you tell me how can i get the limits values (i.e., rmin,Rmax,Cmin,Cmax) shown in the image.
Image Analyst
Image Analyst 2014 年 4 月 23 日
Which image are you starting with, the left one or the right one? that looks like a paper, so can't you just follow the algorithm in it? If not, find one here: http://iris.usc.edu/Vision-Notes/bibliography/contentspeople.html#Face%20Recognition,%20Detection,%20Tracking,%20Gesture%20Recognition,%20Fingerprints,%20Biometrics
Rageeni sah
Rageeni sah 2014 年 4 月 23 日
I have started with image on left with a background which is actually removed as shown in image on the left after certain following a set of steps. The last step is to convert binary image to gray scale image which is quite difficult for more.I am not able to make out how to get the values of those limits as shown in image on the right.
Rageeni sah
Rageeni sah 2014 年 4 月 23 日
Please help me...I have been trying on this from a week but all attempts went furtil.
Image Analyst
Image Analyst 2014 年 4 月 23 日
I don't understand. Usually you go from grayscale to binary by thresholding, then label and call regionprops. Why do you want to go in the reverse direction? What is the binary image you're starting with and how did you get it?
Rageeni sah
Rageeni sah 2014 年 4 月 24 日
I am going in reverse way to remove the background completely from image.
Image Analyst
Image Analyst 2014 年 4 月 24 日
In a binary image, the foreground is white/1/true, and the "background" is black/0/false. So there is no need to get rid of it, unless you are using a very non-standard definition of binary . Why don't you attach your image and explain what you want to achieve.
Osman
Osman 2014 年 11 月 24 日
I faced the same problem, What I want to do?
I have a gray-scale image and want to subtract its background, then I have to convert the image back to gray-scale, in order to use image data "Object before thresholding include different intensity value in each pixels". Can one help me?
Image Analyst
Image Analyst 2014 年 11 月 24 日
I have no idea what this means: "Object before thresholding include different intensity value in each pixels". Please explain.
Subtracting a background does not change a grayscale image into some other kind of image - it's still a gray scale image - so there's nothing you need to do.
Feel free to start your own question with your attached picture and explain what you want to do or measure in the image.
sinan salim
sinan salim 2020 年 7 月 11 日
i need to extract the small object in the image of retina mask,,like make all the image black only the small spot white ..so pls how can do it..thanks in advance
Image Analyst
Image Analyst 2020 年 7 月 11 日
Call imclearborder():
mask = imclearborder(mask);

サインインしてコメントする。

その他の回答 (1 件)

Hazwani Mohmad Ramli
Hazwani Mohmad Ramli 2020 年 12 月 15 日

0 投票

Anyone please help me.
I want to export this image with grascale format. If I write imshow, they will appear in binary format. what sould I do?

2 件のコメント

Image Analyst
Image Analyst 2020 年 12 月 15 日
This doesn't look like an Answer to Rageeni's question. Please attach your original image, plus this screenshot, in a new discussion thread, not here. We'll solve it there. And explain what you mean, because I'm not sure what you mean by gray scale and binary. On disk, while's it's in the PNG file, it's binary - 8 bits per pixel in a special format. Once it's read into MATLAB it's probably uint8 or uint16, which is gray scale. Inside MATLAB a binary image means a logical image with values of true or false (1 or 0) and appears just pure black and pure white (meaning no grays in between).
DGM
DGM 2023 年 2 月 23 日
If a nominally-grayscale image appears binarized in imshow, then it's either not what you think it is due to some prior mistake, or it's simply improperly-scaled floating-point. Since nobody knows what the actual images or code was, it's impossible to know for sure.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

タグ

質問済み:

2014 年 4 月 23 日

コメント済み:

DGM
2023 年 2 月 23 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by