Example – box and Gaussian blurs in Myriad.

Source code:


/*
 * Copyright (c) 2016 Emphysic LLC.  All rights reserved.
 */

package com.emphysic.myriad.core.examples;

import com.emphysic.myriad.core.data.io.Dataset;
import com.emphysic.myriad.core.data.ops.BoxBlur;
import com.emphysic.myriad.core.data.ops.GaussianBlur;
import com.emphysic.myriad.core.data.util.FileSniffer;

import java.io.File;

/**
 * Demonstrates box and Gaussian blur
 * Created by ccoughlin on 9/9/16.
 */
public class Blur {

    public static void main(String[] args) {
        Dataset input;
        if (args == null || args.length == 0) {
            System.out.println("Using default input data");
            input = getDefaultDataset();
        } else {
            System.out.print("Attempting to read " + args[0] + "...");
            try {
                input = FileSniffer.read(new File(args[0]), true);
            } catch (Exception e) {
                System.out.println("failed! Using default data");
                input = getDefaultDataset();
            }
        }
        System.out.println("Input data " + input.getWidth() + "x" + input.getHeight() + ":");
        input.prettyPrint();
        System.out.println();
        System.out.println("Box blur radius 2:");
        BoxBlur bb = new BoxBlur(2);
        bb.run(input).prettyPrint();
        System.out.println();
        System.out.println("Gaussian blur radius 2:");
        GaussianBlur gb = new GaussianBlur(2);
        gb.run(input).prettyPrint();
        System.out.println();
    }

    /**
     * Returns a default Dataset for the demo
     * @return Dataset
     */
    private static Dataset getDefaultDataset() {
        return new Dataset(demoData, 5, 5);
    }

    /**
     * Default input data
     */
    private static double[] demoData = {
            0.0,  0.0,  0.0,  0.0, 0.0,
            0.0, 50.0, 50.0, 50.0, 0.0,
            0.0, 50.0, 50.0, 50.0, 0.0,
            0.0, 50.0, 50.0, 50.0, 0.0,
            0.0,  0.0,  0.0,  0.0, 0.0
    };
}