Edge detection in gradient images

조회 수: 33 (최근 30일)
autumn
autumn 2021년 9월 1일
댓글: autumn 2021년 9월 5일
Hello,
I am trying to detect a smooth boundary of an image (attached) to find contact angles of each component in contact (the whole image is not attached).
Firstly, I averaged 3*3 pixels to reduce noises and then, used 'imgradient()' to detect the boundary (subplot(2,2,3)).
To get a single boundary line, I used 'edge()' and tried different methods (Solbel, Canny, etc.), but I am getting two boundaries, which I didn't intend... Is there any way that I can get only the inner line (orange arrows are indicating) in the last picture (subplot(2,2,4))?
I googled and searched but I could not find clear solutions on this so far. I really appreciate your time and comments in advance.

채택된 답변

Image Analyst
Image Analyst 2021년 9월 1일
Just because you want the edge does not mean you should call edge(). Like you said, it can produce 2 edges. For that image you posted, you can simply threshold and call bwboundaries
mask = grayImage > 128; % or whatever number works, or imbinarize().
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(binaryImage);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
  댓글 수: 4
autumn
autumn 2021년 9월 5일
Thanks a lot ! Just one more question please. How can I append x and y in the loop, and get the final x and y matrix?
Currently, in case I run a image with 3 bourdaries, resulting x and y values are only for the final boundary.
Since 'boundaries' is cell, 3x1 here, I am not sure how to index each resulting x and y, and then append them all..
autumn
autumn 2021년 9월 5일
I googled more and added this in the loop.
arr = [x, y];
arr(:,:,k) = arr;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Simon Chan
Simon Chan 2021년 9월 1일
Try Otsu's method
rawdata=imread('capture 1.png');
I = rgb2gray(rawdata);
level = graythresh(I);
BW = imbinarize(I,level);
J = edge(BW);
imshow(J);
  댓글 수: 1
autumn
autumn 2021년 9월 4일
Thank you for the answer!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by