How to subtract one color from an image?

4 ビュー (過去 30 日間)
Ankurdeep Kaur
Ankurdeep Kaur 2017 年 1 月 26 日
コメント済み: Ankurdeep Kaur 2017 年 2 月 13 日
If I have two images, both having red and black colors with RGB values [1 0 0] and [0 0 0]. The areas covered by red and black colors in both images are different. I just want to show that the two images are similar as they are having the same RGB values. I hope this can be done if somehow I am able to subtract the black color from the images and show that both the leftover color's rgb value is same.(i.e. red, [1 0 0])
  7 件のコメント
Ankurdeep Kaur
Ankurdeep Kaur 2017 年 1 月 27 日
Ok, suggest me a method to do the same.
Ankurdeep Kaur
Ankurdeep Kaur 2017 年 1 月 27 日
@Guillaume- I hope you have understood the question now. Will you suggest me something here, or shall I post a new question?

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

採用された回答

Benjamin Kraus
Benjamin Kraus 2017 年 1 月 27 日
Let's say the two images are A and B, both are MxNx3 matrices:
red = shiftdim([1 0 0],-1);
black = shiftdim([0 0 0],-1);
isAred = all(A == red, 3);
isAblack = all(A == black, 3);
isBred = all(B == red, 3);
isBblack = all(A == black, 3);
bothAandBred = isAred & isBred;
bothAandBblack = isAblack & isBblack;
bothSameColor = bothAandBred | bothAandBblack;
similarity = sum(bothSameColor(:))/numel(bothSameColor);
If you are guaranteed that the colors are all either red or black, the code above has a lot of redundancies. In that case, once you have isAred and isBred you can think of them as 2D black and white images, where white has replaced red. 1 indicates red/white, 0 indicates black. That makes the comparison (perhaps using subtraction) a lot easier.
There are also some image comparison tools in the Image Processing Toolbox you may want to consider. For example imabsdiff.
Note: The code above will only work in R2016b because of the new implicit dimension expansion that was introduced in R2016b (search for "Implicit Expansion" in the R2016b Release Note. To achieve the same behavior in R2016a or earlier you would have to use something like bsxfun.
isAred = all(bsxfun(@eq, A, shiftdim([1 0 0],-1)), 3);
  3 件のコメント
Image Analyst
Image Analyst 2017 年 2 月 11 日
Like Adam, Guillaume, and I said, you don't want to subtract different leaf images to compare them anyway.
Ankurdeep Kaur
Ankurdeep Kaur 2017 年 2 月 13 日
@Benjamin Kraus- Thank you so much for the help. I reached a step closer to my work by the help of your code. Can you please mention the algorithm you used for this similarity?

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 1 月 28 日
This question is very deceptive and confusing. You don't even have these images originally. What you have, and showed in your other post, is a continuous RGB image of a leaf. Then, somehow, in a way you have not shared with us, you classified regions in the leaf and assigned these different class colors. Presumably the different images came from different leaves. It makes little sense to subtract the pseudocolored images. I mean what if one leaf was shifted slightly in the field of view? The whole subtraction would be drastically different! Don't do that. You are on a wild goose chase, going in the wrong direction. Don't waste your time.
What you need to do to compare the images is measure a bunch of things, like area, color, texture, feret diameters, etc. that describe the leaves. Then compare the feature vectors.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by