Commit 18a09c7e authored by dan's avatar dan

Simplification and bugfix

parent 4688bfff
...@@ -124,13 +124,11 @@ def center_crop(image: Image, w: int, h: int): ...@@ -124,13 +124,11 @@ def center_crop(image: Image, w: int, h: int):
def multicrop_pic(image: Image, mindim, maxdim, minarea, maxarea, objective, threshold): def multicrop_pic(image: Image, mindim, maxdim, minarea, maxarea, objective, threshold):
iw, ih = image.size iw, ih = image.size
err = lambda w, h: 1-(lambda x: x if x < 1 else 1/x)(iw/ih/(w/h)) err = lambda w, h: 1-(lambda x: x if x < 1 else 1/x)(iw/ih/(w/h))
try:
w, h = max(((w, h) for w in range(mindim, maxdim+1, 64) for h in range(mindim, maxdim+1, 64) w, h = max(((w, h) for w in range(mindim, maxdim+1, 64) for h in range(mindim, maxdim+1, 64)
if minarea <= w * h <= maxarea and err(w, h) <= threshold), if minarea <= w * h <= maxarea and err(w, h) <= threshold),
key= lambda wh: ((objective=='Maximize area')*wh[0]*wh[1], -err(*wh)) key= lambda wh: (wh[0]*wh[1], -err(*wh))[::1 if objective=='Maximize area' else -1],
default=None
) )
except ValueError:
return
return center_crop(image, w, h) return center_crop(image, w, h)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment