liveBook · Manning

Interpolation

As explained in Learn Go with Pocket-Sized Projects

Pixel interpolation estimates output pixel colors when an image is resized to a different resolution.

Pixel interpolation estimates output pixel colors when an image is resized. In Go, image/draw does not scale images, so resizing uses golang.org/x/image/draw and its Scaler interface. section 9.6.2

Choose a scaling implementation according to the desired image appearance:

  • NearestNeighbor preserves pixel edges without blurring, making it suitable for maze pixels. section 9.6.2
  • CatmullRom and ApproxBiLinear are alternative implementations of the Scaler interface. section 9.6.2

Scaling a maze frame

Create a 500-pixel-wide paletted frame whose height preserves the input ratio, then scale the maze into it: draw.NearestNeighbor.Scale(frame, frame.Rect, maze, maze.Bounds(), draw.Over, nil). section 9.6.2

draw.NearestNeighbor.Scale(frame, frame.Rect, s.maze, s.maze.Bounds(), 
draw.Over, nil)

Inspect the complete scaler call used to resize the current maze image into the animation frame. section 9.6.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains package selection, scaler implementations, and a concrete scaling call, but not interpolation algorithms internally.
Examples
Uses a 500-pixel-wide maze frame and a NearestNeighbor.Scale call to create animation frames.
What it assumes
Assumes an input image and output frame rectangle, then teaches the required Go scaling package and implementation choice.
What you can do after
Apply it via golang.org/x/image/draw to resize an image into a target rectangle without blurring pixel edges.
How it connects
Connects image resizing with GIF animation, paletted images, image/draw, and the Scaler interface.

Also explained in

Compare how 9 books explain interpolation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.