flip and rotate a color image in MATLAB

colors, image, matlab

Solution

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`.

Problem

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.

Original source