Skip to content

Commit 8cad10b

Browse files
committed
Adding some basics image processing scripts
1 parent 507983f commit 8cad10b

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

Image_Processing/src/basics/basic.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# coding: utf8
2+
# Python implementation of basic image processing
3+
# Author: Caio Cesar Viana da Silva
4+
# Install scikit-image: pip install scikit-image
5+
6+
# import skimage.io as io
7+
# from matplotlib import pyplot as plt
8+
# import numpy as np
9+
# from skimage.transform import AffineTransform, warp
10+
# import skimage.transform as ski
11+
12+
#OPENING AN IMAGE
13+
14+
def open_img(img_path):
15+
import skimage.io as io
16+
17+
img = io.imread(img_path)
18+
io.imshow(img)
19+
io.show()
20+
return img
21+
22+
23+
#VISUALIZE HISTOGRAM
24+
25+
def histogram_img(img_path):
26+
import skimage.io as io
27+
from matplotlib import pyplot as plt
28+
29+
img = io.imread(img_path)
30+
plt.hist(img.ravel(),256,[0,256])
31+
plt.show()
32+
33+
#RGB HISTOGRAM
34+
35+
def histogram_rgb_img(img_path):
36+
import skimage.io as io
37+
from matplotlib import pyplot as plt
38+
39+
img = io.imread(img_path)
40+
color = [ 'r','g','b']
41+
for i, c in enumerate(color) :
42+
plt.hist(img[:,:,i].flatten(),256, color=c)
43+
plt.show()
44+
45+
46+
#RGB TO GRAYSCALE
47+
48+
def rgb_2_gray(img_path):
49+
import numpy as np
50+
import matplotlib.pyplot as plt
51+
52+
img = open_img(img_path)
53+
gray = np.dot(img[...,:3], [0.299, 0.587, 0.114])
54+
plt.imshow(gray, cmap = plt.get_cmap('gray'))
55+
plt.show()
56+
57+
#SCALING IMAGE
58+
59+
def scaling_img(img_path):
60+
import skimage.io as io
61+
import matplotlib.pyplot as plt
62+
63+
fig = plt.figure(figsize=(1,8))
64+
img = io.imread(img_path)
65+
plt.imshow(img)
66+
plt.show()
67+
68+
69+
#TRANSLATING IMAGE
70+
71+
def translating_img(img_path, vector):
72+
import matplotlib.pyplot as plt
73+
from skimage.transform import AffineTransform, warp
74+
75+
img = open_img(img_path)
76+
transform = AffineTransform(translation=vector)
77+
shifted = warp(img, transform, mode='constant', preserve_range=True)
78+
plt.imshow(shifted)
79+
plt.show()
80+
81+
#ROTATING IMAGE
82+
83+
def rotating_img(img_path, degree):
84+
import skimage.io as io
85+
import skimage.transform as ski
86+
87+
img = open_img(img_path)
88+
imgR = ski.rotate(img,degree)
89+
io.imshow(imgR)
90+
io.show()
91+
92+
93+
def main():
94+
95+
open_img('test.jpg')
96+
histogram_img('test.jpg')
97+
histogram_rgb_img('test.jpg')
98+
rgb_2_gray('test.jpg')
99+
scaling_img('test.jpg')
100+
translating_img('test.jpg',[-100, -100])
101+
rotating_img('test.jpg',45)
102+
103+
104+
105+
106+
if __name__ == "__main__":
107+
main()

0 commit comments

Comments
 (0)