resampling 2D-arrays (images), how to ?

resampling 2D-arrays (images), how to ?

Post by Malte Lan » Wed, 01 Oct 1997 04:00:00


I am looking for some pseudo-code or implementation
of a function, that takes a 2D-array (image defined by values
at equidistand points) and resamples the data for another grid
of equidistant points by applying an appropriate filter (or some-
thing else). The two grids will have different unit-lengths.

Any help or pointers are highly appreciated.

Thanks in advance.

Malte Lance.


 
 
 

resampling 2D-arrays (images), how to ?

Post by Stuart Mackinn » Wed, 01 Oct 1997 04:00:00



> I am looking for some pseudo-code or implementation
> of a function, that takes a 2D-array (image defined by values
> at equidistand points) and resamples the data for another grid
> of equidistant points by applying an appropriate filter (or some-
> thing else). The two grids will have different unit-lengths.

> Any help or pointers are highly appreciated.

You could try http://almond.srv.cs.cmu.edu/afs/cs/user/ph/www/heckbert.html
which is Paul Heckbert's web page. On there somewhere is a link along the
lines of: "C code to zoom raster images up or down, with nice filtering"
which you may be able to adapt to do what you want.

> Malte Lance.


Regards,
--

+- Stuart MacKinnon ---------------------------------------------------------+
|  Senior Programmer at eyeOn Software             http://www.eyeonline.com  |


 
 
 

resampling 2D-arrays (images), how to ?

Post by David » Wed, 01 Oct 1997 04:00:00


An algorithm I use for scaling bitmaps to any arbitrary factor goes like
this:

1) Create a blank destination bitmap of size (source_width * scale_factor,
source_height * scale_factor).

2) Loop through every pixel in the destination image.

3) Calculate where that pixel would be in the source image (dest_x /
scale_factor, dest_y / scale_factor) using floating-point math.

4) The result will be a fractional coordinate somewhere between for source
pixels, like this:

A   B
   x
C   D

(it may, by chance, land right on a source pixel, but the math will still
come out OK)

5) Perform a linear interpolation of pixels A & B and C & D horizontally,
like this:

AB = x_delta * (B - A) + A
CD = x_delta * (D - C) + C
(x_delta is the fractional portion of the source X value:  source_x -
INT(source_x))

6) Perform a linear interpolation of AB & CD vertically, like this:

result = y_delta * (CD - AB) + AB

7) The resulting pixel value is assigned to the destination image.

This algorithm provides for a high-quality scaled version of the original
image.  It is easy to implement scale-to-gray with this algorithm also.


 
 
 

resampling 2D-arrays (images), how to ?

Post by Nordi » Fri, 03 Oct 1997 04:00:00



> 5) Perform a linear interpolation of pixels A & B and C & D horizontally,
> like this:

[snip]

Quote:> 6) Perform a linear interpolation of AB & CD vertically, like this:

> 7) The resulting pixel value is assigned to the destination image.

  You're point-sampling; won't work well for image minification (scale < 1).
 Look into "Digital Image Warping" by George Wolberg for a survey of proper
prefilters to be used.
 
 
 

1. resampling 2D-arrays (images), how to ?

I am looking for some pseudo-code or implementation
of a function, that takes a 2D-array (image defined by values
at equidistand points) and resamples the data for another grid
of equidistant points by applying an appropriate filter (or some-
thing else). The two grids will have different unit-lengths.

Any help or pointers are highly appreciated.

Thanks in advance.

Malte Lance.

2. Stitch?

3. Help needed: 2d array-> image conversion

4. Which video card for 24bit anim output?

5. Rotation of images in 2d array around free centre

6. Blind Vigilantes

7. Image scaling (resampling) ?

8. PSP7 - changing image dpi without resampling?

9. Resampling Images

10. Best Image Resampling Scaling plugin ??

11. Image resampling algorithm used by Windows NT GDI

12. Resampling for zoomed display of image API (windows 32bits)