How to separate RGB values of an image.

조회 수: 1 (최근 30일)
Niranjan
Niranjan 2011년 2월 1일
편집: Sailesh Sidhwani 2020년 9월 3일
We know that each pixel i in the input image I has rgb colors. My question is how to store them in a 3-vector Ii. Each color is being represented using a 64-bit floating-point number scaled to between 0 and 1.

채택된 답변

Jim Dowd
Jim Dowd 2011년 2월 1일
Sean de has told you how to get each plane, but it sounds like you want some kind of vector. I am not sure what you mean by a 3 vector, but here are a couple of guesses.
If you want 3 vectors:
R = reshape(I(:,:,1),[],1);
G = reshape(I(:,:,2),[],1);
B = reshape(I(:,:,3),[],1);
Now if you want them all together in a 3 column vector:
V3 = reshape(A(:),[],3) % R is first col, G is second col, B is third.
  댓글 수: 3
Vespi
Vespi 2016년 3월 6일
I extracted RGB values of my image using this code. I now have a .txt file with 3 columns. I was wondering how MatLab reads the image so that I can assign the pixel number corresponding to each RGB value in my .txt file.
Walter Roberson
Walter Roberson 2016년 3월 6일
MATLAB goes "down columns" in constructing the above. So if there were, for example, 5 rows of pixels in the image, the order in the file would be
(1,1)
(2,1)
(3,1)
(4,1)
(5,1)
(1,2)
(2,2)
(3,2)
(4,2)
(5,2)
(1,3)
(2,3)
...

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Sailesh Sidhwani
Sailesh Sidhwani 2018년 10월 25일
편집: Sailesh Sidhwani 2020년 9월 3일
Starting R2018b, Image Processing Toolbox has a new function "imsplit" which does exactly this: https://www.mathworks.com/help/images/ref/imsplit.html

Sean de Wolski
Sean de Wolski 2011년 2월 1일
Rchannel = I(:,:,1);
Gchannel = I(:,:,2);
Bchannel = I(:,:,3);
  댓글 수: 2
Abinaya
Abinaya 2014년 5월 6일
can you pls explain that 1 2 3 in each channel.
Walter Roberson
Walter Roberson 2018년 10월 25일
It is by definition: MATLAB interprets the first pane of the third dimension as being red values, the second pane of the third dimension as being green values, the third pane of the third dimension as being blue values.
That particular ordering is arbitrary: there is no reason why it could not have been Green, Red, Blue for example, which would have made some sense in terms of the sensitivity of the human eye to brightness in daylight. Or it could have been Blue that was first, reflecting the fact that the human eye is most sensitive to contrast in the blues. But for whatever reason, RGB was the order standardized on.

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2011년 2월 1일
You could also do it so you have a cell array with each index being a 3x1 vector, perhaps:
I2 = cellfun(@squeeze,num2cell(I,3),'uni',false);

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by