フィルターのクリア

??? Index exceeds matrix dimensions

2 ビュー (過去 30 日間)
MatlabFan
MatlabFan 2013 年 3 月 11 日
why do I get the error ??? Index exceeds matrix dimensions.
Error in ==> ImagExperiment at 38 g=rgb{N}(:,:,2); when trying to run the code:
A=cell(1,Num);
rgb=cell(1,Num);
for N=1:Num
rgb{N} = imread(sprintf('test_image_%d.png', N));
r=rgb{N}(:,:,1);
g=rgb{N}(:,:,2);
b=rgb{N}(:,:,3);
end
How can I solve this problem?
Your support will be well-appreciated. Thanks.

採用された回答

Jan
Jan 2013 年 3 月 11 日
The error appears, if the corresponding picture is a grayscale image. So test this at first:
aRGB = imread(sprintf('test_image_%d.png', N));
if ndims(aRGB) == 3
r = aRGB(:, :, 1);
g = aRGB(:, :, 2);
b = aRGB(:, :, 3);
else
... any code to catch gray scale images, which are matrices
end
  1 件のコメント
MatlabFan
MatlabFan 2013 年 3 月 11 日
Yes indeed Jan, it appears the picture is a grayscale image, but how do I capture the RGB values of each pixel in a grayscale image? more like:
aRGB = imread(sprintf('test_image_%d.png', N));
if ndims(aRGB) == 3
r = aRGB(:, :, 1);
g = aRGB(:, :, 2);
b = aRGB(:, :, 3);
else
r=?
g=?
b=?
end
Thanks.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by