How can I find a certain shape within an image?
Show older comments
I have a script that takes values from these velocity curves, but I'd like to automatically calculate the coordinates for each of the cyan crosses.

This is the mask I'm currently using. I've tried using normxcorr2 to match up a cross template with the crosses but it seems to get confused when the crosses are right next to the curves.

How should I go about this?
Accepted Answer
More Answers (1)
Image Analyst
on 11 Aug 2021
What is your actual starting data? Do you have a 1-D signal (y values and maybe x values too)? Or is all you have an image with colored boundaries burned into it? If all you have is the image, then how did it get created? Who created it? Is it possible to write out the colored curves you show on the image in a .mat, .csv, or .txt file?
If you have the y signals, I'd just find the peaks with findpeaks,
[peakValues, indexesOfPeaks] = findpeaks(ytop, 'MinPeakDistance', n); % n is approximately half the distance between major peaks.
then find the separation
ySeparation = yTop - yBottom;
then "fall down" the left side of the peaks until the separation begins to get larger
Like for one peak
for k = indexesOfPeaks(1)-1 : -1 : 1
if ySeparation(k) > ySeparation(k+1)
cyanIndex = k;
break;
end
end
Repeat for the other peaks. This will give you the location where the separation is narrowest just to the left of the big peaks.
2 Comments
Samuel Harvey
on 11 Aug 2021
Image Analyst
on 12 Aug 2021
Then try this (untested)
[r,g,b] = imsplit(rgbImage);
mask = (r == 0) & (g == 255) & (b == 255); % Find cyan blobs.
% Find centroids of cyan blobs.
props = regionprops(mask, 'Centroid');
% Get all (x,y) centroid coordinates into a nice 2-D matrix.
% xCentroid in column 1, yCentroid in column2.
xy = vertcat(props.Centroid)
Categories
Find more on Template Matching in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!