@Override
  public void apply(Mat src, Mat dst) {
    Core.split(src, mChannels);

    final Mat r = mChannels.get(0);
    final Mat g = mChannels.get(1);
    final Mat b = mChannels.get(2);

    Core.min(b, r, b);
    Core.min(b, g, b);

    Core.merge(mChannels, dst);
  }
예제 #2
0
  public static Mat Histogram(Mat im) {

    Mat img = im;

    Mat equ = new Mat();
    img.copyTo(equ);
    // Imgproc.blur(equ, equ, new Size(3, 3));

    Imgproc.cvtColor(equ, equ, Imgproc.COLOR_BGR2YCrCb);
    List<Mat> channels = new ArrayList<Mat>();
    Core.split(equ, channels);
    Imgproc.equalizeHist(channels.get(0), channels.get(0));
    Core.merge(channels, equ);
    Imgproc.cvtColor(equ, equ, Imgproc.COLOR_YCrCb2BGR);

    Mat gray = new Mat();
    Imgproc.cvtColor(equ, gray, Imgproc.COLOR_BGR2GRAY);
    Mat grayOrig = new Mat();
    Imgproc.cvtColor(img, grayOrig, Imgproc.COLOR_BGR2GRAY);
    System.out.println("Histogram work ///");
    return grayOrig;
  }
예제 #3
0
  /**
   * @param inputImg
   * @return Mat
   */
  public static Mat kmeans(Mat inputImg) {

    Mat rgba = inputImg;
    Mat tempMat = inputImg;
    rgba = new Mat(inputImg.cols(), inputImg.rows(), CvType.CV_8UC3);
    inputImg.copyTo(rgba);

    List<Mat> hsv_planes_temp = new ArrayList<Mat>(3);
    Core.split(tempMat, hsv_planes_temp);

    double threshValue1 = PreProcessingOperation.getHistAverage(inputImg, hsv_planes_temp.get(0));
    sample.util.Estimate.setFirstHistAverageValue(threshValue1);
    System.out.println("Defore eqau " + threshValue1);

    System.out.println(
        Estimate.getBlueAverage() + " ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");

    if (threshValue1 > 140) {
      if (Estimate.getBlueAverage() > 110) {
        rgba.convertTo(rgba, -1, 10d * 31 / 100, 0);
        System.out.println("11");
      } else {
        rgba.convertTo(rgba, -1, 10d * 40 / 100, 0);
        System.out.println("12");
      }
    } else if (threshValue1 > 135) {
      rgba.convertTo(rgba, -1, 10d * 32 / 100, 0);
      System.out.println("21");
    } else if (threshValue1 > 125) {
      if (Estimate.getBlueAverage() > 110) {
        rgba.convertTo(rgba, -1, 10d * 30 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 5);
        System.out.println("31");
      } else {
        rgba.convertTo(rgba, -1, 10d * 37 / 100, 0);
        System.out.println("32");
      }
    } else if (threshValue1 > 120) {
      rgba.convertTo(rgba, -1, 10d * 35 / 100, 0);
      System.out.println("41");
    } else if (threshValue1 > 110) {
      if (Estimate.getBlueAverage() > 110) {
        rgba.convertTo(rgba, -1, 10d * 35 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 5);
        System.out.println("51");
      }
    } else if (threshValue1 > 100) {
      if (Estimate.getBlueAverage() > 107) {
        rgba.convertTo(rgba, -1, 10d * 24 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 5);
        System.out.println("61");
      } else if (Estimate.getBlueAverage() > 90) {
        rgba.convertTo(rgba, -1, 10d * 30 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 5);
        System.out.println("62");
      }
    } else if (threshValue1 > 50) {

      if (Estimate.getBlueAverage() > 160) {
        rgba.convertTo(rgba, -1, 10d * 30 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 3);
        System.out.println("81");
      } else if (Estimate.getBlueAverage() > 160) {
        rgba.convertTo(rgba, -1, 10d * 27 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 9);
        System.out.println("82");
      } else if (Estimate.getBlueAverage() > 130) {
        rgba.convertTo(rgba, -1, 10d * 30 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 9);
        System.out.println("83");
      } else if (Estimate.getBlueAverage() > 70) {
        rgba.convertTo(rgba, -1, 10d * 29 / 100, 0);
        rgba = PreProcessing.Dilate(rgba, 9);
        System.out.println("84");
      }
    } else if (threshValue1 > 30) {
      if (Estimate.getBlueAverage() > 190) {
        rgba.convertTo(rgba, -1, 10d * 25 / 100, 0);
        System.out.println("91");
      } else if (Estimate.getBlueAverage() > 160) {
        rgba.convertTo(rgba, -1, 10d * 35 / 100, 0);
        System.out.println("92");
      }
    } else {
      if (Estimate.getBlueAverage() > 240) {
        rgba.convertTo(rgba, -1, 10d * 24 / 100, 0);
        System.out.println("7");
      } else {
        rgba.convertTo(rgba, -1, 10d * 17 / 100, 0);
        System.out.println("7");
      }
    }
    tempMat.release();

    Mat mHSV = new Mat();
    Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGBA2RGB, 3);
    Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGB2HSV, 3);
    List<Mat> hsv_planes = new ArrayList<Mat>(3);
    Core.split(mHSV, hsv_planes);

    Mat channel = hsv_planes.get(0);
    channel = Mat.zeros(mHSV.rows(), mHSV.cols(), CvType.CV_8UC1);
    hsv_planes.set(2, channel);
    Core.merge(hsv_planes, mHSV);

    mHSV.convertTo(mHSV, CvType.CV_8UC1);
    mHSV = Histogram(mHSV);

    /*
    Mat clusteredHSV = new Mat();
    mHSV.convertTo(mHSV, CvType.CV_32FC3);
    TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
    Core.kmeans(mHSV, 1, clusteredHSV, criteria, 20, Core.KMEANS_PP_CENTERS);
    Mat hsvImg = new Mat();
    List<Mat> hsvPlanes = new ArrayList<>();
    Mat thresholdImg = new Mat();
    int thresh_type = Imgproc.THRESH_BINARY_INV;
    hsvImg.create(mHSV.size(), CvType.CV_8U);
    Imgproc.cvtColor(mHSV, hsvImg, Imgproc.COLOR_BGR2HSV);
    Core.split(hsvImg, hsvPlanes);
    Imgproc.threshold(hsvPlanes.get(1), thresholdImg, 0 , 200 , thresh_type);
    double threshValue = PreProcessingOperation.getHistAverage(hsvImg, hsvPlanes.get(0));
    Estimate.setSecondHistAverageValue(threshValue);
    System.out.println("After equa " + Estimate.getSecondHistAverageValue());*/

    Imgproc.threshold(mHSV, mHSV, 0, 150, Imgproc.THRESH_BINARY_INV);
    // mHSV.convertTo(mHSV, CvType.CV_8UC1);
    return mHSV;
  }