-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab 1.py
136 lines (118 loc) · 4.63 KB
/
lab 1.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#import Image as Image
import rasterio
from rasterio.plot import show
from PIL import Image
import rasterio
import geotiff
import tifffile as tiff
import matplotlib.pyplot as plt
import numpy as np
import cv2
'RGB'
img = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
img2_rgb = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
plt.imshow(img2_rgb)
plt.axis('off')
plt.show()
"canny edge of image"
"""try:
img = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
edges = cv2.Canny(img, 15, 10)
edges2 = cv2.Canny(img2, 15, 10)
cv2.imwrite('result.tiff', edges)
plt.imshow(edges)
cv2.imwrite('result.tiff', edges2)
plt.imshow(edges2)
plt.show()
except IOError:
print('Error while reading files !!!')"""
"translating the image"
"""M = np.float32([[1, 0, 100], [0, 1, 50]])
try:
# Read image from disk.
img = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
res = cv2.warpAffine(img, M, (100,50 ))
res2 = cv2.warpAffine(img2, M, (100, 50))
cv2.imwrite('result.tiff', res)
plt.imshow(res)
cv2.imwrite('result.tiff', res2)
plt.imshow(res2)
plt.show()
except IOError:
print('Error while reading files !!!')"""
'rotating the image'
"""try:
# Read image from disk.
img = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
(rows, cols) = img.shape[:2]
M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 45, 1)
res = cv2.warpAffine(img, M, (cols, rows))
res2 = cv2.warpAffine(img2, M, (cols, rows))
cv2.imwrite('result.tiff', res)
cv2.imwrite('result.tiff', res2)
plt.imshow(res)
plt.imshow(res2)
plt.show()
except IOError:
print('Error while reading files !!!')"""
"reducing tiff file size"
"""try:
# Read image from disk.
img = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = cv2.imread("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHV.tif")
(height, width) = img.shape[:2]
res = cv2.resize(img, (int(width / 2), int(height / 2)), interpolation=cv2.INTER_CUBIC)
res2 = cv2.resize(img2, (int(width / 2), int(height / 2)), interpolation=cv2.INTER_CUBIC)
cv2.imwrite('result.tiff', res)
cv2.imwrite('result.tiff', res2)
plt.imshow(res)
plt.imshow(res2)
plt.show()
except IOError:
print('Error while reading files !!!')"""
'image statistics'
"""img = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHV.tif")
img_array = np.array(img)
mean = np.mean(img_array)
dev= np.std(img_array)
min = np.min(img_array)
max = np.max(img_array)
img2_array = np.array(img2)
mean2 = np.mean(img2_array)
dev2= np.std(img2_array)
min2 = np.min(img2_array)
max2 = np.max(img2_array)
print('minimum value of HH image = ',min ,"\n","maximum value of HH image =", max,"\n",'meanof HH image =', mean,"\n","standard dev of HH image=",dev )
print('minimum value of HV image = ',min2 ,"\n","maximum value of HV image =", max2,"\n",'mean of HV image =', mean2,"\n","standard dev of HV image=",dev2 )"""
'open a tiff file'
"""img = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHV.tif")
show(img)
show(img2)
pixels = img.load()
pixels2 = img2.load()"""
'second programme Meta data about tiff images'
"""a=rasterio.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
b=rasterio.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHV.tif")
img = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHH.tif")
img2 = Image.open("C:\\Users\\ma\\project\\Scripts\\data\\lab1\\ShahzadpurHV.tif")
width= a.width
height=a.height
width2= b.width
height2=b.height
num_bands = a.count
num_bands2 = b.count
print("Image(HH) Size (Width x Height):", width, "x", height)
print("Image (HV) Size (Width x Height):", width2, "x", height2)
print("Number of Bands of HH:", num_bands)
print("Number of Bands of HH:", num_bands2)
plt.imshow(img)
plt.imshow(img2)
plt.show()"""