how to smooth the edge of a binary image

18 次查看(过去 30 天)
Hi,
I've got the bellow zoomed image which does have a not very good resolution. The image itslef is attached.
As you can see the edges between the 0 and 1 areas does not have smooth transition. I am wondering if you could advise how to increase the resolution (smooth the intersection), maybe a linear interpolation could help. Somehting like the red line in this photo:
Thanks
Navid
  3 个评论
NaviD
NaviD 2024-2-27
Thanks. Attached is the updated image.
I don't want to change the image size as I need to use this image as a mask to find the width of the artery model. I was hoping to be able to smooth the transition between black and white zones to make the calcualtion of width with less sudden variations.
Somehow this question is linked to my previous question in the forum: https://au.mathworks.com/matlabcentral/answers/2037096-find-diameter-based-on-the-centreline-and-edge#comment_3074888
Thanks
Navid
DGM
DGM 2024-2-27
I went ahead and posted a comment on the other thread which might help solve a big chunk of your problem.

请先登录,再进行评论。

回答(1 个)

Vidhi Agarwal
Vidhi Agarwal 2024-3-19
Hi NaviD,
I understand your query is regarding a method to smooth out the edges of image. Below is an approach using MATLAB that demonstrates how to:
  1. Extract the boundary of an object in a binary image.
  2. Identify key points along this boundary. (For example, uses points at regular intervals, but you could implement more sophisticated methods to choose points based on curvature or other criteria.)
  3. To approximate the boundary with straight lines, we'll use a simple method by selecting key points, we'll either manually choose significant points or select every nth point along the boundary for a straightforward simplification.
  4. Display the original boundary and the approximated straight-line boundary for comparison.
Below is the code you can try:
% Step 1: Read and process the binary image
binaryImage = imread('text.png');
if size(binaryImage, 3) == 3
binaryImage = rgb2gray(binaryImage);
end
binaryImage = logical(imbinarize(binaryImage));
% Step 2: Find the boundary of the binary object
boundaries = bwboundaries(binaryImage);
largestBoundary = boundaries{1};
% Step 3: Approximate the boundary using straight lines
% For demonstration, let's select every 10th point as a key point
keyPointsIndex = 1:10:length(largestBoundary); % Adjust the interval as needed
keyPoints = largestBoundary(keyPointsIndex, :);
% Step 4: Draw the approximated boundary
approxImage = uint8(zeros(size(binaryImage, 1), size(binaryImage, 2), 3)); % Now it's a 3-channel image
for i = 1:length(keyPoints)-1
approxImage = insertShape(approxImage, 'Line', [keyPoints(i,2), keyPoints(i,1), keyPoints(i+1,2), keyPoints(i+1,1)], 'Color', 'white', 'LineWidth', 1);
end
% Display the original and approximated images
figure;
subplot(1,2,1);
imshow(binaryImage);
title('Original Binary Image');
subplot(1,2,2);
imshow(approxImage); % Directly display approxImage without converting it back
title('Approximated Boundary Image');
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by