Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!src.honeywell.com!msi.umn.edu!cs.umn.edu!kksys!com50!dal From: dal@com50.c2s.mn.org (Dale Schumacher) Newsgroups: comp.graphics Subject: Re: Fast Image Scaling Message-ID: <1990Oct29.152500.15450@com50.c2s.mn.org> Date: 29 Oct 90 15:25:00 GMT References: <1990Oct26.011905.16187@morrow.stanford.edu> Organization: Com Squared Systems, Inc. Lines: 54 In article <1990Oct26.011905.16187@morrow.stanford.edu> rick@pangea.Stanford.EDU (Rick Ottolini) writes: >In article dal@syntel.syntel.mn.org (Dale A. Schumacher) writes: >>The following pseudo-code is from a rough draft of a paper I'm preparing >>for inclusion in Graphics Gems '91. It is in the public domain. >> >> >>src_x_size: integer; >>src_y_size: integer; >>source: array[0..src_x_size-1] of array[0..src_y_size-1] of pixel; >>dst_x_size: integer; >>dst_y_size: integer; >>destination: array[0..dst_x_size-1] of array[0..dst_y_size-1] of pixel; >>sx, sy, dx, dy: integer; >> >>begin >> dx <- 0; >> dy <- 0; >> while dy < dst_y_size do >> sy <- ((dy * src_y_size) / dst_y_size); >> while dx < dst_x_size do >> sx <- ((dx * src_x_size) / dst_x_size); >> destination[dx][dy] <- source[sx][sy]; >> endloop; >> endloop; >>end; > >Two problems (at least): First of all, the original requestor was specifically interested in fast and simple methods, and was not terribly concerned with accuracy. I should have known better than to post this pseudo-code without discussing its limitations as I DO discuss in my article. >(1) When shrinking the high freqyency components of an image must be removed >or else aliasing will result. A fast way to do this is to smooth with a >(rectangular) window the degree of compression. I am aware of several more accurate zooming methods, and realize the drawbacks of this one. Compare this algorithm, however, with some other simplistic methods. How often have you seen enlarging limited to integer zoom factors because a "repeat each pixel N times" algorithm is used, or reduction by "skip every Nth pixel". This method at least has the nice properties that it scales up or down with independent scaling along each axis (nice for fixing aspect-ratio problems) from any source size to any destination size and is deceptively simple to implement. I am trying to give people no more excuses for implementing thing like "integer zoom factors only". >(2) Pre-computing each axis of of sx and sy is even faster than above. This is pseudo-code, not source code. The intent here is to make the algorithm clear, not code it for maximum efficiency. I sure hope this algorithm, with all its limitations, is useful to someone.