How do i output a desired variables instead of number for image processing?

In my class I have a group assignment where we use image processing in order to identify differences on a chess board. What i'm doing is outputting changes on the chess board. For example if i moved a pawn two spaces up i'm trying to get MATLab to output pixel values on the coordinate system of where the pawn was and where the pawn is now. I am pretty close in achieving my goal but in instead of x,y pixel values i want MATLab chess cells (for example A8,A6,D5 etc.) I want to input 4 different xy pixel values which which will be a domain of one square shell on the chess board. When i run the program instead of MATLab spitting xy pixel value i will get values like A1,D3,C4 etc. There are 64 cells so it may take awhile. Completely lost please help, here is our code so far.
x = imread('IMG_1932.jpg');
y = imread('IMG_1933.jpg');
t = imread('IMG_1902.jpg');
f = imread('IMG_1929.jpg');
g = imread('IMG_1930.jpg');
z = imabsdiff(x,y);
z1 = imabsdiff(x,t);
z2 = imabsdiff(f,g);
gray1 = rgb2gray(x);
gray2 = rgb2gray(y);
gray3 = rgb2gray(z);
gray4 = rgb2gray(z1);
gray5 = rgb2gray(z2);
for start_row=281:195:1853;
for start_col=400:195:1991;
crop = gray5(start_row+50:start_row+150, start_col+50:start_col+150, :);
%figure,imshow(crop)
b = find(gray5 >180);
if gray5(b)
A = [start_col start_row]
end
else
A = [0 0]
end
end
end
pause
close all
}
if you see in my code 'A' is the values where MATLab detects pieces. We already have taken two picture took the difference of the pawn in on position and then in the next. I am just trying to figure out when i run the program instead of 'A = 1370 930' i want A to output 'A= D5'. 'if' statements???
i hope my question is clear

1 Comment

It is not getting clear to me. At first I suggest to make it as easy as possible for the ones, who want to answer: Omit all lines, which have bo connection to the problem. gray1, gray2, gray3, gray4?? pause?? close all?? crop?? z?? z1?? Never used! What is the purpose of "if gray5(find(gray5 > 180))"? Are you sure this does what you want?

Sign in to comment.

 Accepted Answer

f = imread('IMG_1929.jpg');
g = imread('IMG_1930.jpg');
gray5 = rgb2gray(imabsdiff(f,g));
RowName = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
ColName = {'1', '2', '3', '4', '5', '6', '7', '8'};
RowPos = 281:195:1853;
ColPos = 400:195:1991;
A = [];
for row = 1:8
start_row = RowPos(row);
for col = 1:8
start_col = ColPos(col);
crop = gray5(start_row+50:start_row+150, ...
start_col+50:start_col+150, :);
% b = find(crop >180); % *Not* the whole gray5 array!
%if ~isempty(b) % Better:
if any(crop(:) > 180)
A = [RowName{row}, ColName{col}];
end
end
end
Now A is either the empty matrix, or a string like 'D5'.

1 Comment

Thanks alot man!! all that other stuff was just trial and error stuff. We're no that MATLab savvy, (at least i'm not). Thanks, i might have more questions

Sign in to comment.

More Answers (0)

Tags

Asked:

on 4 Mar 2011

Community Treasure Hunt

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

Start Hunting!