Jump to content

I don't know if this is the right place to post this but I will anyway.

So I know lossy compression deletes some data from the file and that data can never be got back. Then when you open the file the computer estimates the colour of the pixels lost using the neighbouring pixels. What I'm confused about is how lossless compression gets data back which is 100% accurate. If the data has already been lost from the file from being compressed how does the computer get the data back without using some kind of estimation?

Link to comment
https://linustechtips.com/topic/902030-how-does-lossless-compression-get-data-back/
Share on other sites

Link to post
Share on other sites

Many ways, depends on the actual file.

 

Image for example, rather than saving the color of each pixel, the data can be represented with the difference in value compared to the pixel at its left and there wont be loss of quality. For example, I have two pixels, the one on the left is 255:23:45 (RGB), the one on the right is 224:33:76. With lossless compression the data for the pixel on the right can be changed to -31:10:31 instead.

CPU: i7-2600K 4751MHz 1.44V (software) --> 1.47V at the back of the socket Motherboard: Asrock Z77 Extreme4 (BCLK: 103.3MHz) CPU Cooler: Noctua NH-D15 RAM: Adata XPG 2x8GB DDR3 (XMP: 2133MHz 10-11-11-30 CR2, custom: 2203MHz 10-11-10-26 CR1 tRFC:230 tREFI:14000) GPU: Asus GTX 1070 Dual (Super Jetstream vbios, +70(2025-2088MHz)/+400(8.8Gbps)) SSD: Samsung 840 Pro 256GB (main boot drive), Transcend SSD370 128GB PSU: Seasonic X-660 80+ Gold Case: Antec P110 Silent, 5 intakes 1 exhaust Monitor: AOC G2460PF 1080p 144Hz (150Hz max w/ DP, 121Hz max w/ HDMI) TN panel Keyboard: Logitech G610 Orion (Cherry MX Blue) with SteelSeries Apex M260 keycaps Mouse: BenQ Zowie FK1

 

Model: HP Omen 17 17-an110ca CPU: i7-8750H (0.125V core & cache, 50mV SA undervolt) GPU: GTX 1060 6GB Mobile (+80/+450, 1650MHz~1750MHz 0.78V~0.85V) RAM: 8+8GB DDR4-2400 18-17-17-39 2T Storage: HP EX920 1TB PCIe x4 M.2 SSD + Crucial MX500 1TB 2.5" SATA SSD, 128GB Toshiba PCIe x2 M.2 SSD (KBG30ZMV128G) gone cooking externally, 1TB Seagate 7200RPM 2.5" HDD (ST1000LM049-2GH172) left outside Monitor: 1080p 126Hz IPS G-sync

 

Desktop benching:

Cinebench R15 Single thread:168 Multi-thread: 833 

SuperPi (v1.5 from Techpowerup, PI value output) 16K: 0.100s 1M: 8.255s 32M: 7m 45.93s

Link to post
Share on other sites

22 minutes ago, Almostbauws said:

My understanding is that lossless compression isnt really lossless, but the loss is small enough so they can call it "lossless"

Lossless compression is entirely lossless. The original data can be restored 100% from the compressed data.

Link to post
Share on other sites

13 minutes ago, Jurrunio said:

Many ways, depends on the actual file.

 

Image for example, rather than saving the color of each pixel, the data can be represented with the difference in value compared to the pixel at its left and there wont be loss of quality. For example, I have two pixels, the one on the left is 255:23:45 (RGB), the one on the right is 224:33:76. With lossless compression the data for the pixel on the right can be changed to -31:10:31 instead.

And for video, you can do that image compression and then add interframe compression - each time there's a big change in the image (new scene in a movie eg.), the compression can use that frame as a reference. The following frames only store the stuff that changed compared to the reference frame, which can save tons of space especially when the picture is only changing a little.

Link to post
Share on other sites

Think about it this way.

 

Uncompressed Information: 1 000 000 000 000 000 000 000 000 000

Lossy Compressed Information: 1x1021

 

I used 28 characters to represent a number and I compressed it to six characters but both represent the same number.  However our compressed number, in scientific notation, requires a bit of math to reconstruct.  Lossless compression works like that only it uses VASTLY more complicated techniques to take repeatable, patterened or redundant information, reduce what is needed to store it, and then reconstruct it.  However because of how this works you can have data that is already SO absent of compressable information that lossless compression has minimal or no effect.  Meanwhile some types of data can be HIGLY compressed.  This is why a lossless PNG image of nothing but black can be absolutely TINY but a full color, detailed photo won't be nearly as small, even if both images are the same resolution and the same size when uncompressed.

Link to post
Share on other sites

2 hours ago, AshleyAshes said:

Think about it this way.

 

Uncompressed Information: 1 000 000 000 000 000 000 000 000 000

Lossy Compressed Information: 1x1021

 

I used 28 characters to represent a number and I compressed it to six characters but both represent the same number.  However our compressed number, in scientific notation, requires a bit of math to reconstruct.  Lossless compression works like that only it uses VASTLY more complicated techniques to take repeatable, patterened or redundant information, reduce what is needed to store it, and then reconstruct it.  However because of how this works you can have data that is already SO absent of compressable information that lossless compression has minimal or no effect.  Meanwhile some types of data can be HIGLY compressed.  This is why a lossless PNG image of nothing but black can be absolutely TINY but a full color, detailed photo won't be nearly as small, even if both images are the same resolution and the same size when uncompressed.

Ok I understand now thanks.

Link to post
Share on other sites

6 hours ago, Assassinguy2623 said:

Then when you open the file the computer estimates the colour of the pixels lost using the neighbouring pixels.

No, the file describes how those pixels should be. They may not be faithful to the original because of the information loss, but there is no guesswork involved. A compressed image (even a lossy one) will always be displayed in exactly the same way.

6 hours ago, Assassinguy2623 said:

What I'm confused about is how lossless compression gets data back which is 100% accurate. If the data has already been lost from the file from being compressed how does the computer get the data back without using some kind of estimation?

The data is not lost with lossless compression algorithms. The algorithm just stores the data in a smart way to use as little space as possible. If an image is all made of pure black pixels you can just write in the file the size of the image and the color of the pixels and have reduced the size to a couple of bytes without losing any data; a non compressed image just lists every pixel with its color value, there are many ways to store that information more efficiently without losing details.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×