Commit 4bd86971 authored by David E. DeMarle's avatar David E. DeMarle

make show raster better

With NaN's for background and values no longer bound to 0..255
(i.e. We can rely on floating point textures from OpenGL now),
let's automatically scale and bias to get something visual.
parent f2454630
...@@ -3,6 +3,7 @@ import PIL.Image ...@@ -3,6 +3,7 @@ import PIL.Image
import PIL.ImImagePlugin import PIL.ImImagePlugin
import numpy as np import numpy as np
import zlib import zlib
import numpy.ma as ma
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "supply filename of a raster file" print "supply filename of a raster file"
...@@ -47,11 +48,16 @@ if ext == ".npz": ...@@ -47,11 +48,16 @@ if ext == ".npz":
imageslice = np.multiply(np.subtract(imageslice, mm[0]), 255) imageslice = np.multiply(np.subtract(imageslice, mm[0]), 255)
im = PIL.Image.fromarray(imageslice) im = PIL.Image.fromarray(imageslice)
elif ext == ".Z": elif ext == ".Z":
with open(fname, mode='r') as file: with open(fname, mode='rb') as file:
compresseddata = file.read() compresseddata = file.read()
flatarr = np.fromstring(zlib.decompress(compresseddata), flatarr = np.fromstring(zlib.decompress(compresseddata),
np.float32) np.float32)
im = PIL.Image.fromarray(flatarr.reshape((zlib_width, zlib_height))) flatarr = ma.masked_invalid(flatarr)
mxval = flatarr.max()
mnval = flatarr.min();
print "MIN AND MAX ARE ", mnval, mxval
flatarr = flatarr.filled(0)*255/(mxval-mnval)+mnval #scale and bias into 0..255 for display
im = PIL.Image.fromarray(flatarr.reshape((zlib_width, zlib_height)))
else: else:
im = PIL.Image.open(fname) im = PIL.Image.open(fname)
asnumpy = np.array(im, np.float32) asnumpy = np.array(im, np.float32)
......
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