Example #1
0
 int[] smooth(int[] a, int n) {
   FloatProcessor fp = new FloatProcessor(n, 1);
   for (int i = 0; i < n; i++) fp.putPixelValue(i, 0, a[i]);
   GaussianBlur gb = new GaussianBlur();
   gb.blur1Direction(fp, 2.0, 0.01, true, 0);
   for (int i = 0; i < n; i++) a[i] = (int) Math.round(fp.getPixelValue(i, 0));
   return a;
 }
Example #2
0
 float[] smooth(float[] a, int n) {
   FloatProcessor fp = new FloatProcessor(n, 1);
   for (int i = 0; i < n; i++) fp.setf(i, 0, a[i]);
   GaussianBlur gb = new GaussianBlur();
   gb.blur1Direction(fp, 2.0, 0.01, true, 0);
   for (int i = 0; i < n; i++) a[i] = fp.getf(i, 0);
   return a;
 }
Example #3
0
  void SMLblur1Direction(
      final FloatProcessor ippp,
      final double sigma,
      final double accuracy,
      final boolean xDirection,
      final int extraLines) {

    final float[] pixels = (float[]) ippp.getPixels();
    final int width = ippp.getWidth();
    final int height = ippp.getHeight();
    final int length =
        xDirection ? width : height; // number of points per line (line can be a row or column)
    final int pointInc =
        xDirection ? 1 : width; // increment of the pixels array index to the next poin a line
    final int lineInc =
        xDirection ? width : 1; // increment of the pixels array index to the next line
    final int lineFromA = 0 - extraLines; // the first line to process
    final int lineFrom;
    if (lineFromA < 0) lineFrom = 0;
    else lineFrom = lineFromA;
    final int lineToA = (xDirection ? height : width) + extraLines; // the last line+1 to process
    final int lineTo;
    if (lineToA > (xDirection ? height : width)) lineTo = (xDirection ? height : width);
    else lineTo = lineToA;
    final int writeFrom = 0; // first point of a line that needs to be written
    final int writeTo = xDirection ? width : height;

    final float[][] gaussKernel = lowpassGauss.makeGaussianKernel(sigma, accuracy, length);
    final int kRadius = gaussKernel[0].length; // Gaussian kernel radius after upscaling
    final int readFrom =
        (writeFrom - kRadius < 0)
            ? 0
            : writeFrom - kRadius; // not including broadening by downscale&upscale
    final int readTo = (writeTo + kRadius > length) ? length : writeTo + kRadius;
    final int newLength = length;

    final float[] cache1 =
        new float[newLength]; // holds data before convolution (after downscaling, if any)

    int pixel0 = 0;
    for (int line = lineFrom; line < lineTo; line++, pixel0 += lineInc) {
      int p = pixel0 + readFrom * pointInc;
      for (int i = readFrom; i < readTo; i++, p += pointInc) cache1[i] = pixels[p];
      SMLconvolveLine(
          cache1, pixels, gaussKernel, readFrom, readTo, writeFrom, writeTo, pixel0, pointInc);
    }

    return;
  }