Segment pink color spots from image

5 views (last 30 days)
I = imread('input_image');
figure, imshow(I)
How to extract the pink colour spots in the attached image and find how much area it occupies in the light orange/peach colour region?
I tried imbinarize and multithresh, but cant identify the spots correctly. Please could someone help me to extract the pink spots and find the area it occupies in the peach colour region.

Accepted Answer

DGM
DGM on 25 Jul 2022
Edited: DGM on 25 Jul 2022
This is one example.
A = imread('pink.jpg');
% HSV thresholds for pink areas
th = [0.95 0.04;
0.15 1.00;
0.61 1.00];
% get pink areas
[H S V] = imsplit(rgb2hsv(A));
mkH = H >= th(1,1) | H <= th(1,2);
mkS = S >= th(2,1) & S <= th(2,2);
mkV = V >= th(3,1) & V <= th(3,2);
mkpink = mkH & mkS & mkV;
% clean up mask
mkpink = bwareaopen(mkpink,100);
mkpink = imfill(mkpink,'holes');
% get overall object mask
mkobj = V > 0.5 & S > 0.091;
mkobj = bwareaopen(mkobj,100);
mkobj = imfill(mkobj,'holes');
imshow(imfuse(mkpink,mkobj))
% get area ratio
arearatio = nnz(mkpink)/nnz(mkobj)
arearatio = 0.0825
Bear in mind that's not perfect. The white underlay (paper?) at the RHS is difficult to exclude from the object mask, since white doesn't separate well in HSV and reliance on S is severely limited due to the damage caused by the JPG compression. Also note that I ignored the presence of the staples.
  3 Comments
Elysi Cochin
Elysi Cochin on 20 Oct 2022
Thank you so much Sir, for your reply.

Sign in to comment.

More Answers (1)

Abderrahim. B
Abderrahim. B on 25 Jul 2022
Edited: Abderrahim. B on 25 Jul 2022
Hi!
I recommend to use Color Thresholder.
Workflow I used to get the pink color spots (picture attached) using the app is as follow:
1- Read the image
I = imread('input_image');
2- Start the app like if it was a function
colorThresholder(I)
3- Select HSV color space
4- Tune H, S and V until you segment the pink spots . Mainly H .
5. You can export the segmented image as well as generate a function for your processing.
Hope this helps

Community Treasure Hunt

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

Start Hunting!

Translated by