Search code examples
matlabk-meansimread

How to convert image in form of RGB (2-D matrix)


I have an image of size 128x128. I have applied imread function of matlab on it, A= imread(first.jpg); but this is returning me a 3-D array 128x128x3 , how can I convert it to a 2-D matrix consisting of 3 columns R, G, B (one column for each color)?


Solution

  • A = imread('first.jpg');
    Npixels = size(A,1)*size(A,2);
    newA = reshape(A,[Npixels,3]);