Here is a solution I saw in a master thesis on image retrieval (variable names changed):

R =f (:,:,1);% take all of the first element

G =f (:,:,2);

B =f (:,:,3);

R =R(1:end);%make it into one column matrix

G =G(1:end);

B =B(1:end);

%concentrate these R,G,B into a single 3 dimensional matrix

imf =[R;G;B];

imf =imf';

It looks like that the author made a detour. A simple solution to this problem is

imf= reshape(f, M*N, 3);

If the function 'reshape' is not used, their code can be improved as follows:

R =R(:);%make it into one vector matrix

G =G(:);

B =B(:);

%concentrate these R,G,B into a single 3 dimensional matrix

imf =[R,G,B];

Chinese version:

Didn't you mean:

ReplyDeleteR =f (:,:,1);% take all of the first element

G =f (:,:,2);

B =f (:,:,3);

go help SQUEEZE

ReplyDeleteSQUEEZE is a function provided by MATLAB and can do the trick. But if you look at the code of squeeze, it uses reshape function.

ReplyDeleteI need to change a 3D image into 2D. However the image should stay as coloured, not gray. Because I need to generate the histogram; and imhist() only works on 2D coloured image.

ReplyDeletePlease help.

Thank you

khi

ReplyDeleteIf u did the transformation 3D image to 2D , please tell me how u did it ??

ReplyDeletebcoz I also want to do it transformation ??

i am not good in matlab graphics

how can i converted an iamge back to rgb when i have extracted all the three component from it .... can it b reshape

ReplyDeletef (:,:,1) =R;

ReplyDeletef (:,:,2) =G;

f (:,:,3) =B;

Hi guys , i would first of all like to say thank you for your code and assistance .

ReplyDeletehowever when using reshape ,the conversion operation goes on normally but when i go for "imshow" , to display the image after conversion , nothing besides a straight line appears .... Same goes when i apply "histeq" to the newly converted 2D image .

pls help , ...

Use imagesc instead.

ReplyDeleteHi Wenbin

DeleteThx for your reply , but all i got after applying the following

/

I = imread('cup.jpg');

J = reshape(I,10800,3);

imagesc(J)

/

is just a screen full of horizontal and vertical colorful lines interconnected .

I guess your cup image is a color one, and you want to convert it to gray? Use rgb2gray to convert it. Then use imshow to display it.

DeleteHi everyone. I am doing the complexity of a facial recognition algorithm one step is to use the reshape function in order to reshape a matrix. I have to understand the math behind the function i.e. the number of operations involved in the function. Would anyone be able to lend some assistance please?

ReplyDeleteworks...thanks

ReplyDelete