How to separate an image to rgb?

14 ビュー (過去 30 日間)
Jitha
Jitha 2013 年 12 月 31 日
編集済み: DGM 2023 年 2 月 12 日
how to divide an image into its r,g,and b colour planes,

採用された回答

Image Analyst
Image Analyst 2013 年 12 月 31 日
No reshaping is needed. Simply extract the color channels you need:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then, to reverse the process and create an RGB image from three separate color channels:
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 14 日
This code would definitely work if you have an RGB image stored in a variable named rgbImage .
It is possible, however, that this is not what you want done. What you might want done might be
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
z = zeros(size(rgbImage), class(rgbImage));
redImage = z; redImage(:,:,1) = redChannel;
greenImage = z; greenImage(:,:,2) = greenChannel;
blueImage = z; blueImage(:,:,3) = blueChannel;
subplot(2,2,1); image(rgbImage);
subplot(2,2,2); image(redImage);
subplot(2,2,3); image(greenImage);
subplot(2,2,4); image(blueImage);
atersaw tigyhun
atersaw tigyhun 2019 年 7 月 29 日
移動済み: DGM 2023 年 2 月 12 日
hahaha too long

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

その他の回答 (3 件)

Sailesh Sidhwani
Sailesh Sidhwani 2018 年 10 月 25 日
編集済み: Sailesh Sidhwani 2019 年 7 月 29 日
Starting R2018b, Image Processing Toolbox has a new function "imsplit" which does exactly this: https://www.mathworks.com/help/images/ref/imsplit.html

ES
ES 2013 年 12 月 31 日
I=imread('image.jpg')
will give I (a 3d array, of size [x,y,3] )where x and y are the dimensions of the image. 3 is for R, G, and B components.
To separate out the three components, you can do a
R = reshape(I(:,:,1),[],1);
G = reshape(I(:,:,2),[],1);
B = reshape(I(:,:,3),[],1);

Negesse Tadesse
Negesse Tadesse 2019 年 7 月 29 日
編集済み: DGM 2023 年 2 月 12 日
how about imsplit function?
[R G B] = imsplit(myImage);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by