检测RGB图像中的像素是否属于另外两个像素之间的线(MATLAB) [英] detect if a pixel in RGB image belong to a line between two other pixels (MATLAB)
问题描述
我的matlab项目有问题
I have a problem in my matlab project
我有一个RGB彩色图像,我有两个指定的像素(x1,y1)和(x2,y2)
我想检查图像中的每个像素,并确定像素是否属于(x1,y1)和(x2,y2)之间的线
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试图使用这些函数
m =(y2-y1)/(x2-x1);
b = y1 - m * x1;
如果(y == m * x + b)则为TRUE
m = (y2-y1)/(x2-x1); b= y1 - m*x1; if (y==m*x+b) then TRUE
但它几乎失败
任何人都有另一种解决方法吗?请
anybody has another way to solve it ? please
谢谢
推荐答案
请记住像素有面积和不仅仅是积分。根据你如何定义坐标,你要检查的是我的像素的中心是否正好位于这些其他像素的中心之间的线上
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'我猜你可能想留下一些余地,即设置一些容忍度,然后检查
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
而不是直接平等
这篇关于检测RGB图像中的像素是否属于另外两个像素之间的线(MATLAB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!