Skip to content

Commit

Permalink
ENH Extend croptobbox for ndim > 2
Browse files Browse the repository at this point in the history
This is trivial with the slice functionality (which didn't exist when
croptobbox was first written).
  • Loading branch information
luispedro committed Jun 26, 2015
1 parent 8212d47 commit a4f479c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -6,6 +6,7 @@ Version 1.3.0+
* Added ``mahotas-features.py`` script
* bbox now allows dimensions greater than 2 (including when using the
``as_slice`` and ``border`` arguments)
* Extended croptobbox for dimensions greater than 2

Version 1.3.0 2014-05-28 by luispedro
* Improve memory handling in freeimage.write_multipage
Expand Down
4 changes: 2 additions & 2 deletions mahotas/bbox.py
Expand Up @@ -66,6 +66,6 @@ def croptobbox(img, border=None):
This ensures that the result is always a sub-image of the input.
"""
min1,max1,min2,max2 = bbox(img, border=border)
return img[min1:max1,min2:max2]
sl = bbox(img, border=border, as_slice=True)
return img[sl]

8 changes: 8 additions & 0 deletions mahotas/tests/test_bbox.py
Expand Up @@ -19,6 +19,14 @@ def test_croptobbox():
assert mahotas.croptobbox(ball.T, border=256).sum() == ball.sum()
assert mahotas.croptobbox(ball.T, border=256).size == ball.size

def test_croptobbox_3d():
YXZ = np.indices((32,32,64), float)
YXZ -= 8
Y,X,Z = YXZ
ball = ((X**2+Y**2+Z**2) < 64).astype(np.uint8)
assert np.sum(ball) == np.sum(mh.croptobbox(ball))


def test_bbox_empty():
assert mahotas.bbox(np.zeros((), np.bool)).shape == (0,)

Expand Down

0 comments on commit a4f479c

Please sign in to comment.