0% found this document useful (0 votes)
14 views3 pages

Matrix 2 Chessboard

Generating chessboard through matrix

Uploaded by

HCl007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Matrix 2 Chessboard

Generating chessboard through matrix

Uploaded by

HCl007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

% MATLAB is really good at calculating matrices

% Now, we write 8*8 matrix named CB that has 8 rows and 8 columns

CB = [1 0 1 0 1 0 1 0; 0 1 0 1 0 1 0 1; 1 0 1 0 1 0 1 0; 0 1 0 1 0 1 0 1; 1 0
1 0 1 0 1 0; 0 1 0 1 0 1 0 1; 1 0 1 0 1 0 1 0; 0 1 0 1 0 1 0 1]

% Now, we use imshow function to apply values for each pixel's intensity
% Thus we plot 8*8 pixel image of chessboard.

imshow(CB)

% imshow function assumes highest value to be of minimum intensity


% And lowest value to be of maximum intensity

% BONUS

% Alternatively, we can turn image into 3 matrices(assuming RGB channels)

% Load the image(you can tweak image path in your code environment)
imageFile = '/MATLAB Drive/chessboard_matrix/willsmitheats spaghetti.jpg';
img = imread(imageFile);

% Display the original image


figure
imshow(img)
title('Original Image')

% Get the size of the image


[rows, cols, channels] = size(img);

% Reshape the image to create a 3-row matrix (R, G, B channels)


% Extract each color channel (R, G, B)
redChannel = img(:, :, 1);
greenChannel = img(:, :, 2);
blueChannel = img(:, :, 3);

% Display each color channel separately


figure
subplot(1, 3, 1)
imshow(redChannel)
title('Red Channel')

subplot(1, 3, 2)
imshow(greenChannel)
title('Green Channel')

subplot(1, 3, 3)
imshow(blueChannel)

1
title('Blue Channel')

% We turned RGB image into matrices, then divided it into three intensity
% R, G, B channels

CB =

1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1

2
Published with MATLAB® R2024b

You might also like