Search code examples
imagematlabanalysisimreadimage-thresholding

MATLAB Image thresholding Issue


I have the following image that I am attempting to analyse, the idea is to outline the droplet so that I can then get its boundaries using bwboundaries.

Original Image

My code is currently

image = imread('IMG00022.jpg');

BW = im2bw(image, 0.35);
BW = ~BW;
BW = imfill(BW,'holes');

which results in the following output. It includes the edges around the droplet that are of similar colour to the border.

Current Output

The goal is to achieve the below output. How can I go about rectifying this problem? Is the solution to use a threshold range rather than a static value (I am not sure if this would even resolve the issue) or is there another way?

Thanks in advance.

Goal Output


Solution

  • A small opening will get you where you need to be:

    se = strel('disk',11);
    BW = imopen(BW,se);
    

    Adjust the size (11) to what you need to get everything except the droplet removed.