image processing - Grid detection in matlab -


i have grid in binary image (may rotated). how can know approximate formula grid using matlab?

example image:

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

sometimes these black dots missing, need formula or ‘a way’ estimate possible center of these black dots.

i have tried using regionprops, me center of these exist black dots, no idea if black dots missing

clear im = imread('print5.jpg'); im = im2bw(im); [sy,sx] = size(im); im = imcomplement(im); im(150:200,100:150) = 0; % let dots missing! im = imclearborder(im); st = regionprops(im, 'centroid');  imshow(im) hold on; j = 1:numel(st)     px = round(st(j).centroid(1,1));     py = round(st(j).centroid(1,2));     plot(px,py,'b+') end 

here's way using fft in 1d on x , y projection:

first, i'll blur image bit smooth high freq noise convolving gaussian:

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

then i'll take fft of projection of each axis:

delta=1; n=size(m,1); df=1/(n*delta);        % 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)) 

enter image description here

so can see both axis yield peak @ 0.07422 translate period of 1/0.07422 pixels or ~ 13.5 pixels.

a better way angle info go 2d, is:

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

enter image description here

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

so if threshold ml image say

 imagesc(ml>11) 

you can access center peaks that...

yet approach morphological operation on binary image, example threshold blurred image , shrink objects points. removes pixels objects without holes shrink point:

bw=m2>100; bw2 = bwmorph(bw,'shrink',inf); figure, imshow(bw2) 

enter image description here

then practically have 1 pixel per lattice site grid! can feed amro's solution using hough transform, or analyze fft, or fit block, etc...


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -