I want to smooth the boarder of all white areas in this Binary Image (even the tiny ones). Consider it like smoothing with your hand.

45 次查看(过去 30 天)

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-24
编辑:KALYAN ACHARJYA 2019-8-24
In addition of the above links provided by @Walter morphological operations, imdilate and imclose, you may try with the following code also (@Image Analyst related answer, I cant find the link right now).
*Here image_binary is the input binary image, please note you have to manage the tradeoff between original shape changes vs. smoothness.
windowSize=12; % Decide as per your requirements
kernel=ones(windowSize)/windowSize^2;
result=conv2(single(image_binary),kernel,'same');
result=result>0.5;
image_binary(~result)=0;
figure, imshow(image_binary);
Hope it helps!
  6 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-26
Hi Saafan, as per my undestanding, all smothing operation, you bound to loose data, you have to trade off between how much smooth data vs. loss of original information.
For better smoth operartion, the resolutions / samples size should be more, so that proposed approach can follow the trend (fitting).

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2019-8-25
img = im2bw(imread('image.jpeg'));
subplot(1,2,1)
imshow(img);
subplot(1,2,2)
newimg = imdilate(img, ones(3));
imshow(newimg)
  7 个评论
Walter Roberson
Walter Roberson 2019-8-26
编辑:Walter Roberson 2019-8-26
A relevant question would be whether black and white is to be retained or if grayscale could be used, as grayscale could permit some antialiasing.

请先登录,再进行评论。


Image Analyst
Image Analyst 2019-8-26
Just blur the image with conv2() like KALYAN showed.
blurredImage = conv2(double(binaryImage), ones(3)/9, 'same');
It won't be a binary/logical image anymore, but it will be smoother. You didn't say it had to stay a binary image.
And, it it's not already obvious, you cannot smooth a boundary without losing details. I know you said blurring will lose details, but losing details is EXACTLY what you want when you smooth boundaries. If you don't lose details, it's not smoother!

Community Treasure Hunt

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

Start Hunting!

Translated by