How to find custom shape speicific area?

*爱你&永不变心* 提交于 2019-12-11 19:45:18

问题


please , see following image, here you can see blue rectangle is custom shape bounds and custom shape is shoe , i want to find area of a portion written in image and i want that area in form of rectangle

do is there any path iterator concept ?

Note

custom shape i derived from image of the same size.


回答1:


I would do it like this:

1.create table for all bounding box-rect perimeter lines

  • each value in it will represent the empty space length form border line to shape
  • something like this:

  • the values are found by simple image scanning until first non space color found

2.now bruteforce find the biggest rectangle area

x,y = top left corner
 for  xs = 1 to bounding box width
  now scan the max valid height of rectangle from x to x + xs (x grows to the right)
  // it should be the min y0[x..x+xs]
   remember the biggest valid area/size combination
  • do this for all 4 combinations (star from the other corners)

I now Brute-force is slow but

  • you can divide perimeter lines not by pixels but with some step instead
  • also I am sure this can be optimized somehow
  • for example by derivation of perimeter find the extremes and check from them backwards
  • when the size will start shrinking then stop ...
  • of course take in mind that on complicated shapes this optimization will not work ...


来源:https://stackoverflow.com/questions/15276192/how-to-find-custom-shape-speicific-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!