Scaling

Introduction

Given an image, each pixel of that needs to be scaled along X and Y axis as per given scale factor ( which is a floating-point value != 0.0 ), so that pixels stay on same straight line even after scaling. That’s one of the affine transformation operations that can be preformed on images.

Each pixel of source image to be relocated to a new position in sink image, using following formula.

scale

where Sx & Sy is horizontal & vertical scale factors, respectively

One thing can be observed, resulting pixel location may not be always integer ( depends upon value of scale factors ), which needs us to convert it to some valid integer pixel location in sink image. We’ll go for simple rounding method.

Usage

import in.itzmeanjan.filterit.ImportExportImage;
import in.itzmeanjan.filterit.affine.Scale;

public class Main {

    public static void main(String[] args) {
        Scale scale = new Scale();
        System.out.println(ImportExportImage.exportImage(
                scale.scale("butterfly.jpg", 1.25, 1.25),
                "scaledX1_25Y1_25.jpg"
        ));
    }
}
$ javac -cp ".:in.itzmeanjan.filterit.jar" Main.java
$ java -cp ".:in.itzmeanjan.filterit.jar" Main

Results

Source Scale factor X Scale factor Y Sink
butterfly 1.25 1.25 scaled
butterfly 1.75 1.25 scaled
butterfly 2.0 2.0 scaled

Thanking you :blush: