I have been working on a project in node js for compression of .txt file. So far i have been succeeded in that goal by using Arithmetic coding for encoding and decoding of data but now i want use that code for compression of images but i can't get the idea how to do that. My main problem is how should i read data from image to compress. I did not have slightest idea how to do that with Buffer , stream or even with Blob (by sometime searching on interest theses were the possible way to do that.).
I knew that dealing with images in Python is quite easy so i though to make script to read images with python. For just now i am not integrating Python and Node js that will be later step.
I had small experience with some python libraries like open-csv and Pillow (PIL). So far i have used cv2.imread() function to read an image and store it as binary in .txt file. as for now i have not integrated it with Node js.
from cv2 import cv2
img1 = cv2.imread('cat.png',0)
with open("cat.txt", 'wb') as out:
out.write(img1.tobytes())
Now i use that cat.txt file and read that data by fs in node js and than compress and decompress it
by Arithmetic coding.
Now to main problem :
When i read image in
pythonand store it incat.txtit's size is quite bigger thancat.pngfile. Even such that after compressing thatcat.txtfile the resultantcompressed_cat.txtis bigger than that ofcat.png.
cat.png= 242kb,cat.txt(before compression)= 971kb,compressed_cat.txt(after compression)= 251kb
I think i am reading or storing the file incorrectly. I don't know how to overcome that problem.
Some additional help needed
- Is there any way to process image in
node jslike inpythonso i don't need to integrate it later. I have triedMulterandJimpbut i could not find anything in it likepython open-csv - And i don't know how to store the data after compression because mostly it is stored in either
.zipor.rar. I have never stored/read data in/form that type of format.