MATLAB: Closing the boundary of an image for segmentation

image processingImage Processing Toolboximage segmentation

Hi everyone,
I am working on segmentation of the particle (see attached). I need to differentiate the environment from the particle interior. I have tried the boundary functions on matlab but with no success. I will certainly appreciate any suggestion on differentiating the outside of the grey areas(environment) from the particle interior. How could I close the particle boundary?

Best Answer

I think combining boundary and poly2mask functions should be some help for your task. How about the following?
% Read the image
I = imread('sampleImg.png');
% Extract non-blue area
BW = I(:,:,3) < 140;
% Apply boundary function
[row,col] = find(BW);
k = boundary(row,col);
% Make mask from boundary result
Mask = poly2mask(col(k),row(k),size(BW,1),size(BW,2));
% Show the result
figure
subplot(1,2,1)
imshow(I)
title('Original Image','FontSize',18)
subplot(1,2,2)
imshow(Mask)
title('Mask','FontSize',18)
mask.png