Asked by Harsha K
on 24 Oct 2019

Dear all,

I have a checker board/chess board pattern detection problem. I am interested in knowing the centres of the squares in my image frame.

I have tried the following approach:

clc;

close all;

clear;

% Load attached image (Extract the tiff file from the zip file :-) )

I = imread('23136695_Tilt2.tiff');

% Increase contrast of the image

I = imadjust(I);

% Crop the right half of the image for convenience and avoiding the dark

% blob on the left half of the image

I = I(:, 695:end);

% The code below is taken from Matlab help sections on detecting edges and

% examples provided by matlab users

BW = edge(I, 'Canny');

figure;

imshowpair(I,BW,'montage')

% Calculate the hough transform of the edge detected binarised image above.

figure;

[H,T,R] = hough(BW);

imshow(H,[],'XData',T,'YData',R,...

'InitialMagnification','fit');

xlabel('\theta'), ylabel('\rho');

axis on, axis normal, hold on;

% Plot the hough transform peaks by thresholding

P = houghpeaks(H,40,'threshold',ceil(0.3*max(H(:))));

x = T(P(:,2)); y = R(P(:,1));

plot(x,y,'s','color','white');

% Attempt to plot the lines (vertical and horizontal) running between the

% square cells such that cell centres can be extracted.

lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);

figure, imshow(I), hold on

max_len = 0;

for k = 1:length(lines)

xy = [lines(k).point1; lines(k).point2];

plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

% Plot beginnings and ends of lines

plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');

plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

% Determine the endpoints of the longest line segment

len = norm(lines(k).point1 - lines(k).point2);

if ( len > max_len)

max_len = len;

xy_long = xy;

end

end

As you can see, this is not the desired result. I would need the complete grid detected. Is there a simple, computationally non-intensive (as a last resort, it is still OK to be laborious task as cell centre detection will only be done once) way out to solve this.

R2018a

Answer by Image Analyst
on 29 Nov 2019 at 4:20

What I'd do is to get the sum or mean of the gray level along each direction and look for peaks.

verticalProfile = mean(grayImage, 2);

figure

subplot(2, 1, 1);

plot(verticalProfile, 'b-', 'LineWidth', 2);

grid on;

horizontalProfile = mean(grayImage, 1);

subplot(2, 1, 2);

plot(horizontalProfile, 'b-', 'LineWidth', 2);

grid on;

Then call findpeaks(). Give that a try and report back here to me.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.