How can I find faint objects with known general shape and location in an image?
1 view (last 30 days)
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.
Shraddha Jain on 11 Mar 2021
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);
% Convert input RGB image to grayscale image
G = im2gray(S);
% Find edges
BW_mask = edge(G,'sobel');
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!