Image Compression you can implement in a day

In summary, To implement a decent image compression algorithm in a short time without using libraries, the conversation suggests looking into Huffman encoding as a possible option. Other suggestions include computing the differences between pixel values and using Run Length Encoding or copying the pixel above to take advantage of correlations. The conversation also mentions the possibility of using LZW compression or the codes described in the FAX standard.
  • #1
Superposed_Cat
388
5
I need to implement a decent image compression algorithm in a day or two, without using libraries.
So it can't be anything with multiple layers, like jpeg.
I was thinking huffman encoding,

Which would be a good algorithm I can learn to implement in a day or two that is not terrible at it's job.
 
Technology news on Phys.org
  • #2
Superposed_Cat said:
I need to implement a decent image compression algorithm in a day or two, without using libraries.
So it can't be anything with multiple layers, like jpeg.
I was thinking huffman encoding,

Which would be a good algorithm I can learn to implement in a day or two that is not terrible at it's [SIC] job.
You can find good examples on the internet of huffman encrypt/decrypt. I remember years ago lifting one and modifying it to my needs in a couple of hours.
 
  • Like
Likes Klystron, Superposed_Cat and anorlunda
  • #3
.
phinds said:
You can find good examples on the internet of huffman encrypt/decrypt. I remember years ago lifting one and modifying it to my needs in a couple of hours.
Another idea is to compute the difference between a pixel value and the pixel value to the left or above it, and use huffman compression on those differences. (you can just use unsigned values,)
 
  • #5
1) The simplest of course in just Run Length encoding. That takes advantage of correlations along scan lines.

2) The next step up is correlation between succesive scan lines (copy the pixel above) combined with Run Length.

3) One more step up is copy 2) above that is <offset or different length> by X pixels.

Number 3 above is used in FAX machines. The specific codes for the above are described in the FAX standard. I worked on the early prototypes several decades ago and don't recall the details. This Google search returns many results and probably has the actual standard listed.
https://www.google.com/search?&q=fax+code+standards
The hardware implementation required a one-scanline buffer for the look-behind, some logic, and 3 or 4 EEprom memories for the table lookup/encode-decode.

Cheers,
Tom
 
  • Like
Likes berkeman

1. What is image compression?

Image compression is the process of reducing the size of an image file without significantly affecting its visual quality. This is done by removing unnecessary data from the image while preserving the important details.

2. Why is image compression important?

Image compression is important because it allows for efficient storage and transmission of images. With the increasing use of digital media, large image files can take up a lot of storage space and take longer to load, causing delays in online communication. Compression helps to reduce file size and make images easier to share and access.

3. How does image compression work?

There are two main types of image compression: lossless and lossy. In lossless compression, data is removed from the image but the quality remains the same. In lossy compression, some data is permanently removed, resulting in a slight degradation in image quality. Different compression algorithms use various techniques to achieve this, such as reducing color depth or grouping similar pixels together.

4. What are the benefits of using image compression?

Using image compression can result in faster loading times, reduced storage space, and improved website or application performance. It also allows for easier sharing of images, especially on platforms with size restrictions, such as social media.

5. Are there any downsides to using image compression?

One potential downside of image compression is a decrease in image quality, especially with lossy compression. This can result in a loss of important details or a decrease in overall visual appeal. Additionally, repeated compression and decompression of an image can lead to a loss of quality over time.

Similar threads

  • Programming and Computer Science
Replies
13
Views
3K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
31
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
926
  • Programming and Computer Science
Replies
4
Views
670
  • Computing and Technology
Replies
0
Views
176
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top