如何在图像中找到K个随机的不同像素? [英] How to find K random different pixels in an image?

查看:57
本文介绍了如何在图像中找到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));

这篇关于如何在图像中找到K个随机的不同像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆