MATLAB Answers

Find square cell centres in a noisy checker board/chess board image using pattern detection

11 ビュー (過去 30 日間)
Harsha K
Harsha K 2019 年 10 月 24 日
回答済み: Image Analyst 2019 年 11 月 29 日
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:
close all;
% 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');
% Calculate the hough transform of the edge detected binarised image above.
[H,T,R] = hough(BW);
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));
% 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 beginnings and ends of lines
% 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;
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.

回答 (1 件)

Image Analyst
Image Analyst 2019 年 11 月 29 日
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);
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by