can someone write the line code that checks if the image is rgb and convert it to gfrayscale

1 回表示 (過去 30 日間)
jana
jana 2022 年 12 月 2 日
回答済み: Kevin Holly 2022 年 12 月 2 日
i want to make sure if uts rgb because i keep getting the m*3 map error and after it checks if its rgb to convert it to grayscale plz and thank u

回答 (1 件)

Kevin Holly
Kevin Holly 2022 年 12 月 2 日
If you want a quick fix you can do the following:
try
rgb2gray(Image)
catch
disp("Error using rgb2gray")
end
or you can look at the dimensions of the image:
if size(Image,3)==1
disp('RGB Image')
else
disp('Gray Image')
rgb2gray(Image)
end

カテゴリ

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