Personalized RGB Masked Image

8 views (last 30 days)
Allinone
Allinone on 22 Oct 2021
Commented: Allinone on 3 Nov 2021
Hi everyone! I'm very new in MatLab Programming.
I have a RGB image and I want that certains color pixels are white, certain pixels are black and the others grey. I used the Threshold Apps (with binary mask), but I have only black or white pixels.

Accepted Answer

Image Analyst
Image Analyst on 22 Oct 2021
I'm not sure what you are asking. So what does your original image look like? What do you mean that you want white, black, and gray pixels?
If you use the Color Thresholder app (on the Apps tab of the Tool Ribbon) you can find thresholds to segment out a certain color, like red for example. This will create a mask where it's true/1/white where there are red pixels and false/0/black where the pixels are not red.
Attach your image and explain better if you need more help.

More Answers (5)

Allinone
Allinone on 22 Oct 2021
Edited: Allinone on 22 Oct 2021
This is my Image. I have to extract a pair of colors (e.g. red and green), but in this case all red objects have to be white, all green objects have to be black and the rest grey. I hope it is more clear now.
  10 Comments
Image Analyst
Image Analyst on 28 Oct 2021
Attach the image that has all these colors that you're working with.

Sign in to comment.


Allinone
Allinone on 28 Oct 2021
I attached Green-Yellow and Yellow-Brown pairs. Do I have attach the code also?
  2 Comments
Allinone
Allinone on 29 Oct 2021
It's the same image I attached before. I attached it again.

Sign in to comment.


Image Analyst
Image Analyst on 29 Oct 2021
Doing the same thing for yellow and brown is easy and straightforward.
  3 Comments
Allinone
Allinone on 3 Nov 2021
I have created a function for each pair of colors. I would like to call these functions in the main script and see all the outputs, but I don't know how do i do. Sorry..I'm very new in MatLab..

Sign in to comment.


Image Analyst
Image Analyst on 29 Oct 2021
Doing the same thing for yellow and green is easy and straightforward.
See my other answers for different color pairs.
  1 Comment
Allinone
Allinone on 29 Oct 2021
Ok, thank you so much! I wrote the same code, but with different values, so I didn't have the gray levels..

Sign in to comment.


Image Analyst
Image Analyst on 29 Oct 2021
See my discriminant analysis color segmentation demo.
Also check out my delta E demo, attached.
I've posted several new answers this session so be sure to see them all.
  2 Comments
Image Analyst
Image Analyst on 29 Oct 2021
The delta E demo identifies all pixels that are within a certain color distance of the average color that you outlined. It finds the delta E of all pixels in the image to the average color, and then thresholds it at the delta E you specify to find colors (anywhere in the image) that are close to what you drew. For example here I drew over the red pepper and it found all red pixels that are within a delta E of 21.9 from the average red in the region I drew.
For what it's worth, I'm attaching another, slightly different demo that works with two images.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!