How can I find faint objects with known general shape and location in an image?

2 ビュー (過去 30 日間)
Jason Johnson
Jason Johnson 2020 年 10 月 16 日
回答済み: Shraddha Jain 2021 年 3 月 11 日
I am trying to locate objects in an image, such as the two squares in the attached image. I then want to compare the objects dimensional accuracy relative to the intended shape. This means I should know the general shape and location of each object in the image. Normally it would be no problem to find the shapes with imbinarize() or edge() but the objects are transparent and the boundaries are too faint so all of the edge detection methods I have tried do not accurately pick up the objects edges. Just looking at the image its very obvious to the eye where these objects are so it seems like there should be a way to identify these edges.

回答 (1 件)

Shraddha Jain
Shraddha Jain 2021 年 3 月 11 日
Hi Jason,
Applying edge function directly onto the image attached above does not give desired results due to the grainy texture of the image. You would see better edge detection if the image is first smoothed out using imgaussfilt function.
Below is the code to create the binary gradient mask of the above attached image, which could further be used for edge detection of the shapes present in the image,
% Read input image
I = imread('two_squares_RG.png');
% Apply 2-D Gaussian smoothing kernel with standard deviation of 4
S = imgaussfilt(I,4);
imshowpair(I,S,'montage')
% Convert input RGB image to grayscale image
G = im2gray(S);
% Find edges
BW_mask = edge(G,'sobel');
imshow(BW_mask)
title('Binary Gradient Mask')
You can further apply morphological operations on BW to find the outline of the detected shapes. Follow this example for more information on this, https://www.mathworks.com/help/images/detecting-a-cell-using-image-segmentation.html
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by