Skip to content

Instantly share code, notes, and snippets.

@MarcoForte
Created August 20, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoForte/1ec3595204caee7a91ab5b9d32454539 to your computer and use it in GitHub Desktop.
Save MarcoForte/1ec3595204caee7a91ab5b9d32454539 to your computer and use it in GitHub Desktop.
Overlay zoomed in crop on image. Used for creating images in FBA Matting paper.
def add_zoom_crop(img, crop_xs, crop_ys, r, inset_coord):
x1,x2 = crop_xs
y1,y2 = crop_ys
img = (img*255).astype(np.uint8)
inset_coord_end = ( int(inset_coord[0]+(x2-x1)*r), int(inset_coord[1] +(y2-y1)*r))
patch = img[y1:y2,x1:x2]
patch_bigger = cv2.resize(patch, ( int(patch.shape[1]*r), int(patch.shape[0]*r)))
img[inset_coord[1]:inset_coord[1]+patch_bigger.shape[0], inset_coord[0]:inset_coord[0]+patch_bigger.shape[1]] = np.atleast_3d(patch_bigger)
color = (0, 255, 255)
thickness = 10
if(img.shape[2]==1):
img = np.concatenate((img, img, img),2)
img = cv2.rectangle(img, inset_coord, inset_coord_end, color, thickness)/255.0
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment