检测 RGB 图像中的像素是否属于其他两个像素之间的线 (MATLAB)
我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请记住,像素具有面积而不仅仅是点。根据您定义坐标的方式,您正在检查类似“我的像素的中心是否正好位于这些其他像素的中心之间的直线上”之类的内容,
我猜测您可能想要留出一些余地,即设置一些容差然后检查
而不是直接相等
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
instead of straight equality
尽管您可能不知道,但您正在尝试实现 Bresenham 算法 或类似算法。
You are, though you may not know it, trying to implement Bresenham's Algorithm or a similar algorithm.