Effacer les filtres
Effacer les filtres

How can I find a certain shape within an image?

6 vues (au cours des 30 derniers jours)
Samuel Harvey
Samuel Harvey le 10 Août 2021
Commenté : Image Analyst le 12 Août 2021
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?

Réponse acceptée

DGM
DGM le 11 Août 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 commentaire
Samuel Harvey
Samuel Harvey le 11 Août 2021
Thanks! This is pretty much what I ended up doing and it works great.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 11 Août 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 commentaires
Samuel Harvey
Samuel Harvey le 11 Août 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 le 12 Août 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)

Connectez-vous pour commenter.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by