The Spark Between

Thoughts, Projects, Happenings, Ideas
  • Home
  • About
  • SmartBox
  • LiveTrip
  • Calendar
  • Photos

A Gallery of Ways Not to Resize Images

Colin M | February 24, 2008 | 4:32 am

So for CS 559: Computer Graphics, our first project is to implement a program that can do various things to images. For instance, we need to turn color images to gray scale (or part way there), resize them, rotate them, etc.

As it turns out, the mathematics behind some of these things that we take for granted in Photoshop or the GIMP are actually fairly complex, though I don’t want to get into them now. What I do want to show you are several ways that one (say, me) could try to implement a simple “resize” operation and fail, due to tiny little bugs:

How to Screw Up the “Resize” Function, in Pictures

  1. (First off, here’s the original, full size image. Click for a larger view. Each attempt below was to make it 2/3 size.)
    Original image
  2. Use < where you meant <= to define your resampling filter. (Causes the filter not to include certain values that are exactly on the edge, like, say, all the exact integer multiples):
    Less-than vs Less-than-or-equal
  3. Use an unsigned char instead of an int to store your y coordinate index. (unsigned char‘s can only hold the numbers 0 to 255, whereas ints can hold +/- 2 billion):
    Use char instead of int
  4. Cast float to unsigned char after using a filter not guaranteed not to amplify values. This one is pretty subtle, but you can see red & yellow splotches appear on the shirt (e.g., dots on my left shoulder), and my right ear has holes in it. Very annoying. (If the filter amplifies values, then it can output, say “257″ from inputs ranging 0-255. When you try to fit “257″ in an unsigned char, you get overflow and the output becomes “2″.)
    Amplifying Filter + direct cast to char
Categories
Programming, School
Comments rss
Comments rss
Trackback
Trackback

« Electric Sheep Saturday Leisure Activity: Parallel Kingdom Beta Testing »

One Response to “A Gallery of Ways Not to Resize Images”

  1. The Spark Between » Saturday Leisure Activity: Parallel Kingdom Beta Testing says:
    February 24, 2008 at 4:46 am

    [...] between fits of graphics programming today, I had a pretty neat opportunity to beta test a game that some friends of mine are developing [...]

Leave a Reply

Click here to cancel reply.

Calendar

July 2010
S M T W T F S
« Jun «-»  
 123
45678910
11121314151617
18192021222324
25262728293031

Random Quote

A ship in harbor is safe, but that's not what ships are for.
John A. Shedd

Blogroll

  • Angela
  • Ashley
  • Jared
  • Jeni
  • Jon
  • Paul
  • Scott

Archives

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox