Scaling down algorithm : I suggest "Liquid scale"!

Started by Monsieur OUXX, Mon 18/11/2013 16:27:31

Previous topic - Next topic

Monsieur OUXX

hello,

Out of curiosity: what algorithm does AGS use to scale down sprites that walk away from camera?
I suppose it's just "nearest neighbour", or something fancy in the case of activated anti-aliasing.

I've just tried an implementation of "box" (using ImageMagick), and the results are SPECTACULAR.
EDIT: "box" is not so bad (see screenshots below), but I reckon "liquid scale" would be much better for scaling down sprites in motion. /EDIT

- Unlike bilinear and such, it does not introduce blur at all.
- It does not blindly scale down, but manages error displacement in a way that it cuts out unwanted pixels in plain areas, instead of doing it in arbitrary places. That way, details remain visible for as long as possible, before the picture becomes really too small.

I would highly recommand using that algorithm, or (Calin and Khris , nudge nudge) implementing a plugin for that.




 

Calin Leafshade


Monsieur OUXX

#2
Quote from: Calin Leafshade on Mon 18/11/2013 17:10:25
pics
Too busy figuring out the gigantic mess that are "The Dig" 's walkcycles. No time for pics!

EDIT: do you know if it's indeed "nearest neighbour" that's used in AGS?
 

Snarky

If you don't turn on interpolation, yes. I tried looking up some examples of the Imagemagick box filter; it doesn't look particularly special from those.

David Ostman

Quote from: Monsieur OUXX on Mon 18/11/2013 17:50:29
Too busy figuring out the gigantic mess that are "The Dig" 's walkcycles. No time for pics!
In the time you took to edit your previous post you could have copy and pasted an example into imgur and posted the link here. Come on, don't get us all excited about something and then leave us hanging.

Monsieur OUXX

I've been doing a bit of research: I've actually mixed up two different things :
1. A resizing algorithm I had seen a long time ago in Imagemagick, and I found it so clever at the time that it stuck with me -- as I said it displaces some sharp areas and removes the pixels from plain areas. I can't find it any more, I'll have to dig it out again.
2. The "box" algorithm. It looks "spectacular" only if you compare it with "nearest neighbour" and "bicubic", which look awful on low-res sprites.

Strangely, when I ran "box" on some sprites, a few (really only just a few) pixels actually got anti-aliased. So I suspect it's actually some kind of weighed box. I'll produce pictures if it's really necessary (David, running tests and uploading stuff is longer than it sounds :D) but Snarky said AGS is already using "box", so there's no point really.
 

monkey0506

Quote from: Monsieur OUXX on Tue 19/11/2013 23:38:03I'll produce pictures if it's really necessary

Hey, Monsieur, I drew a really amazing picture. It looks absolutely SPECTACULAR. Just completely incredible artwork, I have created. Will you let me put it in Seven Cities of Gold, no questions asked? I'd upload a copy of the picture for you to look at, but I'm too busy typing this post, lololol (laugh)

Quote from: Monsieur OUXX on Tue 19/11/2013 23:38:03Snarky said AGS is already using "box", so there's no point really.

Did he say that? Where? I didn't see him say that (and I really have no knowledge one way or the other).

selmiak

Quote from: monkey_05_06 on Wed 20/11/2013 00:18:05
Quote from: Monsieur OUXX on Tue 19/11/2013 23:38:03I'll produce pictures if it's really necessary

Hey, Monsieur, I drew a really amazing picture. It looks absolutely SPECTACULAR. Just completely incredible artwork, I have created. Will you let me put it in Seven Cities of Gold, no questions asked? I'd upload a copy of the picture for you to look at, but I'm too busy typing this post, lololol (laugh)
I'd totally trust you on that! I mean, you are a monkey using a computer, this has to be good :D

Snarky

Quote from: monkey_05_06 on Wed 20/11/2013 00:18:05
Quote from: Monsieur OUXX on Tue 19/11/2013 23:38:03Snarky said AGS is already using "box", so there's no point really.

Did he say that? Where? I didn't see him say that (and I really have no knowledge one way or the other).

I did not.

Monsieur OUXX

Would everybody calm down? I only stumbled across something that was looking good, while researching 1 billion other things.
OK, I misread Snarky's "yes". And as explained I'm not depriving you guys on purpose of that screenshot, so relax please. kthxby.
 

David Ostman

I've been looking into results of different resizing algorithms lately myself and got excited when you said you might be on to something. To be fair you kind of sounded like it was all checked out and confirmed in your original post when you recommended plugins being made for it and all, so can't blame us for nagging you about pics :P

Monsieur OUXX

#11
Yes, I tend to get carried away. I'm a big enthusiast ;)

Just because you guys asked so nicely  :



What can we say about that? (please read. Watching the picture is not enough)

1) The box algo looks a bit dirty in some places (dithering), and I'm puzzled why it's doing that. I'll double-check the command I used, to make sure I didn't introduce some anti-aliasing by mistake ( imagemagick tends to be a bit complex to use) EDIT: Oh, I think I know why. It might be because it's an indexed picture.
2) The nearest neighbour seems to keep the face's details much better. But it's only a coincidence here. The nose pixel or the eyes pixels could as well disappear. Box keeps an overall consistence.
3)You can see (especially on the arm) that much more detail is kept with "box". You can still see the entire outline of the arm.

That specific example is actually not very good, because it's better seem in motion : when you scale down a sprite in real time (typically, when the character walks away for the screen), then nearest neighbour makes big "jumps" in quality depending on which pixel is currently in line with the screen pixel. For example: the character 's eye might sort of "blink": appear, then disappear, then appear again... It's terrible for the face's look. With box, the scale-down transition should look much smoother.
 

David Ostman

Thanks for posting pics!

There's some dithering happening but I understand why you got excited about the results, the box filter retains the proportions and the head for example doesn't change shape :)

I can relate to what you're saying about scaling faces using nearest neighbor, it's a real mess especially when in some scenes you have your character scaled constantly at e.g. 80% because he's simply supposed to be smaller because the scene is bigger and supposed to be seen at a bit of a distance, and he looks like someone just ran a train into his face.

Monsieur OUXX

#13
I've found the "smart algorithm" that had struck me first time I read about it : it's called "liquid scale" : http://www.imagemagick.org/Usage/resize/#liquid-rescale

I'll run more tests on my set of sprites, to see what it's worth. But from its very definition, it should be the ultimate algorithm to scale down pixel art that gets progressively zoomed out in real time (yes, it's that specific, like any algorithm)
 

David Ostman

Using liquid scale to scale characters in realtime is an interesting idea, but would it actually look good in realtime? The result with seam carving (as it's also called) on static images is good, and you can see an example of that here, but I can imagine it being difficult to look right in motion.

Snarky

I would personally consider seam carving completely unsuitable to scaling down sprites in most situations, since it (by design) distorts shapes and proportions. You don't want stuff like this happening to your sprites as you scale them down:


David Ostman

#16
I gave it a try to see how it works in realtime, and at least in Photoshop (which has a Liquid Scaling feature) it produces pretty much what I expected. Dwarfism, I suppose:


monkey0506

#17
@Snarky: Ms. Knightley has never looked so beautiful! 8-0 (Good for Quasimodo too, finally hooking up with someone)

As to the "liquid rescale"/seam carving algorithm, just the examples on the ImageMagick site make me wonder what practical purpose it's actually meant to serve. The examples there look absolutely terrible. Even given the genuinely terrible nature of the games I produce, I wouldn't want that happening. (wrong)

Snarky

#18
Seam carving is genuinely useful for quickly manipulating photos, particularly landscape pictures, to change the composition by compressing or extending certain regions. It doesn't do well on things that have very specific shapes, particularly ones humans are good at seeing distortions in. Since the human figure is the ultimate example of that, it's not a method particularly suited to character scaling (although the effect can be interesting, as in David's example).

Trapezoid

Content aware scale is mainly useful for making disturbing surreal gifs.

SMF spam blocked by CleanTalk