如何使用Java找到四边形内的像素点?
我正在做一些图像处理,我有四边形 4 个点的坐标。 (类似梯形的东西) 如何获取其中所有像素的坐标?顺便说一句,我正在使用 Java。 谢谢!
Im doing some image processing and I have the coordinates of the 4 points of a quadrilateral.
(something like a trapezium)
How can i get the coordinates of all the pixels inside it? I'm using Java by the way.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要扫描线多边形填充。
以下是关于该主题的快速 PDF 讲座:
http://www .cs.binghamton.edu/~reckert/460/lect11_2009-areafill-transformations.pdf
这是一个网页示例,其中包含一些示例 C 代码和基本思想的良好说明:
http://alienryderflex.com/polygon_fill/
这是简短的形式。将四边形线分为左侧和右侧的线。对于每个恒定 Y 坐标行,找出左线的交叉点;找出右线的交点;两个交叉点之间该行上的所有像素都在梯形内部。
从历史上看,这种事情最初(并且可能仍然)是为了在软件中渲染 3D 场景而完成的。我想当时它有一个不同的名字,但我不记得了。然而,您实际上不必绘制像素;只需绘制像素即可。无论您是否绘制像素,该算法都会为您提供像素。
You need scanline polygon filling.
Here's a quick PDF lecture on the subject:
http://www.cs.binghamton.edu/~reckert/460/lect11_2009-areafill-transformations.pdf
Here's a web page example with some sample C code and a good illustration of the basic idea:
http://alienryderflex.com/polygon_fill/
Here's the short form. Divide your quadrilateral lines into those that are on the left, and on the right. For each constant-Y-coordinate row, figure out the crossing point for the left line; figure out the crossing point for the right line; all pixels on that row between the two crossing points are inside of your trapezoid.
Just by way of history, this sort of thing was originally (and probably still is) done for rendering 3d scenes in software. I think it had a different name back then, but I can't remember it. However, you don't actually have to draw the pixels; the algorithm will give you the pixels whether you draw them or not.
http://wiki.processing.org/w/Find_which_side_of_a_line_a_point_is_on 有关于如何找到哪一侧的伪代码一个点所在的线上。
如果您的四边形由 A、B、C、D 点定义 - 检查您的点是否位于 AB、BC、CD 和 DA 的“左侧”应该会给您答案。
编辑:哎呀,我把你的问题理解为寻找一个点,而不是所有点。希望这仍然有帮助。
http://wiki.processing.org/w/Find_which_side_of_a_line_a_point_is_on has pseudocode on how to find which side of a line a point is on.
If your quad is defined by points are A, B, C, D - checking if your point is on the 'left' side of AB, BC, CD and DA should give you the answer.
Edit: Oops, I read your question as finding a point, not all points. Hope this is helpful still.
这是一个碰撞检测问题吗?您想知道给定点是否在形状内部吗?或者你真的想要形状内所有点的坐标吗?
Is this a collision detection question? Do you want to know if a given point is inside a shape? Or do you you really want the co-ordinates of all the points inside your shape?