i am new at matlab and i want Create color checkerboard

8 ビュー (過去 30 日間)
abory kikla
abory kikla 2016 年 3 月 6 日
編集済み: DGM 2022 年 11 月 22 日
Please help me solve this Lab-
Coursework1 :
1 Create checkerboard image using MATLAB
1 Use the matrix manipulation to implement a color chessboard image size 1024* 1024, where each stone size 32 * 32 without any loop statement.
2 Create checkerboard image using MATLAB
1 Use the matrix manipulation to implement a color chessboard image size 1024* 1024 ,where each stone size 32 * 32 based on loop statement.  Use checkerboard/kron function to implement a color chessboard image size 1024* 1024 ,where each stone size 32 * 32.?
[Merged from duplicate question]
I want to create a chess colored using the random function and displayed using the command Amco >> Can you do it
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 3 月 6 日
編集済み: Walter Roberson 2016 年 3 月 6 日
Yes of course I can do it. But it is your homework, and you need to work on it.
(Hint: I posted code that could easily be adapted for this, no more than 6 months ago.)
Jan
Jan 2016 年 3 月 6 日
The link does work now. Please, abory kikla, show us what you have tried so far and ask a specific question. The forum will not solve your homework, because this would not be constructive.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 3 月 6 日
Try using the checkerboard function. Then threshold and call bwlabel() to assign every square a unique ID number. Then make up a colormap long enough so that you get a color for every square (this is where you could use rand()). Then apply the colormap with ind2rgb(), and finally show the RGB image with imshow(). That should be enough hints. Now, lets see your code that carries out those steps. You should get a checkerboard where the "black" squares are black and the "white" squares each have a unique color.
  31 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 29 日
Make it easy to help you, not hard. Supply us with a list of the RGB values of the various colors that you want. I don't want to type those in - I'd rather have you do that. After that, just use indexing to set the colors for each square - nothing magic or tricky about it.
DGM
DGM 2022 年 11 月 22 日
編集済み: DGM 2022 年 11 月 22 日
Here is one way:
% parameters
CT = [0 0 0; 253 242 0; 238 15 140; 0 174 237; 255 255 255]/255; % the tile colors
squaresize = [20 20]; % the size of squares [y x]
nsquares = [11 11]; % the tiling [y x]
sizeout = round(squaresize.*nsquares);
outpict = toeplitz([1 2 3 1 4 1 5 1 2 3 1],[1 5 1 4 1 3 2 1 5 1 4]); % create 1px/tile index image
outpict = imresize(outpict,sizeout,'nearest'); % expand to final size
outpict = ind2rgb(outpict,CT); % apply colormap
imshow(outpict)
Considering that the pattern appears to be cyclic, I imagine it can be generalized a bit more.
% parameters
CT = [0 0 0; 253 242 0; 238 15 140; 0 174 237; 255 255 255]/255; % the tile colors
pat = [1 2 3 1 4 1 5]; % the base tile sequence
squaresize = [20 20]; % the size of squares [y x]
nsquares = [21 21]; % the tiling [y x]
sizeout = round(squaresize.*nsquares);
c = repmat(pat,[1 ceil(nsquares(1)/numel(pat))]);
r = circshift(fliplr(repmat(pat,[1 ceil(nsquares(2)/numel(pat))])),1);
outpict = toeplitz(c(1:nsquares(1)),r(1:nsquares(1))); % create 1px/tile index image
outpict = imresize(outpict,sizeout,'nearest'); % expand to final size
outpict = ind2rgb(outpict,CT); % apply augmented colormap
imshow(outpict)
See this thread for more "colored checkerboard" answers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by