how to divide an image diagonally into two equal part where the image size is [168 300 3]?

 Accepted Answer

A simple way would be to use triu and tril. You could do it like this:
UpperTriangle = cat(3, triu(img(:, :, 1), triu(img(:, :, 2), triu(img(:, :, 3));
LowerTriangle = cat(3, tril(img(:, :, 1), triu(iml(:, :, 2), tril(img(:, :, 3));
Or like this:
mask = true(size(img, 1), size(img ,2));
UpperTriangle = img(repmat(triu(mask), [1 1 3]));
LowerTriangle = img(repmat(tril(mask), [1 1 3]));

5 Comments

mask = true(size(img, 1), size(img ,2));
UpperTriangle = img(repmat(triu(mask), [1 1 3]);
LowerTriangle = img(repmat(tril(mask), [1 1 3]);
this is not working. showing error:
??? Subscript indices must either be real positive integers or logicals.
I forgot a closing brackets for UpperTriangle and LowerTriangle, but otherwise the code works. I don't understand how you can get that error message since mask is logical (that's what true returns).
yes,i have seen it and also run it clc; close all; workspace; format long g; format compact; fontsize=20; im=imread('12.jpg'); subplot(3,1,1); imshow(im,[]); title('org im','Fontsize',fontsize); set(gcf,'Units','Normalized', 'OuterPosition',[0 0 1 1]); set(gcf, 'Name', 'picture', 'NumberTitle', 'Off') upperPixelImage = triu(im); subplot(3, 1, 2); imshow(upperPixelImage, []); title('Upper Triangle', 'FontSize', fontSize); mask = triu(ones(size(im))) > 0; upperList = upperPixelImage(mask); lowerPixelImage = tril(im); subplot(3, 1, 3); imshow(lowerPixelImage, []); title('Lower Triangle', 'FontSize', fontSize); mask = tril(ones(size(im))) > 0; lowerList = lowerPixelImage(mask);
error : ??? Error using ==> triu First input must be 2D.
Error in ==> diag at 13 upperPixelImage = triu(im);
only the original image showing not the others
if the first input must be 2D, then what has to be done in case of 3D?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!