java - Scale 2D-Array using Bicubic Interpolation -


i want scale arbitrary double[][] double[][] different dimensions. values of resulting array should calculated based on input array using bicubic interpolation.

i know done in image processing decades now, unable find library or @ least working code snippet works 2d-array rather specific image objects, that's why i'm asking here.

more specific requirements:

as far i've understood, value of point between corners of 3x3-grid can calculated directly using bicubic interpolation, first function need

double interpolate(double[][] grid3by3, double x, double y)` 

where x , y between 0.0 , 1.0

the next step of course ease process 3x3 grid chosen every point automatically , can like

`double[][] interpolate(double[][] input, int newwidth, int newheight)` 

this me new array specified dimensions same borders input array.

where want this:

`double[][] interpolate(double[][] input, int newwidth, int newheight,                         double minx, double miny, double maxx, double maxy)` 

the min , max values define bounding box can subset of initial array not need start or end @ exact index value of input array (e.g. corner can @ (5,3) or (5.25, 3.7), can't cut off input array @ index value). bounding box become extent of new array , values interpolated input array.

oh, , fyi: digital elevation models, please tell me if approach totally wrong in first place ;)

just wanted share how solved problem (or rather, didn't):

for while, tried own bicubic interpolation algorithms started (get inspiration here), , @ point, looked work, , if want decent approximation work numbers, it's fine.

but: if scale image fancy new algorithm, see how crappy results are. unless math behind , know you're doing (and don't, because that's why read this), don't try , code yourself.

and here's workaround: imagej , this:

// works same for: byte, short, int float[] mydata;      // create new image. change 32 16 short or 8 byte imagestack stack = imagestack.create(width, height, 1, 32); stack.setpixels(mydata, 1); imageprocessor processor = new imageplus("", stack).getprocessor(); // crop , scale processor.setroi(x, y, rwidth, rheight); imageprocessor result = processor.crop().resize(newwidth, newheight); // retrieve results float[] myscaleddata = (float[]) result.getpixels(); 

i know, it's not it's intended for, , unfortunately, there no functions 64 bit datatypes, results of high quality , imagej not of weight carry around... still, copy , paste relevant code parts, imagej in public domain.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -