'Most 'fitting' placement of shape in silhouette
I apologize in advance for the lack of code, but I have been looking at this problem for some days now and couldn't proceed much. I am trying to find a method that, given a template shape and a figure, finds the most fitting (edges-wise) placement of such shape in the (binarized) figure.
For example, in the picture above, I've highlighted 2 placement for the triangle on the right (I show 2, but there are probably 5). The blue one covers more "perimeter" and thus should be preferred.
The rotations are limited to steps of 45 degrees and no scaling is involved, so I don't think I need some particularly rotation/size invariant methods. For now, I have obtained some results using opencv template matching, by first extracting the edges with canny and matching the resulting contour, but it is far from precise and I am afraid this would not work for more complex figures. Also by using canny I lose information about the binarized foreground and background, while the placement must be only inside the figure.
Any idea would be appreciated because I really could not find much in the literature (also I am quite inexpert in the field and probably lacking the proper terminology for effective searches), thank you in advance
Solution 1:[1]
Maybe you could use my github as a reference. I implemented a super fast image template matching algorithm and a friendly user interface for you to load source /Dst image, and show results on a dialog which you can zoom in/out image by mouse wheel.
Usage of this project:
- build the code with C++/MFC in Visual Studio (details are in readme.md)
- run it
- Select the Language you want
- Drag Source Image to the Left Area
- Drag Destination Image to the Right Top Area
- Push "Execute Button"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

