Hi all, can anyone help me generate a checkerboard where i can control each square color-wise in gray scale?
6 ビュー (過去 30 日間)
古いコメントを表示
For example i should be able to control the first square from 0 to 255 in gray scale while keeping other squares all black. Then do the same for the second square and the third and so on...
I can generate the matrix to do just that but then the scaling becomes an issue. I need my checkerboard to almost fit in the screen. For practical reasons, i would really appreciate if it was easy to manipulate the size of each pixel and the total number of squares in my pattern.
Any help is appreciated.
0 件のコメント
採用された回答
Image Analyst
2018 年 12 月 17 日
To control every single square, you can't use checkerboard(). You must create an array with the desired values, then use repelem() to replicate it. Not hard - I'm sure you can do it because you're a smart engineer so give it a try.
その他の回答 (2 件)
Mark Sherstan
2018 年 12 月 17 日
編集済み: Mark Sherstan
2018 年 12 月 17 日
Use the checkboard function save it as an image and then adjust the greyscale as desired. Here is a basic example to get you going:
k = (checkerboard(10) > 0.5);
I = uint8(255 * k);
imshow(I)
2 件のコメント
Mark Sherstan
2018 年 12 月 17 日
Image Analyst is correct, I overthought this one. Refer to his solution!
Walter Roberson
2018 年 12 月 17 日
編集済み: Walter Roberson
2018 年 12 月 17 日
basic_cell = kron(eye(2), ones(pixel_height, pixel_width));
full_board = repmat(basic_cell, number_of_squares/2, number_of_squares/2);
For example,
basic_cell = kron(eye(2), ones(8,8));
full_board = rempat(basic_cell, 4, 4);
That would give you 8 squares on a side, each of which was 8 pixels by 8 pixels. The pixels would be alternating 1's and 0's.
For your purpose perhaps you would find it easier to use
full_board_cell = repmat( {0 * ones(pixel_height, pixel_width, 'uint8')}, number_of_squares, number_of_squares );
full_board = cell2mat(full_board_cell);
h = image(full_board);
colormap(gray(255));
for K = uint8(1) : uint8(255)
drawnow();
full_board_cell{1} = K * ones(pixel_height, pixel_width, 'uint8');
full_board = cell2mat(full_board_cell);
set(h, 'CData', full_board);
end
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!