I need a simple matlab code to convert a color image to binary image and back to color image.

9 ビュー (過去 30 日間)
Sujitha
Sujitha 2015 年 4 月 10 日
コメント済み: Sujitha 2015 年 4 月 23 日
Irgb = imread('image.jpg');
threshold = 128;
Igray = rgb2gray(Irgb);
Ibw = Igray>threshold;
imshow(Ibw);
This gives the binary image ..
But RGB = cat(3,Igray,Igray,Igray) and "im2bw" commands are not working... I need a code to convert that binary image back to its original rgb color.

回答 (2 件)

Image Analyst
Image Analyst 2015 年 4 月 10 日
Once you've thrown away the color information by going to a gray scale or binary image, it's not possible to get it back. Fortunately, the Irgb variable is still there, so you still have the original color image.
Why im2bw() is not working (not converting your gray scale image into a binary image) is a separate question. How are you calling im2bw()? How do you know it doesn't work? How are you verifying that? Do you use imshow() to display the output? Is there an error message?

Sujitha
Sujitha 2015 年 4 月 10 日
I understood and got binary image by using im2bw(). I = imread('image.jpg'); J = rgb2gray(I); imshow(I); imshow(J); J = im2bw(J); imshow(J);
But are you sure that there are no possibilities to retrieve the colors back?
  2 件のコメント
Michael Haderlein
Michael Haderlein 2015 年 4 月 10 日
Please make sure your response on answers is in comments to these answers and not new "answers". The order of answers might change and then everything becomes unreadable.
"But are you sure that there are no possibilities to retrieve the colors back?"
Yes. rgb2gray is returning something like the mean of R, G, and B. So if I tell you that the mean of three numbers is 10, you will agree that it's impossible to get the value of these three individual numbers out of that information as there are many valid combinations. You'll have to use your original image I.
Sujitha
Sujitha 2015 年 4 月 23 日
Thanks for the answer.. and sorry for the late response.

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by