コード例 #1
0
ファイル: Utils.java プロジェクト: mkolod/pdfxtk
  public static float gaussian(float x, float mean, float sd) {
    float mu = mean;
    float sigma = sd;

    float k1 = (float) ((float) 1 / (sigma * (Math.sqrt(2 * Math.PI))));
    float k2 = -1 / (2 * (sigma * sigma));

    return (float) (k1 * Math.exp((x - mu) * (x - mu) * k2));
  }
コード例 #2
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 double rodbard(double x) {
   // y = c*((a-x/(x-d))^(1/b)
   // a=3.9, b=.88, c=712, d=44
   double ex;
   if (x == 0.0) ex = 5.0;
   else ex = Math.exp(Math.log(x / 700.0) * 0.88);
   double y = 3.9 - 44.0;
   y = y / (1.0 + ex);
   return y + 44.0;
 }
コード例 #3
0
  public void setXY(double x, double y) {
    // not validated
    // x and y between -1 and 1
    double sigmoidSteepness, sigmoidZero, baseLength;
    double sensitivity =
        1.1; // evaluated with set to 1.1: a sensitivity of 1 means the complete space of the button
             // is used. 2 means only the middle part is used, making it more sensitive and more
             // easy to get to extreme arousal (from a CHI perspective).
    if (!down) {
      p = x * sensitivity;
      d = y * sensitivity;
      baseLength = Math.max(Math.abs(p), Math.abs(d)); // MAX (P, D) base
      // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base

      // now do the mapping to arousal.
      // Arousal is controlled simple by using a Sigmoid function based on length of PD vector
      sigmoidSteepness = 11;
      sigmoidZero = 8;
      a = 2 / (1 + Math.exp(-(sigmoidSteepness * baseLength - sigmoidZero))) - 1;
      a_base = a;
      // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point,
      // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear)
      // sigmoidSteepness=6;
      // sigmoidZero=0.35;
      // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1;

      p = (p > 1 ? 1 : (p < -1 ? -1 : p));
      d = (d > 1 ? 1 : (d < -1 ? -1 : d));
      a = (a > 1 ? 1 : (a < -1 ? -1 : a));

    } else {
      double tmp_p, tmp_d;
      tmp_p = x * sensitivity;
      tmp_d = y * sensitivity;
      baseLength = Math.max(Math.abs(tmp_p), Math.abs(tmp_d)); // MAX (P, D) base
      // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base

      // now do the mapping to arousal.
      // Arousal is controlled simple by using a Sigmoid function based on length of PD vector
      sigmoidSteepness = 11;
      sigmoidZero = 8;
      // a=a_base-(d-tmp_d)+2/(1+Math.exp(-(sigmoidSteepness*baseLength-sigmoidZero)))-1;
      a = tmp_d;
      // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point,
      // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear)
      // sigmoidSteepness=6;
      // sigmoidZero=0.35;
      // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1;

      // p=(p>1?1:(p<-1?-1:p));
      // d=(d>1?1:(d<-1?-1:d));
      a = (a > 1 ? 1 : (a < -1 ? -1 : a));
    }
  }
コード例 #4
0
ファイル: CurvedGaussian.java プロジェクト: Rygbee/CiteSeerX
 public double density(int x, int y) {
   double tmpx, tmpy, tmpxy, det, varx, vary;
   varx = ksx * ksx;
   vary = ksy * ksy;
   det = varx * vary - ksxy * ksxy;
   tmpx = (x - kmx) * (x - kmx);
   tmpy = (y - kmy) * (y - kmy);
   tmpxy = (x - kmx) * (y - kmy);
   return weight
       / Math.sqrt(det)
       / 6.28319
       * Math.exp(-(tmpx * vary + tmpy * varx - 2 * tmpxy * ksxy) / det / 2);
 }
コード例 #5
0
  static {
    g = new float[3][3];
    sum = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        int x = i - 1;
        int y = j - 1;
        g[i][j] = (float) Math.exp(-(x * x + y * y) / (2.0 * 0.8));
        sum += g[i][j];
      }
    }

    sum1 = g[0][0] + g[0][1] + g[0][2] + g[1][0] + g[1][1] + g[1][2];
  }
コード例 #6
0
ファイル: Draw3D.java プロジェクト: jyhong836/draw3d
 /**
  * create a random surface
  *
  * @param obj
  * @param x1:surface x begin
  * @param x2:surface x end
  * @param y1:surface y begin
  * @param y2:surface y end
  * @return: the surface mObject
  */
 private mObject createRandomSurface(mObject obj, int x1, int x2, int y1, int y2) {
   int i = 0, j = 0;
   x1 /= 20;
   x2 /= 20;
   y1 /= 20;
   y2 /= 20;
   mPoint3[][] points = new mPoint3[x2 - x1 + 1][y2 - y1 + 1];
   for (i = y1; i <= y2; i++) {
     for (j = x1; j <= x2; j++) {
       points[j - x1][i - y1] =
           new mPoint3(j * 20, i * 20, (float) (Math.random() * 70 * Math.exp(0 - 0.3 * j)));
     }
   }
   return new mSurface(points, x2 - x1 + 1, y2 - y1 + 1);
 }
コード例 #7
0
 public CellularFilter() {
   results = new Point[3];
   for (int j = 0; j < results.length; j++) results[j] = new Point();
   if (probabilities == null) {
     probabilities = new byte[8192];
     float factorial = 1;
     float total = 0;
     float mean = 2.5f;
     for (int i = 0; i < 10; i++) {
       if (i > 1) factorial *= i;
       float probability = (float) Math.pow(mean, i) * (float) Math.exp(-mean) / factorial;
       int start = (int) (total * 8192);
       total += probability;
       int end = (int) (total * 8192);
       for (int j = start; j < end; j++) probabilities[j] = (byte) i;
     }
   }
 }
コード例 #8
0
  public IntensityFeatureScaleSpacePyramidApp(Class<T> imageType, Class<D> derivType) {
    super(1);
    this.imageType = imageType;

    addAlgorithm(
        0,
        "Hessian Det",
        new WrapperHessianBlobIntensity<T, D>(HessianBlobIntensity.Type.DETERMINANT, derivType));
    addAlgorithm(
        0,
        "Laplacian",
        new WrapperHessianBlobIntensity<T, D>(HessianBlobIntensity.Type.TRACE, derivType));
    addAlgorithm(
        0,
        "Harris",
        new WrapperGradientCornerIntensity<T, D>(
            FactoryIntensityPointAlg.harris(2, 0.4f, false, derivType)));
    addAlgorithm(
        0,
        "Shi Tomasi",
        new WrapperGradientCornerIntensity<T, D>(
            FactoryIntensityPointAlg.shiTomasi(2, false, derivType)));
    addAlgorithm(
        0,
        "FAST 12",
        new WrapperFastCornerIntensity<T, D>(FactoryIntensityPointAlg.fast12(5, 11, imageType)));
    addAlgorithm(0, "KitRos", new WrapperKitRosCornerIntensity<T, D>(derivType));
    addAlgorithm(
        0,
        "Median",
        new WrapperMedianCornerIntensity<T, D>(FactoryBlurFilter.median(imageType, 2), imageType));

    setMainGUI(gui);

    double scales[] = new double[25];
    for (int i = 0; i < scales.length; i++) {
      scales[i] = Math.exp(i * 0.15);
    }
    pyramid = new ScaleSpacePyramid<T>(imageType, scales);

    anyDerivative =
        GImageDerivativeOps.createDerivatives(imageType, FactoryImageGenerator.create(derivType));
  }
コード例 #9
0
ファイル: gaussianGUI.java プロジェクト: AndriansyahYr/kuliah
  private void doDrawing(Graphics g, double std, int sig, int val) {
    double gaus;
    Graphics2D g2d = (Graphics2D) g;
    double Xawal = X_AXIS_FIRST_X_COORD;
    double Yawal = Y_AXIS_SECOND_Y_COORD;
    Point2D.Double point = new Point2D.Double(Xawal, Yawal);
    double xLength = (X_AXIS_SECOND_X_COORD - X_AXIS_FIRST_X_COORD) / xCoordNumbers;
    double yLength = (Y_AXIS_SECOND_Y_COORD - Y_AXIS_FIRST_Y_COORD) / yCoordNumbers;
    if (val == 0) {
      g2d.setColor(Color.blue);
    } else if (val == 1) {
      g2d.setColor(Color.red);
    } else if (val == 2) {
      g2d.setColor(Color.black);
    }
    double tempX = 0.0, tempY = 0.0;
    double i = (double) nilaiAwal[val];
    while (i <= nilaiAkhir[val]) {

      gaus = Math.exp(-((Math.pow((i - sig) / std, 2))));
      // System.out.println(gaus);
      if (gaus > 1.0) {
        gaus = 0.0;
      }
      Xawal = X_AXIS_FIRST_X_COORD + (i * xLength) - 3;
      Yawal = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength);
      if (i == nilaiAwal[val]) {
        tempX = X_AXIS_FIRST_X_COORD + (i * xLength) - 3;
        ;
        tempY = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength);
      }
      g2d.draw(new Line2D.Double(tempX, tempY, Xawal, Yawal));
      tempX = X_AXIS_FIRST_X_COORD + (i * xLength) - 3;
      tempY = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength);
      i = i + 0.1;
    }
    // for(int i=nilaiAwal;i<=xCoordNumbers;i++){
    //     }

  }
コード例 #10
0
ファイル: UnaryOpDlg.java プロジェクト: Sciss/FScape
  /** Translation durchfuehren */
  public void process() {
    int i, j, k;
    int ch, len;
    float f1;
    double d1, d2, d3, d4, d5;
    long progOff, progLen, lo;

    // io
    AudioFile reInF = null;
    AudioFile imInF = null;
    AudioFile reOutF = null;
    AudioFile imOutF = null;
    AudioFileDescr reInStream = null;
    AudioFileDescr imInStream = null;
    AudioFileDescr reOutStream = null;
    AudioFileDescr imOutStream = null;
    FloatFile reFloatF[] = null;
    FloatFile imFloatF[] = null;
    File reTempFile[] = null;
    File imTempFile[] = null;
    int outChanNum;

    float[][] reInBuf; // [ch][i]
    float[][] imInBuf; // [ch][i]
    float[][] reOutBuf = null; // [ch][i]
    float[][] imOutBuf = null; // [ch][i]
    float[] convBuf1, convBuf2;
    boolean complex;

    PathField ggOutput;

    // Synthesize
    Param ampRef = new Param(1.0, Param.ABS_AMP); // transform-Referenz
    float gain; // gain abs amp
    float dryGain, wetGain;
    float inGain;
    float maxAmp = 0.0f;
    Param peakGain;

    int inLength, inOff;
    int pre;
    int post;
    int length;
    int framesRead, framesWritten, outLength;
    boolean polarIn, polarOut;

    // phase unwrapping
    double[] phi;
    int[] wrap;
    double[] carry;

    Param lenRef;

    topLevel:
    try {

      complex = pr.bool[PR_HASIMINPUT] || pr.bool[PR_HASIMOUTPUT];
      polarIn = pr.intg[PR_OPERATOR] == OP_POLAR2RECT;
      polarOut = pr.intg[PR_OPERATOR] == OP_RECT2POLAR;
      if ((polarIn || polarOut) && !complex) throw new IOException(ERR_NOTCOMPLEX);

      // ---- open input ----

      reInF = AudioFile.openAsRead(new File(pr.text[PR_REINPUTFILE]));
      reInStream = reInF.getDescr();
      inLength = (int) reInStream.length;
      reInBuf = new float[reInStream.channels][8192];
      imInBuf = new float[reInStream.channels][8192];

      if (pr.bool[PR_HASIMINPUT]) {
        imInF = AudioFile.openAsRead(new File(pr.text[PR_IMINPUTFILE]));
        imInStream = imInF.getDescr();
        if (imInStream.channels != reInStream.channels) throw new IOException(ERR_COMPLEX);
        inLength = (int) Math.min(inLength, imInStream.length);
      }

      lenRef = new Param(AudioFileDescr.samplesToMillis(reInStream, inLength), Param.ABS_MS);
      d1 =
          AudioFileDescr.millisToSamples(
              reInStream, (Param.transform(pr.para[PR_OFFSET], Param.ABS_MS, lenRef, null).value));
      j = (int) (d1 >= 0.0 ? (d1 + 0.5) : (d1 - 0.5)); // correct rounding for negative values!
      length =
          (int)
              (AudioFileDescr.millisToSamples(
                      reInStream,
                      (Param.transform(pr.para[PR_LENGTH], Param.ABS_MS, lenRef, null)).value)
                  + 0.5);

      // System.err.println( "offset = "+j );

      if (j >= 0) {
        inOff = Math.min(j, inLength);
        if (!pr.bool[PR_REVERSE]) {
          reInF.seekFrame(inOff);
          if (pr.bool[PR_HASIMINPUT]) {
            imInF.seekFrame(inOff);
          }
        }
        inLength -= inOff;
        pre = 0;
      } else {
        inOff = 0;
        pre = Math.min(-j, length);
      }
      inLength = Math.min(inLength, length - pre);
      post = length - pre - inLength;

      if (pr.bool[PR_REVERSE]) {
        i = pre;
        pre = post;
        post = i;
        inOff += inLength;
      }

      // .... check running ....
      if (!threadRunning) break topLevel;

      // for( op = 0; op < 2; op++ ) {
      // 	System.out.println( op +": pre "+pre[op]+" / len "+inLength[op]+" / post "+post[op] );
      // }
      // System.out.println( "tot "+length[0]);

      outLength = length;
      outChanNum = reInStream.channels;

      // ---- open output ----

      ggOutput = (PathField) gui.getItemObj(GG_REOUTPUTFILE);
      if (ggOutput == null) throw new IOException(ERR_MISSINGPROP);
      reOutStream = new AudioFileDescr(reInStream);
      ggOutput.fillStream(reOutStream);
      reOutStream.channels = outChanNum;
      // well, more sophisticated code would
      // move and truncate the markers...
      if ((pre == 0) /* && (post == 0) */) {
        reInF.readMarkers();
        reOutStream.setProperty(
            AudioFileDescr.KEY_MARKERS, reInStream.getProperty(AudioFileDescr.KEY_MARKERS));
      }
      reOutF = AudioFile.openAsWrite(reOutStream);
      reOutBuf = new float[outChanNum][8192];
      imOutBuf = new float[outChanNum][8192];

      if (pr.bool[PR_HASIMOUTPUT]) {
        imOutStream = new AudioFileDescr(reInStream);
        ggOutput.fillStream(imOutStream);
        imOutStream.channels = outChanNum;
        imOutStream.file = new File(pr.text[PR_IMOUTPUTFILE]);
        imOutF = AudioFile.openAsWrite(imOutStream);
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- Further inits ----

      phi = new double[outChanNum];
      wrap = new int[outChanNum];
      carry = new double[outChanNum];
      for (ch = 0; ch < outChanNum; ch++) {
        phi[ch] = 0.0;
        wrap[ch] = 0;
        carry[ch] = Double.NEGATIVE_INFINITY;
      }

      progOff = 0; // read, transform, write
      progLen = (long) outLength * 3;

      wetGain = (float) (Param.transform(pr.para[PR_WETMIX], Param.ABS_AMP, ampRef, null)).value;
      dryGain = (float) (Param.transform(pr.para[PR_DRYMIX], Param.ABS_AMP, ampRef, null)).value;
      if (pr.bool[PR_DRYINVERT]) {
        dryGain = -dryGain;
      }
      inGain = (float) (Param.transform(pr.para[PR_INPUTGAIN], Param.ABS_AMP, ampRef, null)).value;
      if (pr.bool[PR_INVERT]) {
        inGain = -inGain;
      }

      // normalization requires temp files
      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        reTempFile = new File[outChanNum];
        reFloatF = new FloatFile[outChanNum];
        for (ch = 0;
            ch < outChanNum;
            ch++) { // first zero them because an exception might be thrown
          reTempFile[ch] = null;
          reFloatF[ch] = null;
        }
        for (ch = 0; ch < outChanNum; ch++) {
          reTempFile[ch] = IOUtil.createTempFile();
          reFloatF[ch] = new FloatFile(reTempFile[ch], GenericFile.MODE_OUTPUT);
        }
        if (pr.bool[PR_HASIMOUTPUT]) {
          imTempFile = new File[outChanNum];
          imFloatF = new FloatFile[outChanNum];
          for (ch = 0;
              ch < outChanNum;
              ch++) { // first zero them because an exception might be thrown
            imTempFile[ch] = null;
            imFloatF[ch] = null;
          }
          for (ch = 0; ch < outChanNum; ch++) {
            imTempFile[ch] = IOUtil.createTempFile();
            imFloatF[ch] = new FloatFile(imTempFile[ch], GenericFile.MODE_OUTPUT);
          }
        }
        progLen += outLength;
      } else {
        gain = (float) (Param.transform(pr.para[PR_GAIN], Param.ABS_AMP, ampRef, null)).value;
        wetGain *= gain;
        dryGain *= gain;
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ----==================== the real stuff ====================----

      framesRead = 0;
      framesWritten = 0;

      while (threadRunning && (framesWritten < outLength)) {
        // ---- choose chunk len ----
        len = Math.min(8192, outLength - framesWritten);
        if (pre > 0) {
          len = Math.min(len, pre);
        } else if (inLength > 0) {
          len = Math.min(len, inLength);
        } else {
          len = Math.min(len, post);
        }

        // ---- read input chunks ----
        if (pre > 0) {
          Util.clear(reInBuf);
          if (complex) {
            Util.clear(imInBuf);
          }
          pre -= len;
        } else if (inLength > 0) {
          if (pr.bool[PR_REVERSE]) { // ---- read reversed ----
            reInF.seekFrame(inOff - framesRead - len);
            reInF.readFrames(reInBuf, 0, len);
            for (ch = 0; ch < reInStream.channels; ch++) {
              convBuf1 = reInBuf[ch];
              for (i = 0, j = len - 1; i < j; i++, j--) {
                f1 = convBuf1[j];
                convBuf1[j] = convBuf1[i];
                convBuf1[i] = f1;
              }
            }
            if (pr.bool[PR_HASIMINPUT]) {
              imInF.seekFrame(inOff - framesRead - len);
              imInF.readFrames(imInBuf, 0, len);
              for (ch = 0; ch < imInStream.channels; ch++) {
                convBuf1 = imInBuf[ch];
                for (i = 0, j = len - 1; i < j; i++, j--) {
                  f1 = convBuf1[j];
                  convBuf1[j] = convBuf1[i];
                  convBuf1[i] = f1;
                }
              }
            } else if (complex) {
              Util.clear(imInBuf);
            }
          } else { // ---- read normal ----
            reInF.readFrames(reInBuf, 0, len);
            if (pr.bool[PR_HASIMINPUT]) {
              imInF.readFrames(imInBuf, 0, len);
            } else if (complex) {
              Util.clear(imInBuf);
            }
          }
          inLength -= len;
          framesRead += len;
        } else {
          Util.clear(reInBuf);
          if (complex) {
            Util.clear(imInBuf);
          }
          post -= len;
        }
        progOff += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
        // .... check running ....
        if (!threadRunning) break topLevel;

        // ---- save dry signal ----
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = reOutBuf[ch];
          for (i = 0; i < len; i++) {
            convBuf2[i] = convBuf1[i] * dryGain;
          }
          if (complex) {
            convBuf1 = imInBuf[ch];
            convBuf2 = imOutBuf[ch];
            for (i = 0; i < len; i++) {
              convBuf2[i] = convBuf1[i] * dryGain;
            }
          }
        }

        // ---- rectify + apply input gain ----
        for (ch = 0; ch < reInStream.channels; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = imInBuf[ch];
          // ---- rectify ----
          if (pr.bool[PR_RECTIFY]) {
            if (complex) {
              if (polarIn) {
                for (i = 0; i < len; i++) {
                  convBuf2[i] = 0.0f;
                }
              } else {
                for (i = 0; i < len; i++) {
                  d1 = convBuf1[i];
                  d2 = convBuf2[i];
                  convBuf1[i] = (float) Math.sqrt(d1 * d1 + d2 * d2);
                  convBuf2[i] = 0.0f;
                }
              }
            } else {
              for (i = 0; i < len; i++) {
                convBuf1[i] = Math.abs(convBuf1[i]);
              }
            }
          }
          // ---- apply input gain ----
          Util.mult(convBuf1, 0, len, inGain);
          if (complex & !polarIn) {
            Util.mult(convBuf2, 0, len, inGain);
          }
        }

        // ---- heart of the dragon ----
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = imInBuf[ch];

          switch (pr.intg[PR_OPERATOR]) {
            case OP_NONE: // ================ None ================
              for (i = 0; i < len; i++) {
                reOutBuf[ch][i] += wetGain * convBuf1[i];
              }
              if (complex) {
                for (i = 0; i < len; i++) {
                  imOutBuf[ch][i] += wetGain * convBuf2[i];
                }
              }
              break;

            case OP_SIN: // ================ Cosinus ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf1[i] * Math.PI);
                  imOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf2[i] * Math.PI);
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf1[i] * Math.PI);
                }
              }
              break;

            case OP_SQR: // ================ Square ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] +=
                      wetGain * (convBuf1[i] * convBuf1[i] - convBuf2[i] * convBuf2[i]);
                  imOutBuf[ch][i] -= wetGain * (convBuf1[i] * convBuf2[i] * 2);
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (convBuf1[i] * convBuf1[i]);
                }
              }
              break;

            case OP_SQRT: // ================ Square root ================
              if (complex) {
                d3 = phi[ch];
                k = wrap[ch];
                d4 = k * Constants.PI2;
                for (i = 0; i < len; i++) {
                  d1 =
                      wetGain
                          * Math.pow(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i], 0.25);
                  d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                  if (d2 - d3 > Math.PI) {
                    k--;
                    d4 = k * Constants.PI2;
                  } else if (d3 - d2 > Math.PI) {
                    k++;
                    d4 = k * Constants.PI2;
                  }
                  d2 += d4;
                  d3 = d2;
                  d2 /= 2;
                  reOutBuf[ch][i] += (float) (d1 * Math.cos(d2));
                  imOutBuf[ch][i] += (float) (d1 * Math.sin(d2));
                }
                phi[ch] = d3;
                wrap[ch] = k;

              } else {
                for (i = 0; i < len; i++) {
                  f1 = convBuf1[i];
                  if (f1 > 0) {
                    reOutBuf[ch][i] += wetGain * (float) Math.sqrt(f1);
                  } // else undefiniert
                }
              }
              break;

            case OP_RECT2POLARW: // ================ Rect->Polar (wrapped) ================
              for (i = 0; i < len; i++) {
                d1 = wetGain * Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                reOutBuf[ch][i] += (float) d1;
                imOutBuf[ch][i] += (float) d2;
              }
              break;

            case OP_RECT2POLAR: // ================ Rect->Polar ================
              d3 = phi[ch];
              k = wrap[ch];
              d4 = k * Constants.PI2;
              for (i = 0; i < len; i++) {
                d1 = wetGain * Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                if (d2 - d3 > Math.PI) {
                  k--;
                  d4 = k * Constants.PI2;
                } else if (d3 - d2 > Math.PI) {
                  k++;
                  d4 = k * Constants.PI2;
                }
                d2 += d4;
                reOutBuf[ch][i] += (float) d1;
                imOutBuf[ch][i] += (float) d2;
                d3 = d2;
              }
              phi[ch] = d3;
              wrap[ch] = k;
              break;

            case OP_POLAR2RECT: // ================ Polar->Rect ================
              for (i = 0; i < len; i++) {
                f1 = wetGain * convBuf1[i];
                reOutBuf[ch][i] += f1 * (float) Math.cos(convBuf2[i]);
                imOutBuf[ch][i] += f1 * (float) Math.sin(convBuf2[i]);
              }
              break;

            case OP_LOG: // ================ Log ================
              if (complex) {
                d3 = phi[ch];
                k = wrap[ch];
                d4 = k * Constants.PI2;
                d5 = carry[ch];
                for (i = 0; i < len; i++) {
                  d1 = Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                  d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                  if (d2 - d3 > Math.PI) {
                    k--;
                    d4 = k * Constants.PI2;
                  } else if (d3 - d2 > Math.PI) {
                    k++;
                    d4 = k * Constants.PI2;
                  }
                  if (d1 > 0.0) {
                    d5 = Math.log(d1);
                  }
                  d2 += d4;
                  reOutBuf[ch][i] += (float) d5;
                  imOutBuf[ch][i] += (float) d2;
                  d3 = d2;
                }
                phi[ch] = d3;
                wrap[ch] = k;
                carry[ch] = d5;

              } else {
                for (i = 0; i < len; i++) {
                  f1 = convBuf1[i];
                  if (f1 > 0) {
                    reOutBuf[ch][i] += wetGain * (float) Math.log(f1);
                  } // else undefiniert
                }
              }
              break;

            case OP_EXP: // ================ Exp ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  d1 = wetGain * Math.exp(convBuf1[i]);
                  reOutBuf[ch][i] += (float) (d1 * Math.cos(convBuf2[i]));
                  imOutBuf[ch][i] += (float) (d1 * Math.sin(convBuf2[i]));
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.exp(convBuf1[i]);
                }
              }
              break;

            case OP_NOT: // ================ NOT ================
              for (i = 0; i < len; i++) {
                lo = ~((long) (convBuf1[i] * 2147483647.0));
                reOutBuf[ch][i] += wetGain * (float) ((lo & 0xFFFFFFFFL) / 2147483647.0);
              }
              if (complex) {
                for (i = 0; i < len; i++) {
                  lo = ~((long) (convBuf2[i] * 2147483647.0));
                  imOutBuf[ch][i] += wetGain * (float) ((lo & 0xFFFFFFFFL) / 2147483647.0);
                }
              }
              break;
          }
        } // for outChan
        progOff += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
        // .... check running ....
        if (!threadRunning) break topLevel;

        // ---- write output chunk ----
        if (reFloatF != null) {
          for (ch = 0; ch < outChanNum; ch++) {
            reFloatF[ch].writeFloats(reOutBuf[ch], 0, len);
            if (pr.bool[PR_HASIMOUTPUT]) {
              imFloatF[ch].writeFloats(imOutBuf[ch], 0, len);
            }
          }
        } else {
          reOutF.writeFrames(reOutBuf, 0, len);
          if (pr.bool[PR_HASIMOUTPUT]) {
            imOutF.writeFrames(imOutBuf, 0, len);
          }
        }
        // check max amp
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reOutBuf[ch];
          for (i = 0; i < len; i++) {
            f1 = Math.abs(convBuf1[i]);
            if (f1 > maxAmp) {
              maxAmp = f1;
            }
          }
          if (pr.bool[PR_HASIMOUTPUT]) {
            convBuf1 = imOutBuf[ch];
            for (i = 0; i < len; i++) {
              f1 = Math.abs(convBuf1[i]);
              if (f1 > maxAmp) {
                maxAmp = f1;
              }
            }
          }
        }

        progOff += len;
        framesWritten += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
      } // while not framesWritten

      // ----==================== normalize output ====================----

      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        peakGain = new Param(maxAmp, Param.ABS_AMP);
        gain =
            (float)
                (Param.transform(
                        pr.para[PR_GAIN],
                        Param.ABS_AMP,
                        new Param(1.0 / peakGain.value, peakGain.unit),
                        null))
                    .value;
        f1 = pr.bool[PR_HASIMOUTPUT] ? ((1.0f + getProgression()) / 2) : 1.0f;
        normalizeAudioFile(reFloatF, reOutF, reOutBuf, gain, f1);
        if (pr.bool[PR_HASIMOUTPUT]) {
          normalizeAudioFile(imFloatF, imOutF, imOutBuf, gain, 1.0f);
        }
        maxAmp *= gain;

        for (ch = 0; ch < outChanNum; ch++) {
          reFloatF[ch].cleanUp();
          reFloatF[ch] = null;
          reTempFile[ch].delete();
          reTempFile[ch] = null;
          if (pr.bool[PR_HASIMOUTPUT]) {
            imFloatF[ch].cleanUp();
            imFloatF[ch] = null;
            imTempFile[ch].delete();
            imTempFile[ch] = null;
          }
        }
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- Finish ----

      reOutF.close();
      reOutF = null;
      reOutStream = null;
      if (imOutF != null) {
        imOutF.close();
        imOutF = null;
        imOutStream = null;
      }
      reInF.close();
      reInF = null;
      reInStream = null;
      if (pr.bool[PR_HASIMINPUT]) {
        imInF.close();
        imInF = null;
        imInStream = null;
      }
      reOutBuf = null;
      imOutBuf = null;
      reInBuf = null;
      imInBuf = null;

      // inform about clipping/ low level
      handleClipping(maxAmp);
    } catch (IOException e1) {
      setError(e1);
    } catch (OutOfMemoryError e2) {
      reOutBuf = null;
      imOutBuf = null;
      reInBuf = null;
      imInBuf = null;
      convBuf1 = null;
      convBuf2 = null;
      System.gc();

      setError(new Exception(ERR_MEMORY));
    }

    // ---- cleanup (topLevel) ----
    convBuf1 = null;
    convBuf2 = null;

    if (reInF != null) {
      reInF.cleanUp();
      reInF = null;
    }
    if (imInF != null) {
      imInF.cleanUp();
      imInF = null;
    }
    if (reOutF != null) {
      reOutF.cleanUp();
      reOutF = null;
    }
    if (imOutF != null) {
      imOutF.cleanUp();
      imOutF = null;
    }
    if (reFloatF != null) {
      for (ch = 0; ch < reFloatF.length; ch++) {
        if (reFloatF[ch] != null) {
          reFloatF[ch].cleanUp();
          reFloatF[ch] = null;
        }
        if (reTempFile[ch] != null) {
          reTempFile[ch].delete();
          reTempFile[ch] = null;
        }
      }
    }
    if (imFloatF != null) {
      for (ch = 0; ch < imFloatF.length; ch++) {
        if (imFloatF[ch] != null) {
          imFloatF[ch].cleanUp();
          imFloatF[ch] = null;
        }
        if (imTempFile[ch] != null) {
          imTempFile[ch].delete();
          imTempFile[ch] = null;
        }
      }
    }
  } // process()
コード例 #11
0
 public double evaluate_1(double x) {
   return (2 * x / x * x + 1)
       - 0.4 * Math.exp(0.4 * x) * Math.cos(Math.PI * x)
       + Math.PI * Math.exp(0.4 * x) * Math.sin(Math.PI * x);
 }
コード例 #12
0
 public double evaluate(double x) {
   return Math.log(x * x + 1) - Math.exp(0.4 * x) * Math.cos(Math.PI * x);
 }
コード例 #13
0
ファイル: Axis.java プロジェクト: christinapanto/project
 public static double exp10(double val) {
   return Math.exp(val / LOG10SCALE);
 }
コード例 #14
0
ファイル: BlurUtils.java プロジェクト: codewizard0/Trinity
  /**
   * Applies a gaussian blur filter to the given image. Apart from the filter radius, you can also
   * specify an alpha factor which will be multiplied with the filter's result. Also, you can
   * specify whether the blurred image should be rendered into a newly created BufferedImage
   * instance or into the original image. If you request a new image instance, the result will be
   * larger than the original one as a (2*filterradius) pixel wide padding will be applied.
   *
   * @param image the image to be blurred.
   * @param filterRadius the radius of the gaussian filter to apply. The corresponding kernel will
   *     be sized 2 * filterRadius + 1;
   * @param alphaFactor a factor which will be multiplied with the filtered image. You can use this
   *     parameter to weaken or strengthen the colors in the blurred image.
   * @param useOriginalImageAsDestination Determines whether the blur result should be rendered into
   *     the original image or into a new image instance. If you choose to create a new image
   *     instance, the result will be larger than the original image to provide the required padding
   *     for the blur effect.
   * @return An image instance containing a blurred version of the given image.
   */
  public static BufferedImage applyGaussianBlur(
      final BufferedImage image,
      final int filterRadius,
      final float alphaFactor,
      final boolean useOriginalImageAsDestination) {
    if (filterRadius < 1) {
      throw new IllegalArgumentException(
          "Illegal filter radius: expected to be >= 1, was " + filterRadius);
    }

    float[] kernel = new float[2 * filterRadius + 1];

    final float sigma = filterRadius / 3f;
    final float alpha = 2f * sigma * sigma;
    final float rootAlphaPI = (float) Math.sqrt(alpha * Math.PI);
    float sum = 0;
    for (int i = -0; i < kernel.length; i++) {
      final int d = -((i - filterRadius) * (i - filterRadius));
      kernel[i] = (float) (Math.exp(d / alpha) / rootAlphaPI);
      sum += kernel[i];
    }

    for (int i = 0; i < kernel.length; i++) {
      kernel[i] /= sum;
      kernel[i] *= alphaFactor;
    }

    final Kernel horizontalKernel = new Kernel(kernel.length, 1, kernel);
    final Kernel verticalKernel = new Kernel(1, kernel.length, kernel);

    synchronized (BlurUtils.class) {
      final int blurredWidth =
          useOriginalImageAsDestination ? image.getWidth() : image.getWidth() + 4 * filterRadius;
      final int blurredHeight =
          useOriginalImageAsDestination ? image.getHeight() : image.getHeight() + 4 * filterRadius;

      final BufferedImage img0 = ensureBuffer0Capacity(blurredWidth, blurredHeight);
      final Graphics2D graphics0 = img0.createGraphics();
      graphics0.drawImage(
          image,
          null,
          useOriginalImageAsDestination ? 0 : 2 * filterRadius,
          useOriginalImageAsDestination ? 0 : 2 * filterRadius);
      graphics0.dispose();

      final BufferedImage img1 = ensureBuffer1Capacity(blurredWidth, blurredHeight);
      final Graphics2D graphics1 = img1.createGraphics();
      graphics1.drawImage(
          img0, new ConvolveOp(horizontalKernel, ConvolveOp.EDGE_NO_OP, null), 0, 0);
      graphics1.dispose();

      BufferedImage destination =
          useOriginalImageAsDestination
              ? image
              : new BufferedImage(blurredWidth, blurredHeight, BufferedImage.TYPE_INT_ARGB);
      final Graphics2D destGraphics = destination.createGraphics();
      destGraphics.drawImage(
          img1, new ConvolveOp(verticalKernel, ConvolveOp.EDGE_NO_OP, null), 0, 0);
      destGraphics.dispose();

      return destination;
    }
  }