Skip to content

Commit 3d37ebb

Browse files
committed
Moved _scale() out of to_imagemagick() so it can be tested.
1 parent b0a262f commit 3d37ebb

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

halostack/image.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -801,22 +801,6 @@ def to_imagemagick(img, bits=16):
801801

802802
if not isinstance(img, PMImage):
803803

804-
def _scale(img, bits=16):
805-
'''Scale image to cover the whole bit-range.
806-
'''
807-
808-
LOGGER.debug("Scaling image to %d bits.", bits)
809-
810-
img -= img.min()
811-
img_max = np.max(img)
812-
if img_max != 0:
813-
img = (2**bits - 1) * img / img_max
814-
815-
if bits <= 8:
816-
return img.astype('uint8')
817-
else:
818-
return img.astype('uint16')
819-
820804
img = _scale(img, bits=bits)
821805

822806
LOGGER.debug("Converting from Numpy to ImageMagick.")
@@ -845,6 +829,24 @@ def _scale(img, bits=16):
845829
return out_img
846830
return img
847831

832+
833+
def _scale(img, bits=16):
834+
'''Scale image to cover the whole bit-range.
835+
'''
836+
837+
LOGGER.debug("Scaling image to %d bits.", bits)
838+
839+
img -= img.min()
840+
img_max = np.max(img)
841+
if img_max != 0:
842+
img = (2**bits - 1) * img / img_max
843+
844+
if bits <= 8:
845+
return img.astype('uint8')
846+
else:
847+
return img.astype('uint16')
848+
849+
848850
def polyfit2d(x_loc, y_loc, z_val, order=2):
849851
'''Fit a 2-D polynomial to the given data.
850852

0 commit comments

Comments
 (0)