# Edge detection in gradient images

14 views (last 30 days)
autumn on 1 Sep 2021
Commented: autumn on 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.

Image Analyst on 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.
autumn on 5 Sep 2021
arr = [x, y];
arr(:,:,k) = arr;

Simon Chan on 1 Sep 2021
Try Otsu's method
I = rgb2gray(rawdata);
level = graythresh(I);
BW = imbinarize(I,level);
J = edge(BW);
imshow(J);
autumn on 4 Sep 2021

R2018a

### Community Treasure Hunt

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

Start Hunting!