|
@@ -15,7 +15,7 @@ from skimage import img_as_ubyte, img_as_int
|
|
|
import numpy as np
|
|
|
|
|
|
from imageprocessing import tiffPreparer, sliceMapCreator, binaryPreparer
|
|
|
-from . import MultiProcessUByte
|
|
|
+from . import MultiProcessUByte, Normalizer
|
|
|
|
|
|
import logging
|
|
|
|
|
@@ -111,6 +111,16 @@ def sliceGeneratorPlain(data, volumeId):
|
|
|
if len(frames.shape) is not 4:
|
|
|
raise ValueError('read input file shall have dim of 4, please check the used fileparser')
|
|
|
|
|
|
+ if frames.dtype == np.float32 or frames.dtype == np.float16:
|
|
|
+ try:
|
|
|
+ Normalizer.normalize_image(frames, volumeId)
|
|
|
+ except Exception as e:
|
|
|
+ logger.error('volId: %s, error while normalization: ' % (str(e)))
|
|
|
+ Volume.objects(id=volume.id).update_one(set__generateSlicesStatus = 'generation failed, please read the logs')
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ logger.debug('volId: %s, frames do NOT have to be normalized, dtype is %s' % (volumeId, str(frames.dtype)))
|
|
|
+
|
|
|
logger.debug('volId: %s, cropping images to be square' % volumeId)
|
|
|
oldshape = frames.shape
|
|
|
pixelOffset, newSize = sliceMapCreator.calculateXYDimensions(frames[0])
|
|
@@ -121,17 +131,6 @@ def sliceGeneratorPlain(data, volumeId):
|
|
|
del frames
|
|
|
logger.debug('volId: %s, memory freed, frames deleted, keeping squared croppedFrames' % volumeId)
|
|
|
|
|
|
- if croppedFrames.dtype == np.float32 or croppedFrames.dtype == np.float16:
|
|
|
- logger.debug('volId: %s, float frames detected, normalize them' % volumeId)
|
|
|
- collectionMin = croppedFrames.min()
|
|
|
- collectionMax = croppedFrames.max()
|
|
|
- logger.debug('volId: %s, imagesmin: %d, imagesmax: %d' %(volumeId, collectionMin, collectionMax))
|
|
|
- croppedFrames = (croppedFrames - collectionMin) / (collectionMax - collectionMin)
|
|
|
-
|
|
|
- logger.debug('volId: %s, after normalization imagesmin: %d, imagesmax: %d' %(volumeId, croppedFrames.min(), croppedFrames.max()))
|
|
|
- else:
|
|
|
- logger.debug('volId: %s, frames do NOT have to be normalized, dtype is %s' % (volumeId, str(croppedFrames.dtype)))
|
|
|
-
|
|
|
if croppedFrames.dtype != np.int16 and croppedFrames.dtype != np.uint8:
|
|
|
logger.debug('volId: %s, frames are not int16 and not uint8, convert them to int' % volumeId)
|
|
|
croppedFrames = img_as_int(croppedFrames)
|
|
@@ -149,9 +148,14 @@ def sliceGeneratorPlain(data, volumeId):
|
|
|
|
|
|
logger.debug('volId: %s, setting rawframes' % volumeId)
|
|
|
|
|
|
- for frameNumber in range(0, len(croppedFrames)):
|
|
|
- logger.debug('volId: %s, rawFrame: %d, sizeInMemory: %d' % (volumeId, frameNumber, sys.getsizeof(croppedFrames[frameNumber])))
|
|
|
- rawFrame = volume.add_frame(croppedFrames[frameNumber], frameNumber)
|
|
|
+ try:
|
|
|
+ for frameNumber in range(0, len(croppedFrames)):
|
|
|
+ logger.debug('volId: %s, rawFrame: %d, sizeInMemory: %d' % (volumeId, frameNumber, sys.getsizeof(croppedFrames[frameNumber])))
|
|
|
+ rawFrame = volume.add_frame(croppedFrames[frameNumber], frameNumber)
|
|
|
+ except Exception:
|
|
|
+ logger.error('volId: %s, please provide integers or "" for "sliceFrom" and "sliceTo"' % (volumeId))
|
|
|
+ Volume.objects(id=volume.id).update_one(set__generateSlicesStatus = 'generation failed, please read the logs')
|
|
|
+ return
|
|
|
else:
|
|
|
rawFrame = volume.rawFrames[0]
|
|
|
|