示例#1
0
 private void calculateGreyValues() {
   int size = image.getPixelCount();
   int gray;
   for (int pos = 0; pos < size; pos++) {
     gray = image.get(pos);
     grayValue[pos] = (byte) (gray / GRAY_SCALE); // quantized for texture analysis
     grayHistogram[gray]++;
   }
   Arrays2.div(grayHistogram, size);
 }
示例#2
0
  private void calculate() {
    calculateGreyValues();

    final int imageWidth = image.getWidth();
    final int imageHeight = image.getHeight();
    final int d = HARALICK_DIST;
    int i, j, pos;

    // image is not empty per default
    for (int y = 0; y < imageHeight; y++) {
      for (int x = 0; x < imageWidth; x++) {
        pos = imageWidth * y + x;

        // horizontal neighbor: 0 degrees
        i = x - d;
        //                j = y;
        if (!(i < 0)) {
          increment(grayValue[pos], grayValue[pos - d]);
        }

        // vertical neighbor: 90 degree
        //                i = x;
        j = y - d;
        if (!(j < 0)) {
          increment(grayValue[pos], grayValue[pos - d * imageWidth]);
        }

        // 45 degree diagonal neigbor
        i = x + d;
        j = y - d;
        if (i < imageWidth && !(j < 0)) {
          increment(grayValue[pos], grayValue[pos + d - d * imageWidth]);
        }

        // 135 vertical neighbor
        i = x - d;
        j = y - d;
        if (!(i < 0) && !(j < 0)) {
          increment(grayValue[pos], grayValue[pos - d - d * imageWidth]);
        }
      }
    }
    meanGrayValue = Arrays2.sum(grayValue);
  }
示例#3
0
  private void process(ColorProcessor ip) {
    double[] feature = new double[binX * binY * binZ];
    int processedPixels = 0;

    ImageProcessor mask = ip.getMask();

    int numpixels = ip.getPixelCount();
    float[] hsbvals = new float[3]; // Conversion buffer
    for (int i = 0; i < numpixels; i++) {
      if (mask == null || mask.get(i) != 0) {
        if (type == TYPE.HSB) {
          feature[getBinForHSB(ip.get(i), hsbvals)]++;
        } else if (type == TYPE.RGB) {
          feature[getBinForRGB(ip.get(i))]++;
        }
        processedPixels++;
      }
    }

    Arrays2.div(feature, processedPixels);
    addData(feature);
  }
示例#4
0
 /**
  * Normalizes the array by the given sum. by dividing each 2nd dimension array componentwise by
  * the sum.
  *
  * @param A
  * @param sum
  */
 private void normalize(double[][] A, double sum) {
   for (int i = 0; i < A.length; i++) {
     Arrays2.div(A[i], sum);
   }
 }
示例#5
0
  private void process(ByteProcessor image) {
    features = new double[14];

    firePropertyChange(new Progress(1, "creating coocurrence matrix"));
    Coocurrence coocurrence = new Coocurrence(image, NUM_GRAY_VALUES, this.haralickDist);
    double[][] cooccurrenceMatrix = coocurrence.getCooccurrenceMatrix();
    double meanGrayValue = coocurrence.getMeanGrayValue();

    firePropertyChange(new Progress(25, "normalizing"));
    normalize(cooccurrenceMatrix, coocurrence.getCooccurenceSums());

    firePropertyChange(new Progress(50, "computing statistics"));
    calculateStatistics(cooccurrenceMatrix);

    firePropertyChange(new Progress(75, "computing features"));

    double[][] p = cooccurrenceMatrix;
    double[][] Q = new double[NUM_GRAY_VALUES][NUM_GRAY_VALUES];
    for (int i = 0; i < NUM_GRAY_VALUES; i++) {
      double sum_j_p_x_minus_y = 0;
      for (int j = 0; j < NUM_GRAY_VALUES; j++) {
        double p_ij = p[i][j];

        sum_j_p_x_minus_y += j * p_x_minus_y[j];

        features[0] += p_ij * p_ij;
        features[2] += i * j * p_ij - mu_x * mu_y;
        features[3] += (i - meanGrayValue) * (i - meanGrayValue) * p_ij;
        features[4] += p_ij / (1 + (i - j) * (i - j));
        features[8] += p_ij * log(p_ij);

        // feature 13
        if (p_ij != 0 && p_x[i] != 0) { // would result in 0
          for (int k = 0; k < NUM_GRAY_VALUES; k++) {
            if (p_y[k] != 0 && p[j][k] != 0) { // would result in NaN
              Q[i][j] += (p_ij * p[j][k]) / (p_x[i] * p_y[k]);
            }
          }
        }
      }

      features[1] += i * i * p_x_minus_y[i];
      features[9] += (i - sum_j_p_x_minus_y) * (i - sum_j_p_x_minus_y) * p_x_minus_y[i];
      features[10] += p_x_minus_y[i] * log(p_x_minus_y[i]);
    }

    // feature 13: Max Correlation Coefficient
    double[] realEigenvaluesOfQ = new Matrix(Q).eig().getRealEigenvalues();
    Arrays2.abs(realEigenvaluesOfQ);
    Arrays.sort(realEigenvaluesOfQ);
    features[13] = Math.sqrt(realEigenvaluesOfQ[realEigenvaluesOfQ.length - 2]);

    features[2] /= Math.sqrt(var_x * var_y);
    features[8] *= -1;
    features[10] *= -1;
    double maxhxhy = Math.max(hx, hy);
    if (Math.signum(maxhxhy) == 0) {
      features[11] = 0;
    } else {
      features[11] = (features[8] - hxy1) / maxhxhy;
    }
    features[12] = Math.sqrt(1 - Math.exp(-2 * (hxy2 - features[8])));

    for (int i = 0; i < 2 * NUM_GRAY_VALUES - 1; i++) {
      features[5] += i * p_x_plus_y[i];
      features[7] += p_x_plus_y[i] * log(p_x_plus_y[i]);

      double sum_j_p_x_plus_y = 0;
      for (int j = 0; j < 2 * NUM_GRAY_VALUES - 1; j++) {
        sum_j_p_x_plus_y += j * p_x_plus_y[j];
      }
      features[6] += (i - sum_j_p_x_plus_y) * (i - sum_j_p_x_plus_y) * p_x_plus_y[i];
    }

    features[7] *= -1;
  }