Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 2d18e183 authored by Olga Stamati's avatar Olga Stamati
Browse files

return nan when the padded slice doesn't touch the image

parent f37f2a99
Pipeline #49792 passed with stages
in 23 minutes and 20 seconds
......@@ -105,8 +105,8 @@ class testAll(unittest.TestCase):
#spam.helpers.binarisation(im, threshold=0.5, mask=im > 0.2)
def test_slicePadded(self):
# case 1: inside
im = numpy.random.rand(100, 100, 100)
# case 1: inside
startStop = numpy.array([70, 90, 70, 90, 70, 90])
imSliced = spam.helpers.slicePadded(im, startStop)
self.assertEqual(numpy.subtract(im[startStop[0]:startStop[1], startStop[2]:startStop[3], startStop[4]:startStop[5]], imSliced).sum(), 0)
......@@ -143,6 +143,13 @@ class testAll(unittest.TestCase):
self.assertEqual(imSliced[110:, 110:, 110:].sum(), 0)
self.assertEqual(numpy.subtract(im, imSliced[10:110, 10:110, 10:110]).sum(), 0)
self.assertEqual(mask[10:110, 10:110, 10:110].sum(), 100**3)
## case 6: not touching im
startStop = numpy.array([100, 120, 100, 120, 100, 120])
imSliced, mask = spam.helpers.slicePadded(im, startStop, createMask = True)
self.assertEqual(list(imSliced.shape), [20, 20, 20])
self.assertEqual(numpy.isfinite(imSliced).sum(), 0)
self.assertEqual(mask.sum(), 0)
if __name__ == '__main__':
unittest.main()
......@@ -470,7 +470,7 @@ def slicePadded(im, startStop, createMask = False):
[Zmin, Zmax, Ymin, Ymax, Xmin, Xmax]
createMask : bool, optional
If True, return a of the padded slice, which is False when the slice falls outside im
If True, return a padded slice, which is False when the slice falls outside im
Default = False
Returns
......@@ -491,6 +491,10 @@ def slicePadded(im, startStop, createMask = False):
stopLocal = startLocal + stopOffset - startOffset
imSliced[startLocal[0]:stopLocal[0], startLocal[1]:stopLocal[1], startLocal[2]:stopLocal[2]] = im[startOffset[0]:stopOffset[0], startOffset[1]:stopOffset[1], startOffset[2]:stopOffset[2]]
if imSliced.sum() == 0:
print("spam.helpers.slicePadded(): The extracted padded slice doesn't not touch the image!")
imSliced *= numpy.nan
if createMask:
mask = numpy.zeros_like(imSliced, dtype=bool)
mask[startLocal[0]:stopLocal[0], startLocal[1]:stopLocal[1], startLocal[2]:stopLocal[2]] = 1
......
  • What if the image contains NaNs? Perhaps we should check top/bottom requested slice before starting, what do you think?

  • Yes, right, the check top/bottom can be done before starting.

    As it is written now, the padded slice would return these NaNs, if the startStop hits the image on these positions. Don't we want something like this?

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