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.
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.
-
Make sure you've
in.itzmeanjan.filterit.jar
in current project directory -
Type in following code snippet in to
Main.java
.
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"
));
}
}
- Compile it using following bash command
$ javac -cp ".:in.itzmeanjan.filterit.jar" Main.java
- Run it using bash snippet below
$ java -cp ".:in.itzmeanjan.filterit.jar" Main
- And here's result.
Source | Scale factor X | Scale factor Y | Sink |
---|---|---|---|
1.25 | 1.25 | ||
1.75 | 1.25 | ||
2.0 | 2.0 |
Thanking you 😊