publiclab / image-sequencer

A pure JavaScript sequential image processing system, inspired by storyboards
https://sequencer.publiclab.org
GNU General Public License v3.0
110 stars 208 forks source link

Lossless image compression #1505

Open niravasher opened 4 years ago

niravasher commented 4 years ago

Please describe the problem (or idea)

What did you expect to see that you didn't?

A new module for compressing images without loss of any data (lossless compression)

various algorithms are present for the same purpose. Deflate - https://github.com/madler/zlib/blob/master/deflate.c Chain code algorithm - https://www.geeksforgeeks.org/chain-code-for-2d-line/


Thank you!

Your help makes Public Lab better! We deeply appreciate your helping refine and improve this site.

To learn how to write really great issues, which increases the chances they'll be resolved, see:

https://publiclab.org/wiki/developers#Contributing+for+non-coders

daemon1024 commented 4 years ago

I would like to work on it .

niravasher commented 4 years ago

Go ahead @daemon1024

YogeshSharma01 commented 4 years ago

Hi, Can i also work on this ?

harshkhandeparkar commented 4 years ago

Sorry but someone has already claimed the issue.

YogeshSharma01 commented 4 years ago

Yeah, sure @HarshKhandeparkar Thank!

daemon1024 commented 4 years ago

Thanks @niravasher. I have a few queries regarding this issue.

  1. We will be compressing BMP/RAW files or JPEG/PNG files (Since they are already compressed version of the prior) too? ( Something like this https://medium.com/breaktheloop/jpeg-compression-algorithm-969af03773da maybe )

  2. We need to implement the algorithm without any third party libraries or we can use libraries if needed.

niravasher commented 4 years ago

1) Users of image sequencer will upload JPEG/PNG images for compression, so you should start with that I think. 2) You can use third party libraries if needed @daemon1024

daemon1024 commented 4 years ago

From what I have researched for the last day, compression algorithms are based on bitmap images. So maybe we can convert the images to bitmap , compress them using algorithms like Huffman and then convert them back to BMP.

Conversion to BMP and the other way round can be done using OpenCV.Js .

I don't know if I am in the right direction or this a feasible idea so wanted to lay out what I have understood right now.

Also we can use something like https://tinypng.com/developers/reference/nodejs. I couldn't find anything that directly losslessly compresses jpeg. https://compressor.io/compress provides lossless compression but it seems to be patented.

daemon1024 commented 4 years ago

@niravasher @HarshKhandeparkar

harshkhandeparkar commented 4 years ago

@publiclab/is-reviewers

niravasher commented 4 years ago

Also we can use something like https://tinypng.com/developers/reference/nodejs. I couldn't find anything

Yes, I think this works. Also check these for further reference :- https://www.npmjs.com/package/tinify. This compresses both PNG and JPEG, although I am not sure if they are lossy or lossless. https://www.npmjs.com/package/compress-images @daemon1024

daemon1024 commented 4 years ago

https://www.npmjs.com/package/compress-images

I looked into the module it uses algorithms like jpegoptim, mozjpeg, optipng which support lossless compression. So maybe we can implement it in a way such that users are given control if they want lossless or lossy and which algorithm they want to use. @niravasher

niravasher commented 4 years ago

Initially build the module for lossless compression only, open a PR, then as per instructions from reviewers you could add options @daemon1024

harshkhandeparkar commented 4 years ago

Try to chose a library that supports both, lossless and lossy.

niravasher commented 4 years ago

@daemon1024 are you still working on this?

daemon1024 commented 4 years ago

@niravasher Yes, I am working on this. I have most of the stuff offline.

Should I make a PR with WIP? I haven't made significant progress in code implementation cause I spent most of the week in understanding how is image-sequencer working and traversing through the codebase. I will have a initial module ready by end of the week.

niravasher commented 4 years ago

@daemon use this https://www.npmjs.com/package/compress-images . Setting quality to 100 will lead to lossless compression and setting it less than 100 will lead to lossy compression. Plus it provides an option to choose among a lot of compression algo's

daemon commented 4 years ago

@daemon1024

daemon1024 commented 4 years ago

Hi @niravasher ,

use this https://www.npmjs.com/package/compress-images .

I was starting with the initial implementation of the module. But I can't seem to understand how is the input coming and in which format i return the output. I saw other modules and it seemed that they were returning an object but I don't understand how would we return an object.

My initial commit : https://github.com/daemon1024/image-sequencer/commit/ccca8feef9d079d5e1fcf7e2c869b74fecef9cf3

niravasher commented 4 years ago

I have commented on your commit, check it out @daemon1024

daemon1024 commented 4 years ago

Thanks @niravasher , will work on it!

daemon1024 commented 4 years ago

@niravasher made the changes you requested, Here's the commit https://github.com/daemon1024/image-sequencer/commit/7faad06f443892fe93ba948e3c13e9baad467dac

Should I make a PR with [WIP] tag to have a better discussion?

niravasher commented 4 years ago

Why not @daemon1024 . Also ask reviewers for help