/
DisplayTools.py
76 lines (64 loc) · 2.39 KB
/
DisplayTools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""
Module to bring display tools for diffraction images
"""
___author___ = 'Cédric Montero'
___contact___ = 'cedric.montero@esrf.fr'
___copyright__ = '2012, ESRF'
___version___ = '0'
""" External modules (preliminary installation could be require) """
import fabio
import numpy
import pylab
""" Internal modules (local modules files) """
""" Program configurations """
pylab.ion()
""" Functions definitions """
#TODO : colormap selector window that apear when a display is called.
def display_image_from_edffile(filepath):
nparray = fabio.open(filepath).data
pylab.figure()
#Display array with grayscale intensity and no pixel smoothing interpolation
pylab.imshow(numpy.log(nparray),cmap='binary',interpolation='nearest',origin='lower')
pylab.axis('off')
def display_image_from_array(nparray,colory='binary',roi=None):
"""
Produce a display of the nparray 2D matrix
@param nparray : image to display
@type nparray : numpy 2darray
@param colory : color mapping of the image (see http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps)
@type colory : string
"""
#Set the region of interest to display :
# (0,0) is set at lower left corner of the image
if roi == None:
roi = ((0,0),nparray.shape)
nparraydsp = nparray
print roi
elif type(roi[0])==tuple and type(roi[1])==tuple:
# Case of 2 points definition of the domain : roi = integers index of points ((x1,y1),(x2,y2))
print roi
nparraydsp = nparray[roi[0][0]:roi[1][0],roi[0][1]:roi[1][1]]
elif type(roi[0])==int and type(roi[1])==int:
# Case of image centered domain : roi = integers (width,high)
nparraydsp = nparray[int(nparray.shape[0]/2)-int(roi[0])/2:int(nparray.shape[0]/2)+int(roi[0])/2,int(nparray.shape[1]/2)-int(roi[1])/2:int(nparray.shape[1]/2)+int(roi[1])/2]
fig = pylab.figure()
#Display array with grayscale intensity and no pixel smoothing interpolation
pylab.imshow(nparraydsp,cmap=colory,interpolation='nearest')#,origin='lower')
pylab.colorbar()
pylab.axis('off')
# Using PIL
import Image
def display_PIL(nparray):
image = Image.fromarray(nparray,'I;16')
image.show()
"""
def display_histogram(filepath):
def display_image_thresholded(filepath):
nparray = fabio.open(filepath).data
pylab.figure()
#Display array with grayscale intensity and no pixel smoothing interpolation
pylab.imshow(nparray,cmap='gray',interpolation='nearest')
pylab.axis('off')
pylab.colorbar()
"""