Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Pixel loss in resizing images
Pixel loss in resizing images
2009-12-17, 6:54 AM #1
This is probably quite a trivial question, but one I'm not really sure of. If I have an image, and I resize the image to 200% width and height, what actually happens? Does every pixel get shifted along one, and down one, and then the gaps filled in to effectively double the size of the pixel?

So then, if I now resize it again by 50%, back to the original size, does it then select every other pixel, removes all others, then moves every pixel in?

If this the above is true, then the original image should be exactly the same as one stretched to double the size and then halved again. Is is true? Is there any information loss at all in this process?

There's probably some very easy way to explain this one way or another, but I'd quite like to test this. What would be the simplest way to resize an image hundreds of times continually? Could some sort of Photoshop macro do that? I could then compare this to the original image to see if there are any differences.

At the moment I use GIMP for simple image manipulation, but I don't want to sit here and resize the image many times manually.
"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. " - Bertrand Russell
The Triumph of Stupidity in Mortals and Others 1931-1935
2009-12-17, 7:06 AM #2
There are many different image resizing algorithms. Some work like you described, others are a little more complex. So it depends.
Sorry for the lousy German
2009-12-17, 7:23 AM #3
MSPaint use to work like that and I presume that it still does. Other paint programs, as Impi stated, use a variety of resizing algorithms. So, you won't really have data loss per se as much as it would be data deviation. This deviation would be limited by the difference in color pixels. The less the difference between pixel RBG, the less the difference in data deviation when resized back to normal.

Is this just curiosity or are you asking for academic/business reasons?
2009-12-17, 7:24 AM #4
A. Photoshop macros can indeed do that if you want.
B. Yes, if you use your method of resizing, no data is actually lost, and can be regained, as long as you do not DECREASE the size below the original source image size.
C. The method of resizing you describe is called "Nearest Neighbor" resizing. Other common types are bicubic and bilinear. Bicubic is often the highest quality method of resizing, but also the most CPU costly. Photoshop offers all three, and has 3 different versions of bicubic.

There's arguments to be made for all methods of resizing, as some are better for certain scenarios than others. When working with old game sprites and such, nearest neighbor resizing will give a more accurate feel, but have rough edges. When working with photos, bicubic will do different algorithms based on surrounding pixels to create new pixels, which results in a smoother, more appealing, but less detailed (sharp) photo.
2009-12-17, 7:32 AM #5
Originally posted by Alco:
Is this just curiosity or are you asking for academic/business reasons?


Complete idle curiosity.

In particular, because I fell in love with the Vrubel painting The Demon Downcast
[http://www.failbetter.com/Assets/Images/06/VrubelDemonDowncast.jpg]
This is the best quality version I could find (some of the others I found are high quality scans from textbooks, but the colours look more dim)

I wanted a bigger version of this, but blowing it up made it look odd, so I shrunk it back again and I wasn't sure if it was unchanged.

I'll try to learn to use Photoshop macros and try out those three different algorithms over n iterations and see how image quality varies with n. That might make an interesting animation or something.
"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. " - Bertrand Russell
The Triumph of Stupidity in Mortals and Others 1931-1935
2009-12-17, 7:45 AM #6
Well if you did a resize with photoshop or something, not a nearest neighbor resize, I can guarantee that it was not unchanged. You WILL lose data from bicubic/bilinear resizes.
2009-12-17, 7:47 AM #7
I used GIMP, I'm not sure what algorithm it uses.

Why not use nearest neighbour resize all the time? If it's perfectly lossless, surely it's the superior algorithm?
"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. " - Bertrand Russell
The Triumph of Stupidity in Mortals and Others 1931-1935
2009-12-17, 7:49 AM #8
It's only lossless in that specific situation you described.
2009-12-17, 8:00 AM #9
Originally posted by Mort-Hog:
I used GIMP, I'm not sure what algorithm it uses.

Why not use nearest neighbour resize all the time? If it's perfectly lossless, surely it's the superior algorithm?


Because with enlargements especially, it looks god awful on photos.
2009-12-17, 8:05 AM #10
Case in point, here's your picture at 200%:

Nearest Neighbor:
[http://dl.dropbox.com/u/41063/nearest.png]

Bilinear:
[http://dl.dropbox.com/u/41063/bilinear.jpg]

Bicubic (Best for Enlargement) Photoshop setting:
[http://dl.dropbox.com/u/41063/bicubic.jpg]
2009-12-17, 9:13 AM #11
Photoshops upscaling is god awful. Genuine Fractals seems to scale up really really well.

http://blog.iso50.com/2009/10/07/genuine-fractals/

http://www.ononesoftware.com/detail.php?prodLine_id=7
[01:52] <~Nikumubeki> Because it's MBEGGAR BEGS LIKE A BEGONI.
2009-12-17, 9:25 AM #12
Originally posted by Mort-Hog:
This is probably quite a trivial question
It works exactly like the kind of interpolation you use on data points, but because there's no sane way of fitting a curve the person who wrote the software is free to interpolate using any combination of the trillions of naive interpolation algorithms that come from numerical analysis.
2009-12-17, 8:33 PM #13
It's like resampling an MP3 or a video... it works if you do it multiple times in a row, but you won't get the best results unless you convert straight from the source.

Basically, if you put an image through multiple resizes you will lose a small amount of data. So it's best to keep the source image around. If you use a good resizing algorithm to resize bigger or smaller the image will look good (best results when smaller, so get the highest resolution possible for a source image... just like you should do with mp3 or video).

Originally posted by Cool Matty:
Bicubic is often the highest quality method of resizing, but also the most CPU costly.


BTW the CPU cost is negligible usually, only on super large images (or a slow PC) will it even be a problem. Some apps will even use multiple threads on multicore to speed up the process, I think...

Originally posted by Mort-Hog:
I used GIMP, I'm not sure what algorithm it uses.


Then you need to resize images in GIMP more, it has a clear selection of resizing algorithms.

Originally posted by Mort-Hog:
Why not use nearest neighbour resize all the time? If it's perfectly lossless, surely it's the superior algorithm?


Because it's butt ugly. Unless you are going for a pixelated look and you choose an exact multiple of the old size for a new size, it's going to look bad. Any form of bilinear or bicubic algorithm will look way better for sizing smaller or bigger. Lossless usually isn't a problem because a) if you're making it smaller, you WANT to lose data anyway by the very nature of the smaller size. Bilinear or bicubic actually PRESERVE more data than nearest neighbor in this case since text and lines will be clearer. b) if you're making it bigger, you can't add any more data anyway, and bicubic just looks nicer. It still looks ugly if you stretch it big enough that the eye can tell it's been stretched, though. There's no substitute for high-resolution source images.

And if you resize to a non-multiple of the original source image size with nearest neighbor at any point, you lose data, so it's NOT lossless in the majority of cases. :P

http://x.mzzt.net/2009.12.18.00.04.47.jpg

IE7, IE8, and Chrome. IE7 clearly has no filtering, the others do, the difference is best seen with images with lots of high-contrast edges.

2009-12-17, 9:37 PM #14
Originally posted by The Mega-ZZTer:
Any form of bilinear or bicubic algorithm will look way better for sizing smaller or bigger.
I was going to post something about the acutance problem with bicubic interpolation but I think I just thought of a way to fix it.
2009-12-17, 10:26 PM #15
You will either win the Nobel prize 18 times, or get the words "Full of himself" on your gravestone.
2009-12-17, 11:20 PM #16
Originally posted by The Mega-ZZTer:
And if you resize to a non-multiple of the original source image size with nearest neighbor at any point, you lose data, so it's NOT lossless in the majority of cases. :P


Even I figured that bit out! :neckbeard:

/goes back to his hole.
2009-12-18, 6:54 AM #17
Quote:
And if you resize to a non-multiple of the original source image size with nearest neighbor at any point, you lose data, so it's NOT lossless in the majority of cases.


I don't see how that's true.

Say you have an image 100px wide. You resize it using nearest neighbor to 1.5x its original size. The new size is 150px.

Now, I would expect it to simply double every other pixel. However, this operation should be easily reversible, if when resizing back you remove the same pixels.
2009-12-18, 6:58 AM #18
Surely with odd numbers it'll start to get lossy.

/really must stay in his hole.
2009-12-18, 7:00 AM #19
Originally posted by Martyn:
Surely with odd numbers it'll start to get lossy.

/really must stay in his hole.


As long as the algorithm removes pixels in the same order as it adds them, I don't think it should.
2009-12-18, 8:45 AM #20
This is true. <_<
2009-12-18, 10:17 AM #21
Yeah I suppose that would work. That still doesn't change the fact that the quality still sucks. :P

Plus WHY would you want to resize back to the original? :P

2009-12-18, 10:19 AM #22
Dunno. Just sayin'.

↑ Up to the top!