How to label the blank space in a image ?

조회 수: 3 (최근 30일)
Chiriac Andrei
Chiriac Andrei 2016년 12월 5일
댓글: Chiriac Andrei 2016년 12월 6일
Hi.I have a problem in identifying an object in a image. I have 9 squares organized like a matrix,3x3,in each square I can have the letter X,number 0 or blank space.I managed to identify the X and 0 with bwlabel and OCR but I can't think of a solution to identify the blank space.If I can recognize the blank space then I can predict if the winner will be X or 0.Any ideas? This image is pretty similar with the images i'm working Image Example . Thanks.
  댓글 수: 4
Chiriac Andrei
Chiriac Andrei 2016년 12월 6일
@Mohammad Taheri,yes,i can find the number of blank spaces but i need the position,not the numbers. @Adam if the line is completely empty,or just 1 x or 0 there how can i figure out if the X/0 it's on (0,1) position,(0,2) or (0,3) ?
Adam
Adam 2016년 12월 6일
Well I don't know how you are identifying it, but I assumed that such identification would come with a location, otherwise how does it count as being identified?

댓글을 달려면 로그인하십시오.

답변 (1개)

Cyrus
Cyrus 2016년 12월 6일
편집: Cyrus 2016년 12월 6일
Here you go:
The matrix named Blank_Matrix has the location of blank squares as 1; else the value is 0.
clear all; close all; clc;
I = imread('xsio.gif');
figure(), imshow(I), title('Input Image')
impixelinfo
Crop_Begin_X = 7;
Crop_Begin_Y = 21;
Width = 219; %%Col
Height = 219; %%Row
%%Cropping the Image.
Cropped_Image = imcrop (I, [Crop_Begin_X, Crop_Begin_Y, Width, Height]);
figure(), imshow(Cropped_Image), title('Cropped_Image')
impixelinfo
%%Convertnig to Black and White
BW_Image = im2bw(Cropped_Image);
figure(), imshow(BW_Image), title('BW_Image')
impixelinfo
[Row, Col] = size(BW_Image);
Crop_Begin_X = 7;
Crop_Begin_Y = 21;
Width = 219; %%Col
Height = 219; %%Row
Blank_Matrix = zeros(3, 3);
Matrix_Row = 0;
Matrix_Col = 0;
Width_of_the_Square = 72;
y=1;
while y + Width_of_the_Square <= Col
Matrix_Col = Matrix_Col+1;
Matrix_Row = 0;
fprintf('Matrix_Col = %d\n', Matrix_Col);
x = 1;
while x + Width_of_the_Square <= Row
Matrix_Row= Matrix_Row+ 1;
fprintf('Matrix_Row = %d\n\n', Matrix_Row);
TMP_title = ' Not Blank' ;
Square = imcrop (BW_Image, [x, y, 72, 72]);
Number_of_White_Pixels = 0;
for i = 1 : Width_of_the_Square
for j = 1 : Width_of_the_Square
if Square(i, j) == 1
Number_of_White_Pixels = Number_of_White_Pixels + 1;
end
end
end
if Number_of_White_Pixels >= 4500
TMP_title = 'Blank';
Blank_Matrix(Matrix_Col, Matrix_Row) = 1;
end
hold on
figure()
imshow(Square), title(TMP_title)
pause(0.5);
hold off
x =x + Width_of_the_Square;
end
y = y + Width_of_the_Square;
end
  댓글 수: 1
Chiriac Andrei
Chiriac Andrei 2016년 12월 6일
This is a good solution if the size of the squares are always the same but in my case,i forgot to mention, the squares will be handwritten on a board or a paper and the size will be different almost every time...

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by