Skip to content

Image resize (upscale and downscale) implementation written in golang

License

Notifications You must be signed in to change notification settings

chran554/imageinterpolation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image interpolation

This is my own implementation of image interpolation. Used for upscale (and downscale) of images.

I have no initial ambitions to make this the fastest or leanest resource consuming algorithm out there. This project and implementations are made to explore techniques and algorithms to support texture interpolation in my raytracing endeavours as I can not use traditional algorithms or libraries on my own proprietary internal image format. (Plus I need to account for texture wrap and flipping on tiling textures.)

License

CC0

It is not a requirement by the license, but if you do improve the code then any feedback or pull request is very appreciated. Sharing is caring.

Dependencies

Nope. No exotic dependencies to mention.

This library applies to the vanilla images as provided by the standard go library image.

TODO

  • Make sure all calculations are made on alpha and not premultiplied color values.

  • Implement sRGB gamma calculation (not plain gamma 2.2)

Testing

No extensive mathematical testing nor unit tests has been done.

Important
WYSIWYG - literally.

Algorithms

Algorithms are created from scratch based on information found at wikipedia.

All algorithms are working in RGB space.

All interpolation calculations are made in linear RGB space. Gamma of 2.2 is assumed for original image.

(Wikipedia is fantastic source of knowledge, if you use it more than 5 times a year consider what it saves you in time and other expenses for dictionaries, courses, and wasted time searching. Give them a contribution to keep it running and open.)

algorithms
Figure 1. Different interpolation algorithms. Illustration by Cmglee at wikipedia CC BY-SA 4.0.
  • Pixel boxing, used for down scaling an image. An image can be reduced by an integer factor in both width and height dimension. As pixels are evenly averaged during reduction the average color information is preserved. A (small) rounding error going from floating point values to integers is introduced upon consecutive reductions.

Results

Upscale

These algorithms can be used for upscaling an image.

Original image
Figure 2. Original image used for upscale examples. (This image is just a large preview. The actual original image is merely the 5x5 pixels.)

Nearest neighbour

Nearest neighbour interpolation
Figure 3. The original image of 5x5 pixels upscaled to 250x250 pixels using nearest neighbour interpolation.

Bilinear

Bilinear interpolation
Figure 4. The original image of 5x5 pixels upscaled to 250x250 pixels using bilinear interpolation.

Bicubic (using Cubic Hermite spline)

Bicubic interpolation
Figure 5. The original image of 5x5 pixels upscaled to 250x250 pixels using bicubic interpolation (using Cubic Hermite spline).

Releases

No releases published

Packages

No packages published

Languages