ENH: Use dtype scaling routines in qt and pil plugins.

This commit is contained in:
Stefan van der Walt
2011-12-05 16:43:24 -08:00
parent 0b962c41c9
commit f6458f18ef
2 changed files with 9 additions and 16 deletions
+3 -4
View File
@@ -9,6 +9,8 @@ except ImportError:
"Please refer to http://pypi.python.org/pypi/PIL/ "
"for further instructions.")
from skimage.util import img_as_ubyte
def imread(fname, dtype=None):
"""Load an image from file.
@@ -106,7 +108,4 @@ def imshow(arr):
[0, 1]. Images of dtype uint8 are in [0, 255].
"""
if np.issubdtype(arr.dtype, float):
arr = (arr * 255).astype(np.uint8)
Image.fromarray(arr).show()
Image.fromarray(img_as_ubyte(arr)).show()
+6 -12
View File
@@ -2,6 +2,7 @@ import numpy as np
from . import _colormixer
from . import _histograms
import threading
from skimage.util import img_as_ubyte
# utilities to make life easier for plugin writers.
@@ -132,25 +133,18 @@ def prepare_for_display(npy_img):
width = npy_img.shape[1]
out = np.empty((height, width, 3), dtype=np.uint8)
npy_img = img_as_ubyte(npy_img)
if npy_img.ndim == 2 or \
(npy_img.ndim == 3 and npy_img.shape[2] == 1):
npy_plane = npy_img.reshape((height, width))
if np.issubdtype(npy_img.dtype, float):
out[:,:,0] = npy_plane*255
out[:,:,1] = out[:,:,0]
out[:,:,2] = out[:,:,0]
else:
out[:,:,0] = npy_plane
out[:,:,1] = npy_plane
out[:,:,2] = npy_plane
out[:,:,0] = npy_plane
out[:,:,1] = npy_plane
out[:,:,2] = npy_plane
elif npy_img.ndim == 3:
if npy_img.shape[2] == 3 or npy_img.shape[2] == 4:
if np.issubdtype(npy_img.dtype, float):
out[:,:,:3] = (npy_img[:,:,:3])*255
else:
out[:,:,:3] = npy_img[:,:,:3]
out[:,:,:3] = npy_img[:,:,:3]
else:
raise ValueError('Image must have 1, 3, or 4 channels')