Sunday, June 19, 2016

48. GaussianBlur

A GaussianBlur is also a low-pass filter.


However this time the averaging is based on a 2D Gaussian. It results in better image quality, as compared to BoxBlur but with more computations.


package ex48;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Ex48 extends Application {
    
    @Override
    public void start(Stage stage) {
        VBox root = new VBox(50);
        root.setAlignment(Pos.CENTER);
        
        GaussianBlur gaussBlur1 = new GaussianBlur();
        gaussBlur1.setRadius(5);
        
        Text text1 = new Text("blur1 (5)");
        text1.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text1.setFill(Color.GREEN);
        text1.setEffect(gaussBlur1);
        
        GaussianBlur gaussBlur2 = new GaussianBlur();
        gaussBlur2.setRadius(2);
        
        Text text2 = new Text("blur2 (2)");
        text2.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text2.setFill(Color.GREEN);
        text2.setEffect(gaussBlur2);
        
        root.getChildren().addAll(text1, text2);
        Scene scene = new Scene(root, 500, 200, Color.YELLOW);
        stage.setTitle("Example 48. GaussianBlur");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

This is the output:


No comments:

Post a Comment