inpolygon

13 ビュー (過去 30 日間)
AP
AP 2011 年 6 月 4 日
編集済み: Walter Roberson 2018 年 7 月 3 日
Is there a faster function than inpolygon? It takes forever when I want to check 1280x1024 pixels of an image whether they are inside or outside of a closed polygon.
Thank you very much for your quick reply.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 4 日
So your polygon is closed. Aren't they all?
Is your polygon convex? Does it have holes? Is it self-intersecting? Is it complicated or relatively simple?

サインインしてコメントする。

回答 (4 件)

Image Analyst
Image Analyst 2011 年 6 月 4 日
編集済み: Walter Roberson 2018 年 7 月 3 日
What are you really wanting to do? Because there's a chance you can do it without using inpolygon. For example
[rows columns, numberOfColorChannels] = size(originalImage);
pixelsInPolygon = poly2mask(polygonXCoordinates, polygonYCoordinates, rows, columns)
should do what you asked. It will produce a map of which pixels "are" or "are not" inside your polygon. But I have a feeling that this is just one intermediate step in what you really want to do.

John D'Errico
John D'Errico 2011 年 6 月 4 日
No. In fact, inpolygon is already blazingly fast. But no matter how fast you make something, someone will throw a million plus points at it, or a billion points, or a trillion points, and then decide it is too slow for their purposes.
Computers are not infinitely large or infinitely fast. The creative (or the ignorant or the foolish or the lazy) can always find a way to exceed the capabilities of any algorithm on any machine. In fact, problems quickly tend to grow in size to always just exceed those capabilities.
In any problem, there may be tricks one can use to reduce the work. For example, if you feel it is too slow to throw 1.2 million pixels at the tool, perhaps you can decide that entire simple regions are inside the polygon, therefore nothing inside that sub-domain need be tested?

Jan
Jan 2011 年 6 月 4 日
There is a faster function than INPOLYGON. If it is not written yet, it is possible to do, e.g. as C-Mex or in assembler and achieve an acceleration of 10% or 500%. But your problem "takes forever". A factor 5 will not help to reduce this remarkably.
Most likely it will be more helpful to exploit the geometry of the polygon: Exclude all points outside enclosing rectangle (very cheap), exclude all points outside the convex hull (semi cheap), etc.

carl howell
carl howell 2011 年 10 月 28 日
Are there nan's at the end of your polygons? If you've read in a shapefile, than likely so... If so, try removing them (nan's) before you call inpolygon...
  2 件のコメント
carl howell
carl howell 2011 年 10 月 28 日
Never mind, looks like I had a bug in my code making it seem like it was faster with nan's removed... Still working on similar problem...
Reema Alhassan
Reema Alhassan 2018 年 7 月 3 日
hello Carl, did you solve your problem? because I'm facing the same issue now and I couldn't find another way to do it ..

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by