2.2 - Viewing the image with MatplotLib

With different types of visualization according to the parameters when calling the imshow() method

In [13]:
#Init figure
f1 = plt.figure()
f1.add_subplot()

#Show raw image - Parameters dataset-image & colorMap
plt.imshow(image_data, cmap='gray')
plt.show()

Characteristics of the image

To display information about the shooting characteristics, the numpy library can be associated with the numpy library. This allows the statistical values (min, max, avg, standard deviation) to be displayed in addition to the histogram of the image.

Please note that this is a 32 bit floating point image (float). The values will of course be different when working with a 16 bit image. (int).

In [14]:
print('----- Statistics values -----')
print('Min :', np.min(image_data))
print('Max :', np.max(image_data))
print('Mean :', np.mean(image_data))
print('Stdev :', np.std(image_data))
print('Data Type :', image_data.dtype) #i.e. <f4 = little-endian single-precision floating point 32 bit 
#(More detail about stype at https://numpy.org/doc/stable/reference/arrays.dtypes.html)
print('Image length : ', len(image_data)) # size list
print('Shape :', image_data.shape) # dimensions of the array
----- Statistics values -----
Min : 0.0
Max : 1.0
Mean : 0.0162365
Stdev : 0.023749666
Data Type : >f4
Image length :  3672
Shape : (3672, 5496)
In [15]:
np.seterr(divide='ignore') #suppress the warnings raised by taking log10 of data with zeros

#New figure
f2 = plt.figure()

#Prepare Histogram
#Because image is a 2D Tab, need to convert in 1-D for plotting
#Use flatten () method on an array return 1-D numpy tab.
plt.hist(np.log10(image_data.flatten()), range=(-3, 2), bins=1000);

#Show Histogram
plt.show()

We will thus be able to modify the display of our image according to the areas of the histogram that interest us most (i.e. -0.2 / 0.2), because their visualization is facilitated.

In [16]:
f3 = plt.figure()
img = plt.imshow(image_data)
img.set_clim(-0.1,0.3)
plt.colorbar()
Out[16]:
<matplotlib.colorbar.Colorbar at 0x7f8df2171350>

But also use different types of colouring (cmap) and a logarithmic scale with numpy ( np.log(dataset-image) ).

In [17]:
#hide warnings
import warnings
warnings.filterwarnings("ignore", category=UserWarning)

from matplotlib.colors import LogNorm

f4 = plt.figure()
f4.suptitle('gam Cas with different visualisation type')

f4.add_subplot(2,2, 1)
plt.imshow(np.log10(image_data), cmap='plasma', vmin=-3, vmax=0, origin='lower')
plt.colorbar()

f4.add_subplot(2,2, 2)
plt.imshow(np.log10(image_data), cmap='viridis', vmin=-3, vmax=0, origin='lower')
plt.colorbar()

f4.add_subplot(2,2,3)
plt.imshow(np.log10(image_data), cmap='hot', vmin=-3, vmax=0, origin='lower')
plt.colorbar()

f4.add_subplot(2,2, 4)
plt.imshow(np.log10(image_data), cmap='nipy_spectral',  vmin=-3, vmax=0, origin='lower')
plt.colorbar()

plt.show(block=True)

#More params at https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html