Summary: What is the best approach to find the best cropping on image with multiple ROIS?
Details:
- we have image size
- we have known ROI score an position on the image
- we have desired output ratio (portrait/landscape/square)
- positive ROI score should be kept
- negative ROI score should be discard
Should i try all possibilities to find the best one or is there any other way to find best crop (score heatmap, object gravity, statistics...)
Any kind of help is welcome, article, ressource, pseudo code, code
Example of GO code (except implementation of Find method)
package main
import (
"fmt"
"image"
)
type Roi struct {
image.Rectangle
Score float64
}
func main() {
imageBounds := image.Rect(0, 0, 2000, 1000)
rois := []Roi{
{Score: 1, Rectangle: image.Rect(10, 10, 20, 20)},
{Score: -10, Rectangle: image.Rect(400, 400, 600, 600)},
}
cropRatio := float64(100) / float64(1000)
bestCrop := FindBestCrop(imageBounds, cropRatio, rois)
fmt.Printf("Best cropping was %#v", bestCrop)
}
// positive ROI score should be kept
// negative ROI score should be discard
func FindBestCrop(srcBounds image.Rectangle, cropRatio float64, rois []Roi) image.Rectangle {
// Solution 1: Scanning by pixel (vertically or horizontally) and compute visible roi score
// Solution 2: Center crop on roi and compute visible roi score
// other ???
return image.Rectangle{}
}