MoritzWillig / pysnic

Python implementation of the SNIC superpixels algorithm
MIT License
54 stars 5 forks source link

Index Error #8

Closed rahulmoorthy19 closed 3 years ago

rahulmoorthy19 commented 3 years ago

Hello Moritz,

Thanks for such a great implementation of Polygon based on SNIC...i am facing one small issue...so In some cases..I am observing that the polygonize code is giving index error with queue[-1]...I was hoping you could help out in finding a way to solve it.

Preview of the Error is below-

Traceback (most recent call last): File "trial.py", line 33, in graphs = polygonize(segmentation, seeds, rdp) File "/home/sirzech/anaconda3/lib/python3.8/site-packages/pysnic/algorithms/polygonize.py", line 522, in polygonize graphs = trace_isles(vertices, seeds, segmentation) File "/home/sirzech/anaconda3/lib/python3.8/site-packages/pysnic/algorithms/polygonize.py", line 304, in trace_isles vertices, edges = trace_edges_unsafe(px, py, direction, segmentation) File "/home/sirzech/anaconda3/lib/python3.8/site-packages/pysnic/algorithms/polygonize.py", line 348, in trace_edges_unsafe idx = queue[-1] IndexError: list index out of range

Thanks, Rahul Moorthy

MoritzWillig commented 3 years ago

Hi Rahul, thanks for your feedback! I just had a look at the code and checked in a new commit, that hopefully resolves your error. If the change fixes your problem I will release a new version on pip later today.

Best, Moritz

rahulmoorthy19 commented 3 years ago

Yes, I tried it out now, it seems to be working...Thanks a lot...

rahulmoorthy19 commented 3 years ago

I also wanted to know one more thing, instead of the vertices and edges...can the algo directly give the polygon? or do we need to write custom logic for that?

MoritzWillig commented 3 years ago

I currently have no plans for adding such functionality to the code, as there already exist more advanced libraries to handle polygons and/or meshes (e.g. OpenMesh). The extracted data structure is also likely to depend on the specific use case (- point list, half-edge structure, ...).

Just a remark about extracting polygons: Depending on the parameters, the SNIC algorithm can produce superpixels that are fully enclosed into others. Simply converting to polygons by tracing the edges may violate this topology, as the enclosing super-pixels may also cover the area of the enclosed ones. This may be problematic if you plan to do some calculations/statistics on them. If you simply want to visualize the superpixels, make sure to draw the graphs in the provided order. Graphs containing the enclosed superpixels are provided last in the returned graph list.

If you got some suggestions for adding such functionality in a proper way, I can try to free some time and add it to the repo.

rahulmoorthy19 commented 3 years ago

I just want to visualize...and send the polygon coordinates...will keep in mind the point which you mentioned..will implement and let you know if at all a way exists which will be useful for the community

MoritzWillig commented 3 years ago

Just in case you are again encountering index out of bound errors in the polygonization method - I just revised the code to cover some more edge cases. (Fixed the same error in another sub-method and prevented some edges from being mistakenly discarded).

rahulmoorthy19 commented 3 years ago

Thanks a lot Moritz....just wanted to know...whether you have updated the same in the pip version of pysnic

MoritzWillig commented 3 years ago

Just updated the pip package. :+1: