I feel like bicubic interpolation should result in images like:
http://en.wikipedia.org/wiki/Bicubic_interpolation

But, here I'm getting something different:

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import
org.apache.commons.math3.analysis.interpolation.BicubicSplineInterpolatingFunction;
import
org.apache.commons.math3.analysis.interpolation.BicubicSplineInterpolator;

public class Draw {

    static final int STEP = 128;

    public static void main(String[] args) throws IOException {

        final int width = 1024;
        final int height = 512;
        final int totalHt = height + 64;

        // Constructs a BufferedImage of one of the predefined image types.
        final BufferedImage bufferedImage = new BufferedImage(width,
totalHt, BufferedImage.TYPE_INT_RGB);

        // Create a graphics which can be used to draw into the buffered
image
        final Graphics2D g2d = bufferedImage.createGraphics();

        final Random rand = new Random(123);
        final double vx[][] = new double[width / STEP][height / STEP];
        for (int i = 0; i < width / STEP; i++) {
            for (int j = 0; j < height / STEP; j++) {
                final double val = 2 * rand.nextDouble() - 1;
                vx[i][j] = val;
            }
        }
        final double x[] = new double[width / STEP];
        for (int i = 0; i < width / STEP; i++) {
            x[i] = i * STEP;
        }
        final double y[] = new double[height / STEP];
        for (int j = 0; j < height / STEP; j++) {
            y[j] = j * STEP;
        }

        //(1 - yfrac) * [(1 - xfrac)*s00 + xfrac*s01] +
        //yfrac * [(1 - xfrac)*s10 + xfrac*s11]
        final BicubicSplineInterpolatingFunction fun = new
BicubicSplineInterpolator().interpolate(x, y, vx);
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                if (fun.isValidPoint(i, j)) {
                    final float val = (float) fun.value(i, j);
                    final float bx = (float) Math.abs(val);
                    final float hue = val > 0 ? 0.666f : 1;
                    final Color myRGBColor = Color.getHSBColor(hue, bx, 1f);
                    g2d.setColor(myRGBColor);
                    g2d.fillRect(i, j, 1, 1);
                }
            }
        }


        // Disposes of this graphics context and releases any system
resources that it is using.
        g2d.dispose();

        // Save as JPEG
        final File file = new File(System.getProperty("user.home")
+"/myimage.jpg");
        ImageIO.write(bufferedImage, "jpg", file);

    }

}

Reply via email to