Extracting pixels from an image random

8 visualizaciones (últimos 30 días)
andrei alex
andrei alex el 1 de Jun. de 2019
Respondida: Image Analyst el 1 de Jun. de 2019
Hello,
How can I extract 100 pixels color randomly from an image ?

Respuesta aceptada

Guillaume
Guillaume el 1 de Jun. de 2019
One way:
row = randi(size(yourimage, 1), 100, 1); %select 100 row coordinates at random
col = randi(size(yourimage, 1), 100, 1); %and 100 columns to go with it
rgb = yourimage(sub2ind(size(yourimage), repmat(row, 1, 3), repmat(col, 1, 3), repmat(1:3, 100, 1)));
%for pretty display
table(row, col, rgb)
  2 comentarios
andrei alex
andrei alex el 1 de Jun. de 2019
Thank you .
And if I have 200 images and I want to extract 100 pixels for each?
Guillaume
Guillaume el 1 de Jun. de 2019
Wrap that in a loop over your 200 images.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 1 de Jun. de 2019
Here is another way:
% Load standard demo RGB image:
rgbImage = imread('peppers.png');
% Extract the individual red, green, and blue color channels:
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get 100 random locations:
locations = randperm(numel(redChannel), 100)
% Get R, G, and B values at those locations:
redValues = redChannel(locations)
greenValues = greenChannel(locations)
blueValues = blueChannel(locations)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by