如何在图像中找到K个随机的不同像素?

问题描述:

我知道如何使用rand函数在图像范围内对x& y查找随机像素.然后循环执行K次.

I know how to find a random pixel by using rand function, for both x&y in the limits of the image. Then do it K times with a loop.

但是我想以更聪明的方式做到这一点,并确保我不会选择相同的选项 (x,y)坐标.预先感谢!

However I'd like to do it in smarter way and make sure I don't pick the same (x, y) coordinate. Thanks in advance!

使用 randperm (无需工具箱):

Use randperm (no toolbox required):

K = 10;
[h, w, c] = size(image);
[X, Y] = ind2sub([h w], randperm(h*w, K));