How can I segment blobs in a image using the threshold filter

I want to remove the spatter which I marked red in the following image using the threshold filter. Right now as you can see I used the default options of the binarize method
bw_left = imbinarize(v1_left);
binaryimage (2).png
To remove the spatter in the image I also tried to use the adaptive threshold filter which is included in the binarize method with a sensitivity from 0.7 till 1 with no luck. As you can see the image gets worse and looks very unstable (right image)
Iblur_left = imgaussfilt(left1, 2 ); % gaussian filter to remove noise in the image
%parameters vessel filtering
options.sigmas = '0.5:0.5:3'; % vector of scales on which the vesselness is computed
options.spacing ='[1;1.5]'; % input image spacing resolution - during hessian matrix
% computation, the gaussian filter kernel size in each dimension can
% be adjusted to account for different image spacing for different
% dimensions
options.tau = 0.5; % tau:(between 0.5 and 1)parameter that controls response uniformity
% -lower tau -> more intense output response
v1_left = vesselness2D(Iblur_left, options.sigmas,options.spacing, options.tau, true);
bw_left = imbinarize(v1_left, 'adaptive','sensitivity', 0.7);
figure;
imshowpair(v1_left, bw_left, 'montage');
error.png
Is there any way to remove those spatters in the image ?
Thank you for your help

 Accepted Answer

Why not simply use bwareafilt() to throw out blobs not in the correct size range?
Are the little blobs that are closer to the big blob supposed to be kept? Aren't they splatters too? Can you post the original gray scale image also?

3 Comments

My bad, I forgot to mention the original source file is actually a video ( .cine file ) and I converted the video in a image stack using Matlab (.tif file). My goal is to write a code which automatically remove all spatter, also the little blobs that are closer to the big blob for all images.
Because the source file is a video the blobs vary from size and can be as big as the torch which can be seen in the second image.
I tried to use bwareopen() to remove small objects before , but in some images the spatter are still there. It works for the first image but for the second image it does not work. Is the bwarefilter() suited better for my problem?
%%
% image processing --------------------------------------------------------
se = strel('disk',15) % creates a disk shaped structuring element with radius 15
background_left = imopen(left1,se);
background_right = imopen(right1,se);
left_mod = left1-background_left;
right_mod = left1-background_right;
leftadjust = imadjust(left_mod, [0 0.7]); % maps the intensity values in grayscale image to new values in leftadjust
rightadjust = imadjust(right_mod, [0 0.7]);
bwleft = imbinarize(leftadjust); %creates a binary image from 2D image
bwright = imbinarize(rightadjust);
bwleft = bwareaopen(bwleft,50); % remove small objects from binary image (smaller then 50 pixels)
bwright = bwareaopen(bwright,50);
figure;
imshowpair(bwleft,bwright,'montage');
title('BW-Images');
If you're sure that the blob you want is always the biggest one, you can do
mask = bwareafilt(mask, 1); % Extract largest blob only.
If it'a always in a known location, then you can first scan the video to find the frame where it is. Then you can scan it again using that largest one as the mask for all frames to erase things outside of it, including blobs that might be mistakenly chosen as the blob you're interested in because they were the largest at one point in time. Then you can do some area filtering on the blobs inside the mask.
Thanks for your reply! The blobs location and size are arbitrary. I do not know where they are or how big they are.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!