Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

fliplr function

Status
Not open for further replies.

akabee01

Computer
Sep 16, 2006
2
I am having a problem with the fliplr function. I'm am trying to just read in an image file and then flip it. I do...

img = imread('test.jpg')
flp = fliplr(img)

but everytime I get the same error saying

??? Error using ==> fliplr
X must be a 2-D matrix.

which I really dont understand since I can cearly see the matrix for the image file. Another thing is that the function worked perfectly fine before but for some reason, after that one time it just gives that same error

Any help would be appreciated thanks
 
Replies continue below

Recommended for you

akabee01,

Is the test.jpg color by chance?

Is there some bit compression to the test.jpg?

Have you cleared the workspace and run your script again?

Hopefully one of these questions should make you consider something you might of missed and solve your problem.

Else take a look at the link below.

Mathworks

I am sorry I don't have a more direct answer.

BSK
 
i was checking the things u said but i got the same error. however i did notice when i opened an image and the import wizard comes up that the dimensions of the image was 640x480x3.

i think thats why i keep on getting the error saying x must be a 2d matrix.

can anyone tell me what does that 'x3' means and is there a way to make the matrix 640x480
 
Akabee01,

according to this website
the x3 is used to identify RGB values.

Which means Matlab is reading in your image as color or grayscale.

Regardless of this...

fliplr only works for 2 column matrixes or vectors... as read in this link.

Which means that even if you did get a 640x480 matrix for a black/white image you could still not fliplr the entire matrix.

And hopefully to answer one of your possible next questions.

If you want to flip the image top to bottom or left to right.

I would do this be reading 1 row or column out of the matrix at a time and fliplr() it and write it back into another matrix without overwriting each time through the loop.


If you want to invert the color/grayscale.

This could be done for a black/white image by checking each value in the matrix for a 1 or a 0 and inverting them. For color or grayscale you will need to come up with some conversion equation that suits your purposes.

Hopefully this helps.

BSK
 
You need to flip each color separately.

Code:
img = imread('photo.jpg');
for i=1:3   % loop through R, G and B
   imgflp(:,:,i) = fliplr(img(:,:,i));  % flip 2-D matrix
end
imshow(imgflp)  % show flipped image
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor