如何使用Java在四边形内找到像素点? [英] How do i find pixels points inside quadrilateral using 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!
推荐答案
您需要扫描线多边形填充。
You need scanline polygon filling.
这是关于这个主题的快速PDF讲座:
Here's a quick PDF lecture on the subject:
http://www.cs.binghamton.edu/~reckert/460/lect11_2009-areafill-transformations.pdf
这是一个网页示例,其中包含一些示例C代码和基本概念的良好说明:
Here's a web page example with some sample C code and a good illustration of the basic idea:
http://alienryderflex.com/polygon_fill/
这是简短形式。将四边形线划分为左侧和右侧的线。对于每个恒定Y坐标行,找出左边的交叉点;弄清楚右线的交叉点;两个交叉点之间的那一行上的所有像素都在你的梯形内。
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.
仅仅通过历史,这种事情最初(可能仍然是)已完成用于在软件中渲染3D场景。我认为它当时有一个不同的名字,但我不记得了。但是,您实际上不必绘制像素;无论你是否绘制它,算法都会给你像素。
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.
这篇关于如何使用Java在四边形内找到像素点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!