グレースケール化のエラー

18 vues (au cours des 30 derniers jours)
Kodai Sato
Kodai Sato le 6 Oct 2020
Commenté : Kodai Sato le 6 Oct 2020
以下のコードでグレースケール化を行おうと考えています.
clear all;
close all;
%RGBイメージを表示
RGB = imread('2007_000033.png');
%imshow(RGB)
%RGB イメージをグレースケール イメージに変換して表示
I = rgb2gray(RGB);
figure
imshow(I)
しかしながら,実行したところ,以下のようなエラーが発生しました.
エラー: rgb2gray>parse_inputs (line 80)
MAP は m 行 3 列の配列でなければなりません。
エラー: rgb2gray (line 52)
isRGB = parse_inputs(X);
これは,どのような意味なのでしょうか?

Réponse acceptée

Akira Agata
Akira Agata le 6 Oct 2020
Modifié(e) : Akira Agata le 6 Oct 2020
おそらく、もとの画像ファイルがインデックス付き画像ファイルになっていることが原因と思われます。
その場合、以下のようにいったん通常のRGB画像に変換したうえでグレースケール化すれば大丈夫です。
[IDX, cmap] = imread('2007_000033.png'); % インデックスとカラーマップを読み込み
RGB = ind2rgb(IDX, cmap); % 両者から通常のRGB画像に変換
I = rgb2gray(RGB); % グレースケール画像に変換
  1 commentaire
Kodai Sato
Kodai Sato le 6 Oct 2020
非常にわかりやすいご回答ありがとうございました.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Modify Image Colors dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!