LineFiller icon indicating copy to clipboard operation
LineFiller copied to clipboard

How to make this faster?

Open evancasey opened this issue 5 years ago • 1 comments

Hi hepesu,

Great work on this project, I was amazed at how well your segmentation performs.

Do you have any times on how to get this to run faster? If I pass it an HD image with a lot of segments, it sometimes takes up to 30 seconds on my laptop. It seems like the majority of the time is being spend in the flood_fill_multi and merge_fill functions. Is there anyway these functions can be optimized?

I am also wondering if it would be possible to split up the input images into patches and run segmentation in parallel on each patch. Once each patch is finished you could merge them back together. What do you think of this approach?

evancasey avatar May 28 '19 23:05 evancasey

Hi evancasey,

Sorry for the late answer. The performance was not optimized, because the project is not intended for production usage at the moment. But I have some suggestion to make it faster.

  • Select right parameter for different types of line drawings. The main bottleneck is flood_fill_multi and merge_fill as you said. This is related to the parameter in trapped_ball_fill_multi and the filling sequence. The parameter should depend on the gap size and the image size. A trapped ball fill with large radius may cause a big unfilled area in corner, and this increase the operations in flood_fill_multi and merge_fill. A trapped ball fill with small radius after some trapped ball filling operations may cause lots of fragment too. For batch usage, I suggest that you can use flood_fill_multi for all image first, then pick failure cases by hands or some classifier (cnn or stats of some feature such as area nums, area size), use trapped ball fill on these.

  • Use c++ to improve the performance. The main bottleneck in flood_fill_multi and merge_fill has lots of loops, which is the bottleneck in python.

  • Use a better strategy to merge the fills. My solution is a simple and naive method.

  • "Divide and conquer" is a great strategy to speed up the process. It will work, but you have to do some work to merge fills on the edges. I think the current merge method works on this too.

hepesu avatar Jun 29 '19 00:06 hepesu