Edge detection in gradient images

32 Ansichten (letzte 30 Tage)
autumn
autumn am 1 Sep. 2021
Kommentiert: autumn am 5 Sep. 2021
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 1 Sep. 2021
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 Kommentare
autumn
autumn am 5 Sep. 2021
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 am 5 Sep. 2021
I googled more and added this in the loop.
arr = [x, y];
arr(:,:,k) = arr;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Simon Chan
Simon Chan am 1 Sep. 2021
Try Otsu's method
rawdata=imread('capture 1.png');
I = rgb2gray(rawdata);
level = graythresh(I);
BW = imbinarize(I,level);
J = edge(BW);
imshow(J);

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by