Change the bottom-left half of the original image to a black right triangle.

1 view (last 30 days)
I can change the whole picture to black, but i dont know how to change just a half like that. Please help! Thank you!!

Answers (1)

Matt J
Matt J on 17 Oct 2022
Edited: Matt J on 17 Oct 2022
Hint:
triu(true(5,7))
ans = 5×7 logical array
1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 1
  2 Comments
Anna
Anna on 17 Oct 2022
x = imread('peppers.png'); imshow(x);
[r,c,s] = size(x);
y = x;
y(tril(true(r,c))) = 0;
imshow(y);
i just tried somehting like this, use tril(); but I wonder if do we have a way to select the correct diagonal of the rectangle as the figure shown in the problem?
Matt J
Matt J on 17 Oct 2022
Edited: Matt J on 17 Oct 2022
One possibility is to resize it with imresize() to make it square. Then, after blackening the lower triangle, restore the original size.

Sign in to comment.

Categories

Find more on Modify Image Colors 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!