Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. public static void zadanie3_9() {
  2. String sciezka = "E:/NETBEANS WORKSPACE/IZA3.jpg";
  3. Mat zdjecie = imread(sciezka);
  4.  
  5. MatOfFloat ranges = new MatOfFloat(0f, 256f);
  6. Mat hist1 = new Mat();
  7. Mat hist2 = new Mat();
  8. Mat hist3 = new Mat();
  9.  
  10. int rozmiar = 100;
  11. MatOfInt histSize = new MatOfInt(rozmiar);
  12.  
  13. Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(0), new Mat(), hist1, histSize, ranges);
  14. Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(1), new Mat(), hist2, histSize, ranges);
  15. Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(2), new Mat(), hist3, histSize, ranges);
  16.  
  17.  
  18. int histW = (int) zdjecie.size().width, histH = (int) zdjecie.size().height;
  19. int binW = (int)Math.round((double) histW / rozmiar);
  20. Mat histImage = new Mat( histH, histW, CvType.CV_8UC3, new Scalar( 0,0,0) );
  21.  
  22. Core.normalize(hist1, hist1, 0, histImage.rows(), Core.NORM_MINMAX); //normalizacja
  23. Core.normalize(hist2, hist2, 0, histImage.rows(), Core.NORM_MINMAX);
  24. Core.normalize(hist3, hist3, 0, histImage.rows(), Core.NORM_MINMAX);
  25.  
  26. float[] hist1Data = new float[(int) (hist1.total() * hist1.channels())];
  27. hist1.get(0, 0, hist1Data);
  28. float[] hist2Data = new float[(int) (hist2.total() * hist2.channels())];
  29. hist2.get(0, 0, hist2Data);
  30. float[] hist3Data = new float[(int) (hist3.total() * hist3.channels())];
  31. hist3.get(0, 0, hist3Data);
  32. for( int i = 1; i < rozmiar; i++ ) {
  33. Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist1Data[i - 1])),
  34. new Point(binW * (i), histH - Math.round(hist1Data[i])), new Scalar(255, 0, 0), 2);
  35. Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist2Data[i - 1])),
  36. new Point(binW * (i), histH - Math.round(hist2Data[i])), new Scalar(0, 255, 0), 2);
  37. Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist3Data[i - 1])),
  38. new Point(binW * (i), histH - Math.round(hist3Data[i])), new Scalar(0, 0, 255), 2);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement