how to divide an image diagonally into two part?
Show older comments
i want to divide an image diagonally,into two equal part. how can i do this?
Accepted Answer
More Answers (1)
Image Analyst
on 19 Apr 2015
Not exactly sure what you mean so I did it two different ways, one to give a masked image and another that has a 1-D list of extracted values. Make note that the pixels along the main diagonal will occur in both the upper and lower images.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
grayImage = imread('cameraman.tif');
% Display the original gray scale image.
subplot(3, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
upperPixelImage = triu(grayImage); % 2D image
% Display the original gray scale image.
subplot(3, 1, 2);
imshow(upperPixelImage, []);
title('Upper Triangle', 'FontSize', fontSize);
% Get the 1-D list of upper values.
mask = triu(ones(size(grayImage))) > 0;
upperList = upperPixelImage(mask);
lowerPixelImage = tril(grayImage); % 2D image
% Display the original gray scale image.
subplot(3, 1, 3);
imshow(lowerPixelImage, []);
title('Lower Triangle', 'FontSize', fontSize);
% Get the 1-D list of lower values.
mask = tril(ones(size(grayImage))) > 0;
lowerList = lowerPixelImage(mask);

1 Comment
Nepoleon Keisham
on 2 Jul 2019
Edited: Nepoleon Keisham
on 2 Jul 2019
Thank you for your help but Triu is Tril works only on square matrix. Please help in finding the diagonal half of an image or a matrix, where the size of rows and column are different..png)
.png)
Categories
Find more on Contrast Adjustment in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!