Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Checkerboard

                 I came across the matlab built in function checkerboard. And I tried to implement my own code.
First I declared the size of each square and then the number of rows and columns. Then I declared two matrixes initialized with zeros and ones. Using mod 2 I changed the colors or ones and zeros alternatively.
MATLAB CODE:
%Size of the square
sz=45;
%Number of rows
xvalue=8;
%Number of columns
yvalue=8;
%Intialize matrix A with zeros and matrix B with ones
A=zeros([sz sz]);
B=ones([sz sz]);
clear C
 m=sz;
 n=1;
 num=2;
for i=1:xvalue
    n1=1;
    m1=sz;
   
    for j=1:yvalue
        if(mod(num,2)==0)
        C(n:m,n1:m1)=A;
        num=num+1;
        else
        C(n:m,n1:m1)=B;
        num=num+1;
        end
       
        m1=m1+sz;
        n1=n1+sz;
    end
    if(mod(yvalue,2)==0)
    num=num+1;
    end
    n=n+sz;
    m=m+sz;
end
imshow(C)

8X8 size:45

8X20 size:15
              
like button Like "IMAGE PROCESSING" page

1 comments:

Unknown said... Reply to comment


Thank you so much for this program use it I wish there's explanation about the directives written in MATLAB to write this program

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Google ping Hypersmash.com