Commit 5128c4dd authored by Gustavo Pinzon's avatar Gustavo Pinzon
Browse files

Progressbar for Split-Rebuild image functions

parent 463815a9
Pipeline #66807 passed with stages
in 27 minutes and 18 seconds
......@@ -19,6 +19,7 @@ this program. If not, see <http://www.gnu.org/licenses/>.
import numpy
import tifffile
import spam.label
import progressbar
def stackToArray(prefix, sufix='.tif', stack=range(10), digits='05d', erosion=False, verbose=False):
"""
......@@ -520,7 +521,7 @@ def slicePadded(im, startStop, createMask=False, padValue=0, verbose=False):
return imSliced
def splitImage(im, divisions, margin, verbose=False):
def splitImage(im, divisions, margin, verbose=True):
"""
Divides the image in zDiv x yDiv x xDiv blocks, each block is padded
with a margin.
......@@ -540,6 +541,7 @@ def splitImage(im, divisions, margin, verbose=False):
verbose : bool
Print the parameters of the operations (number of blocks and margin)
Default = True
Returns
-------
......@@ -583,8 +585,7 @@ def splitImage(im, divisions, margin, verbose=False):
return -1
# Print parameters if needed
if verbose==True:
print('spam.helpers.imageManipulation.splitImage: Working with margin of ', margin)
print('spam.helpers.imageManipulation.splitImage: The total number of blocks is ', zDiv*yDiv*xDiv)
print('spam.helpers.imageManipulation.splitImage: Working with margin of ', margin, '. The total number of blocks is ', zDiv*yDiv*xDiv)
# Pad initial image with zeros on the edge
imPad = numpy.pad(im, margin, mode='edge')
......@@ -627,7 +628,7 @@ def splitImage(im, divisions, margin, verbose=False):
return output
def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False):
def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False, verbose=True):
"""
Rebuilds splitted image from `spam.helpers.imageManipulation.splitImage()`.
......@@ -651,6 +652,10 @@ def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False):
keepLabels : bool
Do we need to want to keep the current labels from the blocks, or create a new one?
Default = False
verbose : bool
Print the evolution of the operation
Default = True
Returns
-------
......@@ -677,6 +682,13 @@ def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False):
print('spam.helpers.imageManipulation.splitImage: coordinates in listCoordinates must be all different')
return -1
if verbose:
# Create progressbar
widgets = [progressbar.FormatLabel(''), ' ', progressbar.Bar(), ' ', progressbar.AdaptiveETA()]
pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(listCoordinates))
pbar.start()
finishedBlocks = 0
if mode == 'grey':
# Shape of the block opposite to the origine
......@@ -703,7 +715,12 @@ def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False):
imBuild[origin[0]:origin[0]+blockPad.shape[0] - 2*margin,
origin[1]:origin[1]+blockPad.shape[1] - 2*margin,
origin[2]:origin[2]+blockPad.shape[2] - 2*margin] = blockPad[margin:-margin, margin:-margin, margin:-margin]
if verbose:
# Update the progressbar
finishedBlocks += 1
widgets[0] = progressbar.FormatLabel("{}/{} ".format(finishedBlocks, len(listCoordinates)))
pbar.update(finishedBlocks)
print('\n\t')
return imBuild
if mode == 'label':
......@@ -799,10 +816,18 @@ def rebuildImage(listBlocks, listCoordinates, margin, mode, keepLabels=False):
origin[2]+box[4]-margin:origin[2]+box[5]+1-margin] = imBuildSubset
#Update label counter
labCounter += 1
if verbose:
# Update the progressbar
finishedBlocks += 1
widgets[0] = progressbar.FormatLabel("{}/{} ".format(finishedBlocks, len(listCoordinates)))
pbar.update(finishedBlocks)
if not keepLabels:
imBuild = spam.label.makeLabelsSequential(imBuild)
print('\n\t')
return imBuild
else:
......
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