Error when using rgb2gray in a for loop.

2 ビュー (過去 30 日間)
Ailun Yang
Ailun Yang 2020 年 4 月 2 日
回答済み: Walter Roberson 2020 年 4 月 2 日
I have four different .tif images in my folder. I want to use a for loop to load all of the images into Matlab then convert them to grayscale and then perform frame averaging on all for and display them in a montage. But I keep getting an error MAP must be a m x 3 array.
only one section of my code:
for i = 1:4
img{i} = imread(sprintf('PShot%d.tif',i));
Igray = rgb2gray(img);
end
I believe my issue is that the variables are in a cell which is messing with the rgb2gray function but im not sure. I'm fairly new to Matlab so this maybe a trivial question.

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 2 日
nfile = 4;
img = cell(nfile,1);
Igray = cell(nfile,1);
for i = 1:nfile
img{i} = imread(sprintf('PShot%d.tif',i));
Igray{i} = rgb2gray(img{i});
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by