检测 RGB 图像中的像素是否属于其他两个像素之间的线 (MATLAB)

发布于 2024-10-01 23:33:38 字数 254 浏览 5 评论 0原文

我的 matlab 项目有问题

我有一个 RGB 彩色图像,并且有两个指定的像素 (x1,y1) 和 (x2,y2) 我想检查图像中的每个像素并确定像素是否属于 (x1,y1) 和 (x2,y2) 之间的线

我尝试使用这些函数

m = (y2-y1)/(x2-x1); b= y1 - m*x1; if (y==m*x+b) then TRUE

但它几乎失败

任何人有另一种方法来解决它吗?请

谢谢

I have a problem in my matlab project

I have a RGB color image, and I have two specified pixel (x1,y1) and (x2,y2)
I want to check each pixel in the image and determine if pixel is belong to the line between (x1,y1) and (x2,y2)

I tried to use these functions

m = (y2-y1)/(x2-x1);
b= y1 - m*x1;
if (y==m*x+b) then TRUE

but it almost fails

anybody has another way to solve it ? please

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盛夏尉蓝 2024-10-08 23:33:38

请记住,像素具有面积而不仅仅是点。根据您定义坐标的方式,您正在检查类似“我的像素的中心是否正好位于这些其他像素的中心之间的直线上”之类的内容,

我猜测您可能想要留出一些余地,即设置一些容差然后检查

if abs(m*x+b -y) < tolerance  

而不是直接相等

bear in mind that pixels have area and aren't just points. depending on how you define your coordinates, you are checking something like "does the centre of my pixel lie exactly on the line between the centres of these other pixels"

i'm guessing that you may want to leave some leeway, ie set some tolerance and then check

if abs(m*x+b -y) < tolerance  

instead of straight equality

江湖彼岸 2024-10-08 23:33:38

尽管您可能不知道,但您正在尝试实现 Bresenham 算法 或类似算法。

You are, though you may not know it, trying to implement Bresenham's Algorithm or a similar algorithm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文