forked from qalhata/Python-Scripts-Repo-on-Data-Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatVis_Images.py
111 lines (83 loc) · 2.83 KB
/
DatVis_Images.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 1 19:30:44 2017
@author: Shabaka
"""
import matplotlib.pyplot as plt
import numpy as np
# Load the image into an array: img
img = plt.imread('480px-Astronaut-EVA.jpg')
# Print the shape of the image
print(img.shape)
# Display the image
plt.imshow(img)
# Hide the axes
plt.axis('off')
plt.show()
# ''''''''''' Pseudocolor Plot from Image Data ''''''''''''#
# Load the image into an array: img
img = plt.imread('480px-Astronaut-EVA.jpg')
# Print the shape of the image
print(img.shape)
# Compute the sum of the red, green and blue channels: intensity
intensity = img.sum(axis=2)
# Print the shape of the intensity
print(intensity.shape)
# Display the intensity with a colormap of 'gray'
plt.imshow(intensity, cmap='gray')
# Add a colorbar
plt.colorbar()
# Hide the axes and show the figure
plt.axis('off')
plt.show()
# # '''''''''''''Specifying Extents and Aspect Ratio '''''#
# Load the image into an array: img
img = plt.imread('480px-Astronaut-EVA.jpg')
# Specify the extent and aspect ratio of the top left subplot
plt.subplot(2, 2, 1)
plt.title('extent=(-1,1,-1,1),\naspect=0.5')
plt.xticks([-1, 0, 1])
plt.yticks([-1, 0, 1])
plt.imshow(img, extent=(-1, 1, -1, 1), aspect=0.5)
# Specify the extent and aspect ratio of the top right subplot
plt.subplot(2, 2, 2)
plt.title('extent=(-1,1,-1,1),\naspect=1')
plt.xticks([-1, 0, 1])
plt.yticks([-1, 0, 1])
plt.imshow(img, extent=(-1, 1, -1, 1), aspect=1)
# Specify the extent and aspect ratio of the bottom left subplot
plt.subplot(2, 2, 3)
plt.title('extent=(-1,1,-1,1),\naspect=2')
plt.xticks([-1, 0, 1])
plt.yticks([-1, 0, 1])
plt.imshow(img, extent=(-1, 1, -1, 1), aspect=2)
# Specify the extent and aspect ratio of the bottom right subplot
plt.subplot(2, 2, 4)
plt.title('extent=(-2,2,-1,1),\naspect=2')
plt.xticks([-2, -1, 0, 1, 2])
plt.yticks([-1, 0, 1])
plt.imshow(img, extent=(-2, 2, -1, 1), aspect=2)
# Improve spacing and display the figure
plt.tight_layout()
plt.show()
# '''''' Rescale Pixel Intensities '''''''''''''#
# Load the image into an array: image
image = plt.imread('640px-Unequalized_Hawkes_Bay_NZ.jpg')
# Extract minimum and maximum values from the image: pmin, pmax
pmin, pmax = image.min(), image.max()
print("The smallest & largest pixel intensities are %d & %d." % (pmin, pmax))
# Rescale the pixels: rescaled_image
rescaled_image = 256*(image - pmin) / (pmax - pmin)
print("The rescaled smallest & largest pixel intensities are %.1f & %.1f." %
(rescaled_image.min(), rescaled_image.max()))
# Display the original image in the top subplot
plt.subplot(2, 1, 1)
plt.title('original image')
plt.axis('off')
plt.imshow(image, extent=(-2, 2, -1, 1), aspect=2)
# Display the rescaled image in the bottom subplot
plt.subplot(2, 1, 2)
plt.title('rescaled image')
plt.axis('off')
plt.imshow(rescaled_image, extent=(-2, 2, -1, 1), aspect=2)
plt.show()