test_regression.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import division, print_function, absolute_import
  2. import numpy as np
  3. from numpy.testing import assert_array_almost_equal
  4. import scipy.ndimage as ndimage
  5. def test_byte_order_median():
  6. """Regression test for #413: median_filter does not handle bytes orders."""
  7. a = np.arange(9, dtype='<f4').reshape(3, 3)
  8. ref = ndimage.filters.median_filter(a,(3, 3))
  9. b = np.arange(9, dtype='>f4').reshape(3, 3)
  10. t = ndimage.filters.median_filter(b, (3, 3))
  11. assert_array_almost_equal(ref, t)
  12. def test_zoom_output_shape():
  13. """Ticket #643"""
  14. x = np.arange(12).reshape((3,4))
  15. ndimage.zoom(x, 2, output=np.zeros((6,8)))
  16. def test_ticket_742():
  17. def SE(img, thresh=.7, size=4):
  18. mask = img > thresh
  19. rank = len(mask.shape)
  20. la, co = ndimage.label(mask,
  21. ndimage.generate_binary_structure(rank, rank))
  22. slices = ndimage.find_objects(la)
  23. if np.dtype(np.intp) != np.dtype('i'):
  24. shape = (3,1240,1240)
  25. a = np.random.rand(np.product(shape)).reshape(shape)
  26. # shouldn't crash
  27. SE(a)
  28. def test_gh_issue_3025():
  29. """Github issue #3025 - improper merging of labels"""
  30. d = np.zeros((60,320))
  31. d[:,:257] = 1
  32. d[:,260:] = 1
  33. d[36,257] = 1
  34. d[35,258] = 1
  35. d[35,259] = 1
  36. assert ndimage.label(d, np.ones((3,3)))[1] == 1