问题
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