MATLAB: How to randomly select n number of pixels from an image whose value is one

How to randomly select n number of pixels from an image whose value is one ?

Best Answer

ind = find(I == 1);
r = randperm(numel(ind));
r = r(1:n);
Related Question