How to add two images excluding simalar elements

The figure below shows two images and their addition. Is there a simple code or a function to avoid adding the highlighted area (triangle) in black
example.png

1 件のコメント

Guillaume
Guillaume 2019 年 3 月 21 日
What do you define as "addition" of two images? For that matter, what do you define as image?
It looks like what you're asking may be the symmetric difference
It's actually really unclear what in your figure you call an image. Is the black rectangle part of the image? In that case, what is the result of the addition of black on black. Similarly, what is the result of addition of white on white. And if the highlighted rectangle is not added, what colour should it be? black? white?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 3 月 21 日

0 投票

mask = repmat(any(first_image ~= second_image, 3), 1, 1, 3);
total = first_image;
total(mask) = total(mask) + second_image(mask);
However, keep in mind that with white being fully saturated, if you add anything to it you are going to get a white result, so adding images will not give you the result you show. Adding the two images would give you white everywhere except the place the red overlaps.

9 件のコメント

D_coder
D_coder 2019 年 3 月 21 日
The third dimension is creating a problem
Walter Roberson
Walter Roberson 2019 年 3 月 21 日
Please post the two top images separately so we can test.
Guillaume
Guillaume 2019 年 3 月 21 日
And answer my comments, because what you're doing is not image addition.
D_coder
D_coder 2019 年 3 月 21 日
編集済み: D_coder 2019 年 3 月 21 日
all i am doing is adding whatever is present inside the rectangles pixel by pixel to produce an image in the bottom. I want to exclude the triangular part from addition and just replace it with triangualar part from one of the images .
Walter Roberson
Walter Roberson 2019 年 3 月 21 日
That is what my code does. However I explained to you why the result of addition is not what you expect, and asked you to post the original images so we can test.
Guillaume
Guillaume 2019 年 3 月 22 日
Again, you will have to explain what you define by addition of two images. What you show is not image addition (as implemented in matlab by imadd). Image addition emulates the additive model of colour: addition of red + red is red, addition of white + white is white, addition of red + blue is purple, addition of red + blue + green is white. With addition, saturation always increases.
It looks like you want some other image composition method that you haven't fully described.
"all i am doing is adding whatever is present inside the rectangles pixel by pixel"
Hopefully, you're not using a loop. That can be done at once for all pixels.
Walter Roberson
Walter Roberson 2019 年 3 月 22 日
Have you considered
total = min(first_image, second_image);
D_coder
D_coder 2019 年 3 月 22 日
no it doesnt work
Walter Roberson
Walter Roberson 2019 年 3 月 22 日
Not many of us can be bothered to take your composite image and crop out sections of it in order to get images to test with. You should post the original images.

サインインしてコメントする。

タグ

質問済み:

2019 年 3 月 21 日

コメント済み:

2019 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by