Extracting pixels from an image random

조회 수: 8 (최근 30일)
andrei alex
andrei alex 2019년 6월 1일
답변: Image Analyst 2019년 6월 1일
Hello,
How can I extract 100 pixels color randomly from an image ?

채택된 답변

Guillaume
Guillaume 2019년 6월 1일
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
andrei alex
andrei alex 2019년 6월 1일
Thank you .
And if I have 200 images and I want to extract 100 pixels for each?
Guillaume
Guillaume 2019년 6월 1일
Wrap that in a loop over your 200 images.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 6월 1일
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)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by