Smooth Binary Image Edges

23 views (last 30 days)
Kaden
Kaden on 8 Jun 2018
Commented: Image Analyst on 7 Nov 2018
I am looking to smooth edges of a binary image (black and white). Currently I have a 3D segmented image with fairly jagged edges which I would like to smooth. The code I have written takes the image and separates it into slices, with my intention being to smooth the edge of each slice to hopefully give a good 3D smooth surface.
How can I go about making these edges smooth? I cant seem to solve this problem.
Thanks in advance!
segment_volume = int16(readanalyze([ImagePath ImageName]));
for i = 1:size(segment_volume,1)
im_temp = squeeze(segment_volume(:,i,:)); %(row, column, slice)
% Smoothing function here???
segment_volume(:,i,:) = reshape(im_temp, [1 size(im_temp)]);
end
%Save File
writeanalyze(FileName, segment_volume_smooth);

Answers (1)

Image Analyst
Image Analyst on 9 Jun 2018
A fairly good way is to just blur the image and threshold. Something like (untested)
kernel = ones(N, N, N) / N^3;
blurryImage = convn(double(binaryImage), kernel, 'same');
newBinaryImage = blurryImage > 0.5;
Increase N from 3 to some bigger odd number to get more smoothing.
  2 Comments
Eric Chadwick
Eric Chadwick on 7 Nov 2018
Hi Image Analyst. Your suggestion works well if your image consists of thick objects, but if - as in my case - you are working with a range of object sizes, this method will delete thinner objects. Do you have any suggestions to smooth edges of only the thick objects? The thin objects don't need to have smoothing done to them.
Image Analyst
Image Analyst on 7 Nov 2018
Use bwareafilt() or bwropfilt() to identify thin objects and erase those from the image, then smooth, then OR them back into the image.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!