matlab中的网格检测 [英] Grid detection in matlab

查看:274
本文介绍了matlab中的网格检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在二进制图像中有一个网格(可以旋转)。如何使用MATLAB了解该网格的近似公式?

I have a grid in a binary image (may be rotated). How can I know approximate formula for that grid using MATLAB?

示例图片:

http://www.pami.sjtu.edu.cn/people/wyg/images/print5.jpg

有时这些黑点缺失,所以我需要公式或方法来估计这些黑点的可能中心。

Sometimes these black dots are missing, so I need formula or ‘a way’ to estimate possible center of these black dots.

我试过使用 regionprops ,它帮助我获得这些存在的黑点的中心,但不知道黑点是否缺失

I have tried by using regionprops, it help me to get center of these exist black dots, but no idea if black dots a missing

clear all
im = imread('print5.jpg');
im = im2bw(im);
[sy,sx] = size(im);
im = imcomplement(im);
im(150:200,100:150) = 0; % let some dots missing!
im = imclearborder(im);
st = regionprops(im, 'Centroid');

imshow(im) hold on;
for j = 1:numel(st)
    px = round(st(j).Centroid(1,1));
    py = round(st(j).Centroid(1,2));
    plot(px,py,'b+')
end


推荐答案

这是一种在x和y预测中使用 fft 的方式:

here's a way using fft in 1D over the x and y projection:

首先,我将模糊图像以通过高斯卷积来平滑高频噪声:

First, I'll blur the image a bit to smooth the high freq noise by convolving with a gaussian:

m=double(imread('print5.jpg'));
m=abs(m-max(m(:))); % optional line if you want to look on the black square as "signal"
H=fspecial('gaussian',7,1);
m2=conv2(m,H,'same');

然后我将获取每个轴投影的fft:

then I'll take the fft of a projection of each axis:

delta=1;
N=size(m,1);
df=1/(N*delta);        % the frequency resolution (df=1/max_T)
f_vector= df*((1:N)-1-N/2);     % frequency vector 

freq_vec=f_vector;
fft_vecx=fftshift(fft(sum(m2)));
fft_vecy=fftshift(fft(sum(m2')));
plot(freq_vec,abs(fft_vecx),freq_vec,abs(fft_vecy))

< img src =https://i.stack.imgur.com/2sGgB.pngalt =在此输入图像描述>

所以我们可以看到两个轴在0.07422处产生一个峰值,转换为1 / 0.07422像素或~13.5像素的周期。

So we can see both axis yield a peak at 0.07422 which translate to a period of 1/0.07422 pixels or ~ 13.5 pixels.

获得角度信息的更好方法是去2D,是:

A better way to get also the angle info is to go 2D, that is:

ml= log( abs( fftshift (fft2(m2)))+1);
imagesc(ml) 
colormap(bone)

然后应用简单几何或regionprops等工具如果你愿意,你可以得到正方形的角度和大小。方块的大小是1 /背景上大旋转方块的大小(位模糊,因为我模糊了图像所以尝试不用那样做),角度 atan(y / x )。正方形之间的距离是1 /中心部分中的强峰与图像中心之间的距离。

and then apply tools such as simple geometry or regionprops if you want, you can get the angle and size of the squares. The size of the square is 1/ the size of the big rotated square on the background ( bit fuzzy because I blurred the image so try to do that without that), and the angle is atan(y/x). The distance between the squares is 1/ the distance between the strong peaks in the center part to the image center.

所以如果你的门槛 ml 正确的图像说

so if you threshold ml properly image say

 imagesc(ml>11)

您可以访问该中心这个峰......

you can access the center peaks for that...

另一种方法将是对二进制图像的形态学操作,例如我对模糊图像进行阈值处理并缩小对象要点。它会删除像素,以便没有孔的对象缩小到某一点:

yet another approach will be morphological operation on a binary image, for example I threshold the blurred image and shrink objects to points. It removes pixels so that objects without holes shrink to a point:

BW=m2>100;
BW2 = bwmorph(BW,'shrink',Inf);
figure, imshow(BW2)

然后,每个网格网格网格实际上只有一个像素!所以你可以使用Hough变换将其输入 Amro的解决方案
,或者用fft进行分析,或者适合一个块等...

Then you practically have a one pixel per lattice site grid! so you can feed it to Amro's solution using Hough transform, or analyze it with fft, or fit a block, etc...

这篇关于matlab中的网格检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆