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 Center および File ExchangeImages についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by