How to use masks operations and morphological filters to segment the object as shown in image c: where a is the given image, b is the background(no idea why is this given), c is what we aim for:

I thought binarizing the image would help, but the result is like so:

otherwise, I Intuitively don't see how is that possible
I thought of "Segmentation Using Morphological Watersheds" but I am not sure if this is the right way to go
Actually having the background makes this much easier:
A = im2double(rgb2gray(imread('a.png'))); % image
B = im2double(rgb2gray(imread('b.png'))); % background
D = abs(A-B)>0.12; % difference > threshold
D = imerode(D, strel('rectangle', [2 2])); % reducing spots
C = A;
C(D)=1;
subplot 121, imshow(D)
subplot 122, imshow(C)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With