bie*_*man 5 matlab image image-processing
我正在整理一个用示波器输出计算一些东西的程序,但是当程序现在工作时,我只是将图像导入MATLAB,然后使用ginput在生成的曲线上找到各个区域的坐标.
有没有办法,我可以采取,比如说,这个图像:
并且使用ginput或类似的东西沿着亮绿色曲线自动跟踪并将x,y坐标存储到单独的数组(可能通过能够区分曲线的颜色和背景颜色)?这样我就可以使用图片中曲线的x,y坐标的实际绘图,而不需要在数据分析中实际使用图像.
我能够得到的最接近的就是用它[x,y]=ginput
来沿着曲线捣碎鼠标按钮并生成一个巨大的阵列,但我的手指需要休息!
谢谢!
Sha*_*hai 11
看看这个
img = imread('http://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
Run Code Online (Sandbox Code Playgroud)
现在你可以绘制积分:
figure;plot(xx,yy, '.');
Run Code Online (Sandbox Code Playgroud)
结果
如果您对线条较粗(即每个x的多个y值)感到困扰,您可以简单地取平均值
uy = accumarray( xx, yy, [], @mean );
ux = 1:max(xx);
Run Code Online (Sandbox Code Playgroud)
可视化线
figure;imshow( img );hold on; plot(ux,uy,'r','LineWidth',1.5);
Run Code Online (Sandbox Code Playgroud)
如果你也在网格之后,那么
[gy gx] = find( max(img,[],3) < 60); %// get the darkest points
Run Code Online (Sandbox Code Playgroud)
为了确定我们寻找的网格点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
Run Code Online (Sandbox Code Playgroud)
同样的y:
ny = hist(gy,1:334);
gyy = find(ny > 100 );
Run Code Online (Sandbox Code Playgroud)
删除重复项:
gxx( diff([0 gxx]) == 1 ) = [];
gyy( diff([0 gyy]) == 1 ) = [];
Run Code Online (Sandbox Code Playgroud)
创建网格点
[GX GY] = meshgrid(gxx, gyy);
Run Code Online (Sandbox Code Playgroud)
现在全貌:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2173 次 |
最近记录: |