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 flip the given image vertically (along the x-axis), if we reverse the order of the pixels (elements of the matrix) in each column as illustrated in the below image.

Code #1: Using MATLAB Library function
% Read the target image file img = imread('leaf.png'); % Reverse the order of the element in each column vertFlip_img = flip(img, 1); % Display the vertically flipped image imshow(vertFlip_img); title('Vertically flipped image'); |
Code #2: Using matrix manipulation
% Read the target image file img = imread('leaf.png'); % Flip the columns vertically vertFlip_img = img(end : -1: 1, :, :); % Display the vertically flipped image imshow(vertFlip_img); title('Vertically flipped 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 column in every image plane
- Display the water image (vertically flipped image).
Below is the implementation of the above approach:
% Read the target image file img = imread('leaf.png'); % Get the dimensions of the image [x, y, z] = size(img); % Reverse elements of each column % in each image plane (dimension) for plane = 1 : z len = x; for i = 1 : x for j = 1 : y % To reverse the order of the element % of a column we can swap the % topmost element of the row with % its bottom-most element if i < x/2 temp = img(i, j, plane); img(i, j, plane) = img(len, j, plane); img(len, j, plane) = temp; end end len = len - 1; endend % Display the vertically flipped image imshow(img); title('Vertically flipped image'); |
Input image: leaf.png

Output:

Recommended Posts:
- Flip image across Secondary Diagonal in MATLAB
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- MATLAB | RGB image to grayscale image conversion
- Matlab | Dilation of an Image
- Matlab | Erosion of an Image
- Negative of an image in MATLAB
- MATLAB | RGB image representation
- Image Complement in Matlab
- Image Resizing in Matlab
- MATLAB | Complement colors in RGB Image
- Extract bit planes from an Image in Matlab
- LSB based Image steganography using MATLAB
- Create Mirror Image using MATLAB
- MATLAB | Complement colors in a Binary image
- MATLAB | Display histogram of a grayscale Image
- MATLAB | Complement colors in a Grayscale Image
- Image Processing in MATLAB | Fundamental Operations
- MATLAB - Butterworth Highpass Filter in Image Processing
- MATLAB - Butterworth Lowpass Filter in Image Processing
- Matlab | Edge Detection of an image without using in-built function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

