MATLAB: Extracting pixels from an image random

extractimage processingMATLAB

Hello,
How can I extract 100 pixels color randomly from an image ?

Best Answer

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)