Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flip and rotate a color image in MATLAB

Tags:

How do I flip a color image (RGB) in MATLAB? The fliplr does not seem to work without losing the color contents, as it only deals with 2D.

As well, the imrotate may not rotate color images.

like image 296
Ursa Major Avatar asked Oct 24 '10 19:10

Ursa Major


People also ask

How do you flip an image in Matlab?

To vertically flip the image, we need to change the position of pixels. For example, the last row of the matrix will become the first row and the first who will become the last row, and so on. We can use the Matlab built-in function flip() to flip an image or a matrix.

How do you flip an image 90 degrees in Matlab?

Description. B = rot90( A ) rotates array A counterclockwise by 90 degrees. For multidimensional arrays, rot90 rotates in the plane formed by the first and second dimensions. B = rot90( A , k ) rotates array A counterclockwise by k*90 degrees, where k is an integer.


2 Answers

The function flipdim will work for N-D matrices, whereas the functions flipud and fliplr only work for 2-D matrices:

img = imread('peppers.png');     %# Load a sample image imgMirror = flipdim(img,2);      %# Flips the columns, making a mirror image imgUpsideDown = flipdim(img,1);  %# Flips the rows, making an upside-down image 

NOTE: In more recent versions of MATLAB (R2013b and newer), the function flip is now recommended instead of flipdim.

like image 121
gnovice Avatar answered Oct 31 '22 11:10

gnovice


An example:

I = imread('onion.png'); I2 = I(:,end:-1:1,:);           %# horizontal flip I3 = I(end:-1:1,:,:);           %# vertical flip I4 = I(end:-1:1,end:-1:1,:);    %# horizontal+vertical flip  subplot(2,2,1), imshow(I) subplot(2,2,2), imshow(I2) subplot(2,2,3), imshow(I3) subplot(2,2,4), imshow(I4) 

alt text

like image 34
Amro Avatar answered Oct 31 '22 10:10

Amro