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 4ffdd099 authored by Olga Stamati's avatar Olga Stamati
Browse files

helper function of padding inside label

parent f37f2a99
Pipeline #49788 passed with stages
in 12 minutes and 24 seconds
......@@ -498,7 +498,6 @@ def slicePadded(im, startStop, createMask = False):
return imSliced
# private functions
#def _mask2D(im, erosion=False, structure=None, ):
#"""
......
......@@ -411,7 +411,7 @@ def _checkSlice(topOfSlice, botOfSlice, topLimit, botLimit):
return returnSliceLimited, returnSliceOffset
def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, margin=None, extractCube=False, extractCubeSize=None, maskOtherLabels=True, labelDilate=0, labelDilateMaskOtherLabels=False):
def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, margin=0, extractCube=False, extractCubeSize=None, maskOtherLabels=True, labelDilate=0, labelDilateMaskOtherLabels=False):
"""
Helper function to extract labels from a labelled image/volume.
A dictionary is returned with the a subvolume around the particle.
......@@ -543,8 +543,8 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
offset = int(extractCubeSize)
# if a margin is set, add it to offset
if margin is not None:
offset += margin
#if margin is not None:
offset += margin
offset = int(offset)
......@@ -558,32 +558,32 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
int(comRound[1] + offset + 1),
int(comRound[2] + offset + 1)])
sliceLimited, sliceOffset = _checkSlice(topOfSlice, botOfSlice, [0, 0, 0], numpy.array(labelledVolume.shape))
#sliceLimited, sliceOffset = _checkSlice(topOfSlice, botOfSlice, [0, 0, 0], numpy.array(labelledVolume.shape))
output['sliceCube'] = sliceLimited
labSubVol = spam.helpers.slicePadded(labelledVolume, [topOfSlice[0], botOfSlice[0], topOfSlice[1], botOfSlice[1], topOfSlice[2], botOfSlice[2]])
#output['sliceCube'] = sliceLimited
output['sliceCube'] = (slice(topOfSlice[0], botOfSlice[0]), slice(topOfSlice[1], botOfSlice[1]), slice(topOfSlice[2], botOfSlice[2]))
output['centreOfMassREL'] = com - [sliceLimited[0].start - sliceOffset[0].start,
sliceLimited[1].start - sliceOffset[1].start,
sliceLimited[2].start - sliceOffset[2].start]
labSubVol[sliceOffset] = labelledVolume[sliceLimited].copy()
output['centreOfMassREL'] = com - topOfSlice
# We have a bounding box, let's extract it.
else:
if margin is None:
margin = 0
topOfSlice = numpy.array([int(bbo[0] - margin),
int(bbo[2] - margin),
int(bbo[4] - margin)])
botOfSlice = numpy.array([int(bbo[1] + margin + 1),
int(bbo[3] + margin + 1),
int(bbo[5] + margin + 1)])
sliceLimited = (slice(max(int(bbo[0] - margin), 0), min(int(bbo[1] + 1 + margin), labelledVolume.shape[0])),
slice(max(int(bbo[2] - margin), 0), min(int(bbo[3] + 1 + margin), labelledVolume.shape[1])),
slice(max(int(bbo[4] - margin), 0), min(int(bbo[5] + 1 + margin), labelledVolume.shape[2])))
#sliceLimited = (slice(max(int(bbo[0] - margin), 0), min(int(bbo[1] + 1 + margin), labelledVolume.shape[0])),
#slice(max(int(bbo[2] - margin), 0), min(int(bbo[3] + 1 + margin), labelledVolume.shape[1])),
#slice(max(int(bbo[4] - margin), 0), min(int(bbo[5] + 1 + margin), labelledVolume.shape[2])))
output['slice'] = sliceLimited
labSubVol = spam.helpers.slicePadded(labelledVolume, [topOfSlice[0], botOfSlice[0], topOfSlice[1], botOfSlice[1], topOfSlice[2], botOfSlice[2]])
output['centreOfMassREL'] = com - [sliceLimited[0].start,
sliceLimited[1].start,
sliceLimited[2].start]
output['slice'] = (slice(topOfSlice[0], botOfSlice[0]), slice(topOfSlice[1], botOfSlice[1]), slice(topOfSlice[2], botOfSlice[2]))
labSubVol = labelledVolume[sliceLimited].copy()
output['centreOfMassREL'] = com - topOfSlice
# Get mask for this label
maskLab = labSubVol == label
......
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