필터 지우기
필터 지우기

How can I find a certain shape within an image?

조회 수: 6 (최근 30일)
Samuel Harvey
Samuel Harvey 2021년 8월 10일
댓글: Image Analyst 2021년 8월 12일
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?

채택된 답변

DGM
DGM 2021년 8월 11일
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
Samuel Harvey
Samuel Harvey 2021년 8월 11일
Thanks! This is pretty much what I ended up doing and it works great.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 8월 11일
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
Samuel Harvey
Samuel Harvey 2021년 8월 11일
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 2021년 8월 12일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by