-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompresser.py
46 lines (35 loc) · 1.4 KB
/
compresser.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
from basic import *
from chiseler import chiseler
import numpy as np
import cv2
import sys
def compresser(img):
# this file will compress big file in to small one
dimention ,image = chiseler(img)
image = image.tolist()
height,width =image_size(image)
# array of zeros of requirment dimentions
git_image = create_empty_array(height,width,dimention)
# adding data to git image
for git_h,i in enumerate(range(0,height,dimention)):
# give index and value of jump (0,0)
for x in range(i,i+dimention):
# go in each line one by one of each jump [profit]!! jump provide index for git_img
# so x is each line
for git_w,j in enumerate(range(0,width,dimention)):
# on each single line width of whole image come with different jumps provide index for git_img
for y in range(j,j+ dimention):
# so y is each element
# adding color code to the elements
git_image[git_h][git_w] += image[x][y]
# so there for each element it is the sum of dimention**2 pixles colours
# to take the average of all the if =sum of all the number /numbers of numbers
for i in range(len(git_image)):
for j in range(len(git_image[i])) :
git_image[i][j] = round((git_image[i][j])/(dimention**2))
print( f'✅ image is compressed here by {dimention} times')
return (dimention,git_image)
if __name__ == "__main__" :
im = 'img/1.jpeg'
a=compresser(im)
# print(a)