How to separate RGB values of an image?

J
Jessica · Sep 30, 2020 · 1.8K views
Question
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.
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 14, 2026
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.
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!