Clear Filters
Clear Filters

How can I find a certain shape within an image?

6 views (last 30 days)
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

DGM
DGM on 11 Aug 2021
Is it necessary to use normxcorr? The content seems reasonably seperable by color.
inpict = imread('crosswav.jpg');
mask = inpict(:,:,1)<20 & inpict(:,:,2)>=210 & inpict(:,:,3)>=210;
S = regionprops(mask);
C = vertcat(S.Centroid);
imshow(inpict); hold on;
plot(C(:,1),C(:,2),'k+')
That said, I sure hope that the actual images aren't tiny jpegs. Don't let MATLAB save images as JPG if you ever intend to post-process them. It uses abnormally low-fidelity parameters for JPG encoding.
  1 Comment
Samuel Harvey
Samuel Harvey on 11 Aug 2021
Thanks! This is pretty much what I ended up doing and it works great.

Sign in to comment.

More Answers (1)

Image Analyst
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
Samuel Harvey on 11 Aug 2021
Unfortunately yes, I only have these images with the colored lines. We use other software to create them from Doppler velocity imaging but it doesn't have the functionality to export the results in a numeric format yet.
Image Analyst
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)

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!