How to set pixel values in 100*100 matrix?

I should set 1/3 pixels have value 50, 1/3 pixels have value 100, and remaining 1/3 pixels have value 200. How to set pixels 50, 100, 200 in 100*100 matrix?

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 25 de Oct. de 2020
Try something like this
img = zeros(100, 'uint8');
idx_all = 1:numel(img);
idxs = cell(1,3);
for i = 1:numel(idxs)-1
idx_temp = randperm(numel(idx_all), round(numel(img)/3));
idxs{i} = idx_all(idx_temp);
idx_all(idx_temp) = [];
end
idxs{end} = idx_all;
img(idxs{1}) = 50;
img(idxs{2}) = 100;
img(idxs{3}) = 200;

Más respuestas (0)

Categorías

Más información sobre Aerospace Blockset en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Oct. de 2020

Respondida:

el 25 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by