フィルターのクリア

Separating RGB components from two different .png files

1 回表示 (過去 30 日間)
fiona rozario
fiona rozario 2017 年 4 月 3 日
編集済み: fiona rozario 2017 年 6 月 8 日
I used a file 'facebook.png' and separated the RGB components. The following code worked fine.
if true
red=f(:,:,1); %Sieved R component
green=f(:,:,2); %Sieved G component
blue=f(:,:,3); %Sieved B component
end
But I used the same code for 'android.png' and I got an error 'Index exceeds matrix dimensions.', 'green=f(:,:,2); %Sieved G component'.
Why are the two files being treated differently?

回答 (2 件)

KSSV
KSSV 2017 年 4 月 3 日
If you read RGB image file it will be 3D matrix and hence you can separate R,G and B as you did. If the file is binary, on reading it you will get 2D matrix. Check the size of matrix obtained on reading android.png, it would be 2D. So you cannot extract it like 3D matrix and error popped.
  6 件のコメント
Image Analyst
Image Analyst 2017 年 6 月 8 日
It has a width and a height, and only one color plane. So it's 2-D. Do you have a definition of 2-D different than that?
fiona rozario
fiona rozario 2017 年 6 月 8 日
編集済み: fiona rozario 2017 年 6 月 8 日
No...I thought it would have just two colour channels and was wondering how that could be possible. Thanks, for the code below...

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


Image Analyst
Image Analyst 2017 年 6 月 8 日
See this code demo:
fontSize = 20;
filename = 'android.png';
% Read in indexed image.
[img, storedColorMap] = imread(filename);
[rows, columns, numberOfColorChannels] = size(img)
% Display indexed image without colormap being applied.
subplot(3, 2, 1);
imshow(img, []);
caption = sprintf('Indexed image without\ncolormap being applied');
title(caption, 'FontSize', fontSize);
% Display indexed image with colormap being applied.
subplot(3, 2, 2);
imshow(img, storedColorMap);
caption = sprintf('Indexed image with\ncolormap being applied');
title(caption, 'FontSize', fontSize);
% Convert to RGB image by appying the colormap
rgbImage = ind2rgb(img, storedColorMap);
% Display RGB image.
subplot(3, 2, 3);
imshow(rgbImage);
title('RGB Image', 'FontSize', fontSize);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the three color channels separately
subplot(3, 2, 4);
imshow(redChannel);
title('Red Channel Image', 'FontSize', fontSize);
subplot(3, 2, 5);
imshow(greenChannel);
title('Green Channel Image', 'FontSize', fontSize);
subplot(3, 2, 6);
imshow(blueChannel);
title('Blue Channel Image', 'FontSize', fontSize);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by