Skip to content

Commit

Permalink
add example to get_overlapping_region docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Oct 22, 2015
1 parent 37195a0 commit a68b871
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions util/miscutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ def get_overlapping_region(xlo, xhi, xmin, xmax):
of an image, [xlo, xhi], and bounds for the image [xmin, xmax],
returns the range of coordinates that are in-bounds, and the
corresponding region within the desired cutout.
For example, say you have an image of shape H,W and you want to
cut out a region of halfsize "hs" around pixel coordinate x,y, but
so that coordinate x,y is centered in the cutout even if x,y is
close to the edge. You can do:
cutout = np.zeros((hs*2+1, hs*2+1), img.dtype)
iny,outy = get_overlapping_region(y-hs, y+hs, 0, H-1)
inx,outx = get_overlapping_region(x-hs, x+hs, 0, W-1)
cutout[outy,outx] = img[iny,inx]
'''
if xlo > xmax or xhi < xmin or xlo > xhi or xmin > xmax:
return ([], [])
Expand Down

0 comments on commit a68b871

Please sign in to comment.