看看这个
img = imread('https://i.stack.imgur.com/3GH1x.jpg'); %// read the image
bw = img(:,:,2) > 128; %// pick only green points (2nd RGB channel)
bw(275:end,:) = false; %// discard the lower flat line
[yy xx]=find(bw); %// get the x-y coordinates of green pixels
现在您可以绘制这些点:
figure;plot(xx,yy, '.');
Resulting with
如果您对线很粗(即每个 x 有多个 y 值)这一事实感到困扰,您可以简单地取平均值
uy = accumarray( xx, yy, [], @mean );
ux = 1:max(xx);
可视化线条
figure;imshow( img );hold on; plot(ux,uy,'r','LineWidth',1.5);
如果你也追求网格,那么
[gy gx] = find( max(img,[],3) < 60); %// get the darkest points
确定我们寻找的网格点x
使得许多网格点gy
有相同的gx
nx = hist(gx,1:size(img,2)); %// count how many gx per x location
gxx = find(nx > 100 ); %// only those with more than 100 are grid X
y 也一样:
ny = hist(gy,1:334);
gyy = find(ny > 100 );
删除重复项:
gxx( diff([0 gxx]) == 1 ) = [];
gyy( diff([0 gyy]) == 1 ) = [];
创建网格点
[GX GY] = meshgrid(gxx, gyy);
现在全图:
figure('Name','I MUST award Shai a FAT Bounty for this');
imshow( img );hold on;
plot(ux,uy,'r','LineWidth',1.5); %// the curve
scatter( GX(:), GY(:), 150, '+c'); %// the grid