mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-15 12:54:54 +08:00
Do not try and save signed integer output, improved signed checks for tif.
This commit is contained in:
@@ -119,8 +119,13 @@ def ubyte_check(plugin, fmt='png'):
|
|||||||
testing.assert_allclose(r3, img)
|
testing.assert_allclose(r3, img)
|
||||||
|
|
||||||
img4 = img_as_int(img)
|
img4 = img_as_int(img)
|
||||||
r4 = roundtrip(img4, plugin, fmt)
|
if fmt.lower() in (('tif', 'tiff')):
|
||||||
testing.assert_allclose(r4, img)
|
img4 -= 100
|
||||||
|
r4 = roundtrip(img4, plugin, fmt)
|
||||||
|
testing.assert_allclose(r4, img4)
|
||||||
|
else:
|
||||||
|
r4 = roundtrip(img4, plugin, fmt)
|
||||||
|
testing.assert_allclose(r4, img_as_ubyte(img4))
|
||||||
|
|
||||||
img5 = img_as_uint(img)
|
img5 = img_as_uint(img)
|
||||||
r5 = roundtrip(img5, plugin, fmt)
|
r5 = roundtrip(img5, plugin, fmt)
|
||||||
@@ -150,8 +155,13 @@ def full_range_check(plugin, fmt='png'):
|
|||||||
testing.assert_allclose(r3, img_as_uint(img))
|
testing.assert_allclose(r3, img_as_uint(img))
|
||||||
|
|
||||||
img4 = img_as_int(img)
|
img4 = img_as_int(img)
|
||||||
r4 = roundtrip(img4, plugin, fmt)
|
if fmt.lower() in (('tif', 'tiff')):
|
||||||
testing.assert_allclose(r4, img4)
|
img4 -= 100
|
||||||
|
r4 = roundtrip(img4, plugin, fmt)
|
||||||
|
testing.assert_allclose(r4, img4)
|
||||||
|
else:
|
||||||
|
r4 = roundtrip(img4, plugin, fmt)
|
||||||
|
testing.assert_allclose(r4, img_as_uint(img4))
|
||||||
|
|
||||||
img5 = img_as_uint(img)
|
img5 = img_as_uint(img)
|
||||||
r5 = roundtrip(img5, plugin, fmt)
|
r5 = roundtrip(img5, plugin, fmt)
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ def pil_to_ndarray(im, dtype=None):
|
|||||||
elif im.mode.startswith('I;16'):
|
elif im.mode.startswith('I;16'):
|
||||||
shape = im.size
|
shape = im.size
|
||||||
dtype = '>u2' if im.mode.endswith('B') else '<u2'
|
dtype = '>u2' if im.mode.endswith('B') else '<u2'
|
||||||
|
if 'S' in im.mode:
|
||||||
|
dtype = dtype.replace('u', 'i')
|
||||||
im = np.fromstring(im.tostring(), dtype)
|
im = np.fromstring(im.tostring(), dtype)
|
||||||
im.shape = shape[::-1]
|
im.shape = shape[::-1]
|
||||||
elif 'A' in im.mode:
|
elif 'A' in im.mode:
|
||||||
@@ -133,10 +135,7 @@ def ndarray_to_pil(arr, format_str=None):
|
|||||||
mode = mode_base = 'L'
|
mode = mode_base = 'L'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if arr.dtype.kind == 'u':
|
arr = img_as_uint(arr)
|
||||||
arr = img_as_uint(arr)
|
|
||||||
else:
|
|
||||||
arr = img_as_int(arr)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
arr = img_as_ubyte(arr)
|
arr = img_as_ubyte(arr)
|
||||||
@@ -183,8 +182,7 @@ def imsave(fname, arr, format_str=None):
|
|||||||
All images besides single channel PNGs are converted using `img_as_uint8`.
|
All images besides single channel PNGs are converted using `img_as_uint8`.
|
||||||
Single Channel PNGS have the following behavior:
|
Single Channel PNGS have the following behavior:
|
||||||
- Integer values in [0, 255] and Boolean types -> img_as_uint8
|
- Integer values in [0, 255] and Boolean types -> img_as_uint8
|
||||||
- Other unsigned integers and floating point -> img_as_uint16
|
- Floating point and other integers -> img_as_uint16
|
||||||
- Other signed integers -> img_as_int16
|
|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
|
|||||||
Reference in New Issue
Block a user