added “gap” value to render pieces of resulting image transparent.
This commit is contained in:
parent
66564c1f75
commit
f8658ffea1
|
@ -4,7 +4,7 @@
|
||||||
import os,sys,string
|
import os,sys,string
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw, ImageOps
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptID = string.replace('$Id$','\n','\\n')
|
scriptID = string.replace('$Id$','\n','\\n')
|
||||||
|
@ -23,6 +23,8 @@ parser.add_option('-l','--label', dest='label', type='string',
|
||||||
help='column containing data [all])')
|
help='column containing data [all])')
|
||||||
parser.add_option('-r','--range', dest='range', type='float', nargs=2,
|
parser.add_option('-r','--range', dest='range', type='float', nargs=2,
|
||||||
help='data range (min max) [auto]')
|
help='data range (min max) [auto]')
|
||||||
|
parser.add_option('--gap', '--transparent', dest='gap', type='float',
|
||||||
|
help='value to treat as transparent [%default]')
|
||||||
parser.add_option('-d','--dimension', dest='dimension', type='int', nargs=2,
|
parser.add_option('-d','--dimension', dest='dimension', type='int', nargs=2,
|
||||||
help='data dimension (width height) [native]')
|
help='data dimension (width height) [native]')
|
||||||
parser.add_option('--abs', dest='abs', action='store_true',
|
parser.add_option('--abs', dest='abs', action='store_true',
|
||||||
|
@ -50,6 +52,7 @@ parser.add_option('-y','--pixelsizey', dest='pixelsizey', type='int',
|
||||||
|
|
||||||
parser.set_defaults(label = None,
|
parser.set_defaults(label = None,
|
||||||
range = [0.0,0.0],
|
range = [0.0,0.0],
|
||||||
|
gap = None,
|
||||||
dimension = [],
|
dimension = [],
|
||||||
abs = False,
|
abs = False,
|
||||||
log = False,
|
log = False,
|
||||||
|
@ -111,13 +114,16 @@ for name in filenames:
|
||||||
if options.log: table.data = np.log10(table.data);options.range = np.log10(options.range)
|
if options.log: table.data = np.log10(table.data);options.range = np.log10(options.range)
|
||||||
if options.flipLR: table.data = np.fliplr(table.data)
|
if options.flipLR: table.data = np.fliplr(table.data)
|
||||||
if options.flipUD: table.data = np.flipud(table.data)
|
if options.flipUD: table.data = np.flipud(table.data)
|
||||||
|
|
||||||
|
mask = np.where(table.data != options.gap,True,False) if options.gap != None else np.ones_like(table.data,dtype='bool')
|
||||||
if np.all(np.array(options.range) == 0.0):
|
if np.all(np.array(options.range) == 0.0):
|
||||||
options.range = [table.data.min(),table.data.max()]
|
options.range = [table.data[mask].min(),
|
||||||
file['croak'].write('data range: %g -- %g\n'%(options.range[0],options.range[1]))
|
table.data[mask].max()]
|
||||||
|
file['croak'].write('data range: %g – %g\n'%(options.range[0],options.range[1]))
|
||||||
|
|
||||||
delta = max(options.range) - min(options.range)
|
delta = max(options.range) - min(options.range)
|
||||||
avg = 0.5*(max(options.range) + min(options.range))
|
avg = 0.5*(max(options.range) + min(options.range))
|
||||||
print delta,avg,delta/avg
|
|
||||||
if delta * 1e8 <= avg: # delta around numerical noise
|
if delta * 1e8 <= avg: # delta around numerical noise
|
||||||
options.range = [min(options.range) - 0.5*avg, max(options.range) + 0.5*avg] # extend range to have actual data centered within
|
options.range = [min(options.range) - 0.5*avg, max(options.range) + 0.5*avg] # extend range to have actual data centered within
|
||||||
|
|
||||||
|
@ -129,8 +135,10 @@ for name in filenames:
|
||||||
repeat(options.pixelsizey,axis = 0)
|
repeat(options.pixelsizey,axis = 0)
|
||||||
|
|
||||||
(height,width) = table.data.shape
|
(height,width) = table.data.shape
|
||||||
|
file['croak'].write('image dimension: %i x %i\n'%(width,height))
|
||||||
|
|
||||||
im = Image.fromarray(theColors[np.array(255*table.data,dtype='i')], 'RGB').\
|
im = Image.fromarray(np.dstack((theColors[np.array(255*table.data,dtype=np.uint8)],
|
||||||
|
255*mask.astype(np.uint8))), 'RGBA').\
|
||||||
crop(( options.crop[0],
|
crop(( options.crop[0],
|
||||||
options.crop[2],
|
options.crop[2],
|
||||||
width -options.crop[1],
|
width -options.crop[1],
|
||||||
|
|
Loading…
Reference in New Issue