×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

fliplr function

fliplr function

fliplr function

(OP)
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

RE: fliplr function

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

RE: fliplr function

(OP)
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

RE: fliplr function

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

RE: fliplr function

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources