Related Articles

Related Articles

Flip image across Secondary Diagonal in MATLAB
  • Last Updated : 17 Apr, 2019

The aim is to flip a colored image in MATLAB across secondary diagonal without using inbuilt functions for rotating. A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for the layers, the pixel value will determine the color of the pixel based on the color format.

Approach is very simple. We are given a colored image. We have to separate each layer. Flip every layer up to down then flip every layer right to left. Take transpose of the image.

Below is the implementation:

filter_none

edit
close

play_arrow

link
brightness_4
code

% MATLAB code to flip a colored image
% across secondary diagonal.
  
% Read a colored image
I=imread('image.jpg');
figure, imshow(uint8(I));
  
% Initilase an image 
I2 = [];
  
%iterate each layer
for k = 1:3
    Im = I(:, :, k);
  
    %Flip every layer up to down.
    Im1 = Im(end:-1:1, :); 
  
    %Flip every layer right to left.
    Im2 = Im1(:, end:-1:1); 
  
    %Take transpose of the image.
    Im3 = Im2'; 
    I2(:, :, k)=Im3;
end
  
% Show the image.
figure, imshow(uint8(I2));

chevron_right


Input Image:

Output :

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up