Conversion to grayscale image from binary image

2 views (last 30 days)
snake eyes
snake eyes on 23 Aug 2011
Answered: DGM on 15 Jun 2025
I've converted a grayscale image to binary image using "im2bw" function. Now I want to do the opposite, i,e; i want to convert the binary image to grayscale image. How can I do it?
Thanks in advance.

Answers (1)

DGM
DGM on 15 Jun 2025
If your binary image is a logical image, as returned from im2bw() or imbinarize(), then it can be converted to a numeric class using im2double(), im2uint8() or other similar functions.
inpict = imread('cameraman.tif'); % uint8 grayscale image
mask = imbinarize(inpict); % a logical image
outpict = im2uint8(mask); % the same binarized image in uint8
montage({inpict,mask,outpict},'size',[1 3],'bordersize',10,'backgroundcolor','m')
All that does is rescale the data and change its class. The result is still a binary image, even though it's no longer a logical image. This option does not recover the original image. Once an image is binarized, all that information is gone. If you want the original image, use the original image.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!