-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharcodeImage.py
More file actions
33 lines (20 loc) · 867 Bytes
/
Copy patharcodeImage.py
File metadata and controls
33 lines (20 loc) · 867 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
28
29
30
31
32
33
import arcode
import Image, numpy
import array
class ArithmeticCodeImage (arcode.ArithmeticCode):
def _init_(self):
super(ArithmeticCodeImage,self)
def encode(self, input_file_name, output_file_name):
f_tmp = open("tmp.in","wb")
im = Image.open( input_file_name)
im = im.convert("L") #to grayscale
a = numpy.asarray(im)
a.tofile(f_tmp)
f_tmp.close()
super(ArithmeticCodeImage,self).encode(self, "tmp.in", output_file_name)
def decode_file(self, input_file_name, output_file_name):
super(ArithmeticCodeImage,self).encode(self, output_file_name,"tmp.out")
f_tmp = open("tmp.out","wb")
out = array.fromfile(f_tmp)
im = Image.fromarray(out)
im.save(output_file_name)