{"id":349,"date":"2008-02-24T04:32:19","date_gmt":"2008-02-24T09:32:19","guid":{"rendered":"http:\/\/www.mccambridge.org\/blog\/2008\/02\/a-gallery-of-ways-not-to-resize-images\/"},"modified":"2022-09-11T00:40:39","modified_gmt":"2022-09-11T00:40:39","slug":"a-gallery-of-ways-not-to-resize-images","status":"publish","type":"post","link":"http:\/\/www.mccambridge.org\/blog\/2008\/02\/a-gallery-of-ways-not-to-resize-images\/","title":{"rendered":"A Gallery of Ways Not to Resize Images"},"content":{"rendered":"
So for CS 559: Computer Graphics<\/a>, 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.<\/p>\n As it turns out, the mathematics behind some of these things that we take for granted in Photoshop or the GIMP<\/a> are actually fairly complex, though I don’t want to get into them now. What I do<\/em> 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:<\/p>\n 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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,22],"tags":[],"_links":{"self":[{"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/posts\/349"}],"collection":[{"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/comments?post=349"}],"version-history":[{"count":1,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":1602,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions\/1602"}],"wp:attachment":[{"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/media?parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/categories?post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mccambridge.org\/blog\/wp-json\/wp\/v2\/tags?post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}How to Screw Up the “Resize” Function, in Pictures<\/h4>\n
\n
\n<\/a><\/li>\n<<\/code> where you meant
<=<\/code> 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):<\/em>
\n<\/a><\/li>\nunsigned char<\/code> instead of an
int<\/code> to store your y coordinate index. (
unsigned char<\/code>‘s can only hold the numbers 0 to 255, whereas
int<\/code>s can hold +\/- 2 billion)<\/em>:
\n<\/a><\/li>\nfloat<\/code> to
unsigned char<\/code> 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<\/code>, you get overflow and the output becomes “2”.)<\/em>
\n<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"