Hi all, can anyone help me generate a checkerboard where i can control each square color-wise in gray scale?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ceren duygu
am 17 Dez. 2018
Kommentiert: ceren duygu
am 17 Dez. 2018
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 17 Dez. 2018
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.
Weitere Antworten (2)
Mark Sherstan
am 17 Dez. 2018
Bearbeitet: Mark Sherstan
am 17 Dez. 2018
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 Kommentare
Mark Sherstan
am 17 Dez. 2018
Image Analyst is correct, I overthought this one. Refer to his solution!
Walter Roberson
am 17 Dez. 2018
Bearbeitet: Walter Roberson
am 17 Dez. 2018
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
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!