MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / resampleArray

Method resampleArray

ij/src/main/java/ij/util/Tools.java:335–363  ·  view source on GitHub ↗

Returns an array linearly resampled to a different length.

(double[] y1, int len2)

Source from the content-addressed store, hash-verified

333
334 /** Returns an array linearly resampled to a different length. */
335 public static double[] resampleArray(double[] y1, int len2) {
336 int len1 = y1.length;
337 double factor = (double)(len2-1)/(len1-1);
338 double[] y2 = new double[len2];
339 if(len1 == 0){
340 return y2;
341 }
342 if(len1 == 1){
343 for (int jj=0; jj<len2; jj++)
344 y2[jj] = y1[0];
345 return(y2);
346 }
347 double[] f1 = new double[len1];//fractional positions
348 double[] f2 = new double[len2];
349 for (int jj=0; jj<len1; jj++)
350 f1[jj] = jj*factor;
351 for (int jj=0; jj<len2; jj++)
352 f2[jj] = jj/factor;
353 for (int jj=0; jj<len2-1; jj++) {
354 double pos = f2[jj];
355 int leftPos = (int)Math.floor(pos);
356 int rightPos = (int)Math.floor(pos)+1;
357 double fraction = pos-Math.floor(pos);
358 double value = y1[leftPos] + fraction*(y1[rightPos]-y1[leftPos]);
359 y2[jj] = value;
360 }
361 y2[len2-1] = y1[len1-1];
362 return y2;
363 }
364
365 /** Opens a text file in ij.jar as a String (example path: "/macros/Circle_Tool.txt"). */
366 public static String openFromIJJarAsString(String path) {

Callers 1

resampleArrayMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected