forked from nishant-Tiwari24/python-foundation-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCompression.py
More file actions
28 lines (19 loc) · 712 Bytes
/
DataCompression.py
File metadata and controls
28 lines (19 loc) · 712 Bytes
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
import numpy as np
from PIL import Image
img = Image.open('img_name')
pixelMap = img.load()
I = np.asanyarray(Image.open('img_name'))
imgNew = Image.new(img.mode,img.size)
pixelNew = imgNew.load()
for i in range(img.size[0]):
for j in range(img.size[1]):
if(pixelMap[i,j]>=0 and pixelMap[i,j]<=31):
pixelMap[i,j] = 0
elif(pixelMap[i,j]>=32 and pixelMap[i,j]<=63):
pixelMap[i,j] = 1
elif(pixelMap[i,j]>=64 and pixelMap[i,j]<=95):
pixelMap[i,j] = 2
elif(pixelMap[i,j]>=96 and pixelMap[i,j]<=127):
pixelMap[i,j] = 2
img2 = pixelMap.load()
img.save('new_image_name')