Prerequisite: Image representation in MATLAB
In MATLAB, Images are stored in matrices, in which each element of the matrix corresponds to a single discrete pixel of the image. We can get the mirror image of the given image if we reverse the order of the pixels (elements of the matrix) in each row.

Code #1: Using MATLAB Library function
img = imread( 'leaf.png' );
mirror_image = flip(img, 2);
imshow(mirror_img);
title( 'Mirror image' );
|
Code #2: Using matrix manipulation
img = imread( 'leaf.png' );
mirror_image = img(:, end :, -1:, 1, :);
imshow(mirror_img);
title( 'Mirror image' );
|
Code #3: Using matrix manipulation (Using loops)
Approach:
- Read the source image file in MATLAB environment
- Get the Dimensions of the image matrix
- Reverse the order of the elements of each row in every image plane
- Display the mirror image
Below is the implementation of the above approach:
img = imread( 'leaf.png' );
[x, y, z] =size(img);
for plane = 1: z
for i = 1 : x
len = y;
for j = 1 : y
if j < y/2
temp = img(i, j, plane);
img(i, j, plane) = img(i, len, plane);
img(i, len, plane) = temp;
len = len - 1;
end
end
end
end
imshow(img);
title( 'Mirror image' );
|
Input Image: leaf.png

Output:
