In: Computer Science
A colored image consists of 3-D matrix values where each plane is for each color channel of RGB colors.
To reflect an image about y-axis, we need to start with the bottom row and end with the first row for all the 3 colors. For example take a binary colored image ( 1 plane => 2-D matrix) as
1 2 3 4
5 6 7 8
9 10 11 12
To reflect it about y-axis, we write this as
9 10 11 12
5 6 7 8
1 2 3 4
We can do this in MATLAB, by starting with the bottom row (denoted by end) and decreasing this by -1 at each iteration till 1.
the end:-1:1 is the code for the same in MATLAB.
Program:
img = imread('example.jpg'); % read image
subplot(2,1,1); % subplot 1
imshow(img); % display image
title('Original Image');
y_img = img(end:-1:1, :, :); % reflected image, starting with last row and end with the first row, y remains same
subplot(2,1,2); % subplot 2
imshow(y_img); % display the reflected image
title('Image reflected about y-axis');