Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void zadanie3_9() {
- String sciezka = "E:/NETBEANS WORKSPACE/IZA3.jpg";
- Mat zdjecie = imread(sciezka);
- MatOfFloat ranges = new MatOfFloat(0f, 256f);
- Mat hist1 = new Mat();
- Mat hist2 = new Mat();
- Mat hist3 = new Mat();
- int rozmiar = 100;
- MatOfInt histSize = new MatOfInt(rozmiar);
- Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(0), new Mat(), hist1, histSize, ranges);
- Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(1), new Mat(), hist2, histSize, ranges);
- Imgproc.calcHist(Arrays.asList(zdjecie),new MatOfInt(2), new Mat(), hist3, histSize, ranges);
- int histW = (int) zdjecie.size().width, histH = (int) zdjecie.size().height;
- int binW = (int)Math.round((double) histW / rozmiar);
- Mat histImage = new Mat( histH, histW, CvType.CV_8UC3, new Scalar( 0,0,0) );
- Core.normalize(hist1, hist1, 0, histImage.rows(), Core.NORM_MINMAX); //normalizacja
- Core.normalize(hist2, hist2, 0, histImage.rows(), Core.NORM_MINMAX);
- Core.normalize(hist3, hist3, 0, histImage.rows(), Core.NORM_MINMAX);
- float[] hist1Data = new float[(int) (hist1.total() * hist1.channels())];
- hist1.get(0, 0, hist1Data);
- float[] hist2Data = new float[(int) (hist2.total() * hist2.channels())];
- hist2.get(0, 0, hist2Data);
- float[] hist3Data = new float[(int) (hist3.total() * hist3.channels())];
- hist3.get(0, 0, hist3Data);
- for( int i = 1; i < rozmiar; i++ ) {
- Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist1Data[i - 1])),
- new Point(binW * (i), histH - Math.round(hist1Data[i])), new Scalar(255, 0, 0), 2);
- Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist2Data[i - 1])),
- new Point(binW * (i), histH - Math.round(hist2Data[i])), new Scalar(0, 255, 0), 2);
- Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(hist3Data[i - 1])),
- new Point(binW * (i), histH - Math.round(hist3Data[i])), new Scalar(0, 0, 255), 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement