フィルターのクリア

imread and/or rgb2gray not working as expected

4 ビュー (過去 30 日間)
Daniel Lee
Daniel Lee 2016 年 11 月 21 日
回答済み: KSSV 2016 年 11 月 21 日
I am trying to read an image and convert it to grayscale. Originally, I thought the problem was with the rgb2gray function, but when I displayed the image i was trying to read, it was completely different. Here is my code (I got a part of it from another forum) as well as the picture i was trying to read and convert to grayscale.
RGB = imread('Cir1.png');
imshow(RGB);
[rows columns numberOfColorChannels] = size(RGB);
if numberOfColorChannels > 1
Igray = rgb2gray(RGB);
else
Igray = RGB; % It's already gray.
end
imshow(Igray);
The image i am trying to read is show below.
Thanks!

採用された回答

KSSV
KSSV 2016 年 11 月 21 日
[RGB, map, alpha] = imread('Cir1.png');
figure ; imshow(RGB,map);
[rows, columns, numberOfColorChannels] = size(RGB);
if numberOfColorChannels > 1
Igray = rgb2gray(RGB);
else
Igray = rgb2gray(map);
end
figure ;imshow(RGB,Igray);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by