views:

44

answers:

2

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.

+3  A: 

An example:

I = imread('onion.png');
I2 = flipdim(I ,2);           %# horizontal flip
I3 = flipdim(I ,1);           %# vertical flip
I4 = flipdim(I3,2);    %# 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

Amro
+1  A: 

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
gnovice