两条相交线之间的像素 [英] Pixels between 2 intersecting lines
问题描述
我需要找到2行交叉之间的像素值。下图显示了我想要的点,即棕色区域。
I need to find pixel values that are between the intersection of 2 lines. The following image shows the points that I want namely the brown region.
这4个坐标可以改变,不一定是角点。
These 4 co-ordinates can change and are not necessarily the corner points.
获取像素值的最快方法是什么?是否有任何功能可以给我必要的掩码。
What is the fastest way to get the pixel values ? Is there any function that can give me the necessary mask.
推荐答案
你应该计算每个点,它是否在线上方或以下。如果该行以公式形式 Ax + By + C
给出,那么就像根据你的点计算这个表达式的符号一样简单 (X,Y)
。如果您的行以任何其他形式给出,您应首先计算上面的表格。 (参见此处和这里)
You should calculate for each point, whether it is above the line or below. If the line is given in its equation form Ax+By+C
, then it is as simple as calculating the sign of this expression, per your point (x,y)
. If your lines are given in any other form, you should first calculate the form above. (See here and here)
设 L1
是第一行以下所有点的集合, L2
第二行以下所有点的集合。然后,你的套装 X = Xor(L1,L2)
Let L1
be the set of all points below the first line, and L2
the set of all points below the second line. Then, your set is X = Xor(L1,L2)
[ < img src =https://i.stack.imgur.com/WJEay.pngalt =在此处输入图像说明> ] Xor [ ]
等于:
这是一个Matlab代码,根据我所描述的解决方案解决角点问题。您可以在代码中调整线方程。
Here is a Matlab code that solves you problem for the corner points, based on the solution that I've described. You can adjust the line equations in your code.
function CreateMask()
rows = 100;
cols = 200;
[X,Y] = ndgrid(1:cols,1:rows);
belowFirstLine = X*(1/cols) + Y*(-1/rows) + 0 < 0;
belowSecondLine = X*(-1/cols) + Y*(-1/rows) + 1 < 0;
figure;imshow( transpose(xor(belowSecondLine,belowFirstLine)));
end
这篇关于两条相交线之间的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!