0
votes

I need to use Matlab reshape() to achieve the following:

Say I have an image (M lines x N cols x 3). So essentially an M by N image with 3 channels for each pixel as red, green, blue.

I would like to reshape this image to become.

3 x total number of pixels

where, column 1 is RGB for image(1,1), column 2 is RGB for image(2,1), column 3 is RGB for image(3,1), . . . is RGB for image(m,1), is RGB for image(1,2) and so on ...

1

1 Answers

1
votes

You need to reshape and then transpose as follows:

im_out = reshape(im_in, [], 3).';

Note that reshape works here (gives the order you want) because it implicitly traverses the 3D-array in linear-indexing order: row subindex first, then column subindex, then 3rd-dim subindex.