How can I detect corner points where an object contacts a line/surface?

8 views (last 30 days)
I have a grayscale image of an object sitting on a flat surface. I would like to use a function like detectFASTFeatures or detectHarrisFeatures to find the points where the object contacts the surface. If I specify the ROI Name-Value Argument as a 1-pixel-high rectangle corresponding to the surface, no corners are detected, presumably because image regions outside the ROI aren't used to detect corners inside the ROI. How can I find the points where the object contacts the surface?
  2 Comments
Image Analyst
Image Analyst on 9 Dec 2021
You forgot to attach your image. I'll check back later, after you read this:
By the way, you cannot have corners if your image is only one pixel high. It's essentially not an image but just a vector. Maybe try findchangepts(). Not sure why you want an ROI that is only one pixel high though. Maybe if you had attached the image it would have been obvious.
Ryan McGowan
Ryan McGowan on 10 Dec 2021
Edited: Ryan McGowan on 10 Dec 2021
Here is an example image for one potential application (determining contact angle of a droplet). I would want to plot the blue lines on either side of the droplet. My code defines a vector of x-y coordinates corresponding to the surface line. The reason I was thinking of using a 1-pixel-high ROI was to constrain the corners to be on this line, but as you mention I still need the rest of the image to determine the corners. I can't fit an ellipse and find the intersection with the surface like in the image, because the object isn't always a well-defined shape.

Sign in to comment.

Answers (1)

Shubham
Shubham on 16 Apr 2024 at 9:47
Hi Ryan,
To find the points where an object contacts the surface in a grayscale image, especially when using functions like detectFASTFeatures or detectHarrisFeatures that rely on corner detection, you need to consider that these algorithms look for corners within the specified Region of Interest (ROI) based on the contrast and structure within that ROI. If the ROI is too narrow (e.g., a 1-pixel-high rectangle), there might not be enough information for these algorithms to work effectively.
However, you can work around this limitation by strategically selecting a slightly larger ROI that includes both the surface and a part of the object sitting on it. This way, the algorithms have enough context to identify corners or features that are indicative of the contact points. Here's a step-by-step approach to achieve this:
Step 1: Define an Expanded ROI
Instead of a 1-pixel-high rectangle, define an ROI that includes a few pixels above the surface where the object sits. This area should be thin enough to focus on the contact region but thick enough to include some part of the object and the surface for the algorithms to analyze.
Step 2: Apply Corner Detection
Use detectFASTFeatures, detectHarrisFeatures, or any similar function on the defined ROI. Since the ROI now includes parts of both the object and the surface, these functions can use the contrast between the object and the surface to detect features.
Step 3: Filter Detected Features
After detecting features within the expanded ROI, you might need to filter them to identify which ones are likely to represent contact points. This filtering could be based on criteria such as the feature's position within the ROI, the feature's metric (strength), or other image properties.
Example Code:
% Read and display the grayscale image
I = imread('path_to_your_image.jpg');
imshow(I);
hold on;
% Define an expanded ROI
% Assume the surface is at the bottom of the image
height = size(I, 1);
width = size(I, 2);
surfaceY = height - 10; % Example: 10 pixels above the bottom
roiHeight = 20; % Example: 20 pixels tall ROI
roi = [1, surfaceY, width, roiHeight];
% Detect features within the ROI
features = detectFASTFeatures(I, 'ROI', roi);
% Alternatively, use detectHarrisFeatures or any other feature detection function
% Display the detected features
plot(features);
% Additional filtering of features can be done based on specific criteria
Step 4: Additional Considerations
  • Adjust the ROI's height based on the resolution of your image and the size of the object.
  • Experiment with different feature detectors and their parameters to see which one works best for your specific image and application.
  • Consider preprocessing steps like edge detection or contrast enhancement on the ROI before applying the feature detection to enhance the results.
This approach balances the need for context within the ROI against the desire to focus on the contact region, allowing for effective use of corner detection algorithms to find where the object contacts the surface.

Community Treasure Hunt

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

Start Hunting!