Example usage for org.opencv.core Mat get

List of usage examples for org.opencv.core Mat get

Introduction

In this page you can find the example usage for org.opencv.core Mat get.

Prototype

public double[] get(int row, int col) 

Source Link

Usage

From source file:controller.GhostDetection.java

public static int[][] detect(Mat imgR, Mat imgO, JointPDF jointPDF) {

    double count_blue, count_green, count_red;
    final double threshold = 0.00001;
    int[][] ghostPixel = new int[imgO.rows()][imgO.cols()];

    // Tresholding
    for (int i = 0; i < imgR.rows(); i++) {
        for (int j = 0; j < imgR.cols(); j++) {
            double[] rgbR = imgR.get(i, j);
            double[] rgbO = imgO.get(i, j);

            count_blue = jointPDF.getPDF_blue()[(int) rgbO[0]][(int) rgbR[0]];
            count_green = jointPDF.getPDF_green()[(int) rgbO[1]][(int) rgbR[1]];
            count_red = jointPDF.getPDF_red()[(int) rgbO[2]][(int) rgbR[2]];

            if (count_blue < threshold || count_green < threshold || count_red < threshold) {
                ghostPixel[i][j] = 0;//from   w w  w.j av a  2s  . com
            } else {
                ghostPixel[i][j] = 1;
            }
        }
    }
    //        for (int i = 0; i < 3; i++) {
    //            for (int j = 0; j < 5; j++) {
    //                double ghost = ghostPixel[i][j];
    //                System.out.print(ghost+";");
    //            }
    //            System.out.println("");
    //        }
    return ghostPixel;
}

From source file:ctPrincipal.Ruidos.java

private String ruidoGaussiano(int mean, int desv) {
    Mat original_Bgr = image.clone();
    Mat mGaussian_noise = new Mat(original_Bgr.size(), original_Bgr.type());
    randn(mGaussian_noise, mean, desv);//from  ww w.j av a  2s. c  om
    for (int m = 0; m < original_Bgr.rows(); m++) {
        for (int n = 0; n < original_Bgr.cols(); n++) {
            double[] val = new double[3];
            for (int i = 0; i < original_Bgr.get(m, n).length; i++) {
                val[i] = original_Bgr.get(m, n)[i] + mGaussian_noise.get(m, n)[i];
            }
            original_Bgr.put(m, n, val);
        }
    }
    normalize(original_Bgr, original_Bgr, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3);
    Imgcodecs.imwrite("OutputImg/gaussian.jpg", original_Bgr);
    return "OutputImg/gaussian.jpg";
}

From source file:ctPrincipal.Ruidos.java

private String ruidoSalPimenta(int min, int max) {
    Mat saltPepper_img = image.clone();/*from w  w w  .j  av  a2  s.  co m*/
    Mat mSaltPepper_noise = new Mat(saltPepper_img.size(), saltPepper_img.type());
    randn(mSaltPepper_noise, 0, 255);
    for (int m = 0; m < saltPepper_img.rows(); m++) {
        for (int n = 0; n < saltPepper_img.cols(); n++) {
            double[] val = new double[3];
            if (mSaltPepper_noise.get(m, n)[0] < min && mSaltPepper_noise.get(m, n)[1] < min
                    && mSaltPepper_noise.get(m, n)[2] < min) {
                for (int i = 0; i < saltPepper_img.get(m, n).length; i++) {
                    val[i] = 0;
                }
                saltPepper_img.put(m, n, val);
            }
            if (mSaltPepper_noise.get(m, n)[0] > max && mSaltPepper_noise.get(m, n)[1] > max
                    && mSaltPepper_noise.get(m, n)[2] > max) {
                for (int i = 0; i < saltPepper_img.get(m, n).length; i++) {
                    val[i] = 255;
                }
                saltPepper_img.put(m, n, val);
            }
        }
    }
    normalize(saltPepper_img, saltPepper_img, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3);
    Imgcodecs.imwrite("OutputImg/saltpepper.jpg", saltPepper_img);
    return "OutputImg/saltpepper.jpg";
}

From source file:cv.faceRecognize.faceRecognizer.java

public Mat ListToMat(List<Integer> a) {
    System.out.println(a);//from   w w w .j a v  a 2 s .com
    Mat m = new Mat(a.size(), 1, CvType.CV_32SC1);
    //        IntBuffer inf = m.createBuffer();
    System.out.println(m);
    int i = 0;
    for (int lable : a) {
        System.out.println(Arrays.toString(m.get(i, 1)));
        m.put(i, 0, lable);
        System.out.println(Arrays.toString(m.get(i, 0)));
        i += 1;
    }
    System.out.println(m);
    return m;
}

From source file:de.hu_berlin.informatik.spws2014.mapever.entzerrung.CornerDetector.java

License:Open Source License

/**
 * Finds the lines closest to the images border within a reasonable range
 * of slopes./*from   w w  w  .j  a  va 2  s  .  c om*/
 * 
 * Turns out this is sufficient to give acceptable results.
 * 
 * @param lines The lines within the original image, in OpenCVs Mat format(as returned by HoughLines or HoughLinesP)
 * @param image_dimensions The original image size
 * @return 4 lines in the by now well known format of 4 doubles per line: {x0,y0,x1,y1}{x0,y0,x1,y1}...
 **/
private static double[][] filter_lines(Mat lines, Size image_dimensions) {
    double[][] ret_lines = new double[4][4];
    double min_x = Double.MAX_VALUE, max_x = Double.MIN_VALUE, min_y = Double.MAX_VALUE,
            max_y = Double.MIN_VALUE;

    for (int l = 0; l < lines.cols(); ++l) {
        double current_line[] = lines.get(0, l);
        if (too_close(current_line, image_dimensions))
            continue;

        double slope = get_slope(current_line);
        if (Math.abs(slope) <= MAX_SLOPE) {
            double cl_min_y = Math.min(current_line[1], current_line[3]);
            double cl_max_y = Math.max(current_line[1], current_line[3]);
            if (cl_min_y < min_y) {
                ret_lines[0] = current_line;
                min_y = cl_min_y;
            }
            if (cl_max_y > max_y) {
                ret_lines[1] = current_line;
                max_y = cl_max_y;
            }
        } else if (Math.abs(1.0 / slope) <= MAX_SLOPE) {
            double cl_min_x = Math.min(current_line[0], current_line[2]);
            double cl_max_x = Math.max(current_line[0], current_line[2]);
            if (cl_min_x < min_x) {
                ret_lines[2] = current_line;
                min_x = cl_min_x;
            }
            if (cl_max_x > max_x) {
                ret_lines[3] = current_line;
                max_x = cl_max_x;
            }
        }

    }
    return ret_lines;
}

From source file:dfmDrone.examples.fitEllipseExample.java

private static Mat findAndDrawEllipse(Mat sourceImg) {
    Mat grayScaleImg = new Mat();
    Mat hsvImg = new Mat();
    Imgproc.cvtColor(sourceImg, hsvImg, Imgproc.COLOR_BGR2HSV);
    Mat lower_hue_range = new Mat();
    Mat upper_hue_range = new Mat();
    Core.inRange(hsvImg, new Scalar(0, 100, 45), new Scalar(15, 255, 255), lower_hue_range);
    Core.inRange(hsvImg, new Scalar(160, 100, 45), new Scalar(180, 255, 255), upper_hue_range);
    Mat red_hue_image = new Mat();
    Core.addWeighted(lower_hue_range, 1.0, upper_hue_range, 1.0, 0, red_hue_image);
    Mat dilateElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(24, 24));
    Mat erodeElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10, 10));

    Imgproc.blur(red_hue_image, red_hue_image, new Size(11, 11));
    // init/* w  w w  .ja va  2  s  .  co m*/
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();

    // find contours
    Imgproc.findContours(red_hue_image, contours, hierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);
    System.out.println("After findcontours");
    // if any contour exist...
    if (hierarchy.size().height > 0 && hierarchy.size().width > 0) {
        // for each contour, display it in blue
        for (int idx = 0; idx >= 0; idx = (int) hierarchy.get(0, idx)[0]) {
            System.out.println(idx);
            //   Imgproc.drawContours(frame, contours, idx, new Scalar(250, 0, 0), 3);

        }
    }
    MatOfPoint2f approxCurve = new MatOfPoint2f();

    //For each contour found
    MatOfPoint2f contour2f = null;
    RotatedRect rotatedrect = null;
    for (MatOfPoint contour : contours) {
        //Convert contours(i) from MatOfPoint to MatOfPoint2f
        if (contour2f == null)
            contour2f = new MatOfPoint2f(contour.toArray());
        if (contour.size().area() > contour2f.size().area()) {
            contour2f = new MatOfPoint2f(contour.toArray());
        }
    }
    try {
        Imgproc.fitEllipse(contour2f);
        rotatedrect = Imgproc.fitEllipse(contour2f);

        double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
        Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

        //Convert back to MatOfPoint
        MatOfPoint points = new MatOfPoint(approxCurve.toArray());

        // Get bounding rect of contour
        Rect rect = Imgproc.boundingRect(points);

        // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
        Imgproc.rectangle(sourceImg, rect.tl(), rect.br(), new Scalar(255, 0, 0), 1, 8, 0);
        Imgproc.ellipse(sourceImg, rotatedrect, new Scalar(255, 192, 203), 4, 8);
    } catch (CvException e) {
        e.printStackTrace();
        System.out.println("Ingen ellipse fundet");
    }
    return sourceImg;
}

From source file:edu.soict.hust.k57.mmdb.components.HistogramImageBulder.java

private ImageIcon createImageIcon(Mat hist, int bin, Channel c) {
    int hist_w = 150; // width of the histogram image
    int hist_h = 100; // height of the histogram image
    int bin_w = (int) Math.round(hist_w * 1.0 / bin);

    Mat histImage = new Mat(hist_h, hist_w, CvType.CV_8UC3, new Scalar(80, 60, 60));
    Mat normalizeHist = hist.clone();
    Core.normalize(normalizeHist, normalizeHist, 0, histImage.rows(), Core.NORM_MINMAX, -1, new Mat());

    Scalar scalar = null;//from www.j  av a2  s  .  c  o  m
    switch (c) {
    case B:
        scalar = new Scalar(255, 0, 0);
        break;
    case G:
        scalar = new Scalar(0, 255, 0);
        break;
    case R:
        scalar = new Scalar(0, 0, 255);
    }

    for (int i = 1; i < bin; i++) {
        Imgproc.line(histImage, new Point(bin_w * (i - 1), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])),
                new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])), scalar, 1, 8, 0);
        Imgproc.line(histImage, new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])),
                new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i, 0)[0])), scalar, 1, 8, 0);
    }
    MatOfByte buffer = new MatOfByte();
    Imgcodecs.imencode(".png", histImage, buffer);
    return new ImageIcon(buffer.toArray());
}

From source file:edu.sust.cse.analysis.news.NewsAnalysis.java

public static void main(String[] args) throws IOException {

    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-01.jpg");
    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-01-145.jpg");
    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-02.jpg");
    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-03.jpg");
    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-04.jpg");
    //                Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\e-05.jpg");
    //                 Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-01.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-04_resized.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\Camscanner Output\\normal_output_scan0007.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\Camscanner Output\\normal_output_scan0007-01.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\Camscanner Output\\normal_output_scan0001-01.bmp");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\scan-01-dec\\scan0007-300.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\scan-01-dec\\scan0007-145.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\scan-01-dec\\scan0007-145.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\scan-01-dec\\scan0007-96.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Google\\Thesis Work\\scan-01-dec\\scan0001-145.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Thesis-4-1\\Previous Work\\OPenCv2\\eProthomAlo Sample I-O\\e-5-12.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\Thesis-4-1\\Previous Work\\OPenCv2\\eProthomAlo Sample I-O\\e-6-12.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\06-12-2015\\sc-03-145.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\06-12-2015\\sc-03-145.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\06-12-2015\\sc-03-300B.jpg");
    Mat inputImageMat = Highgui/* www .j  a  v a  2 s  .com*/
            .imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\06-12-2015\\sc-03-145B.jpg");
    if (null == inputImageMat) {
        System.out.println("[INPUT IMAGE NULL]");
    }
    Mat image = new Mat();//normal_output_scan0002.jpg
    double ratio = 150 / 72.0; // 4.167
    System.out.println("WIDTH: " + inputImageMat.width() + " HEIGHT:" + inputImageMat.height());
    int inputWidth = (int) (inputImageMat.width() * ratio);
    int inputHeight = (int) (inputImageMat.height() * ratio);
    System.out.println("WIDTH: " + inputWidth + " HEIGHT:" + inputHeight);

    //        inputImageMat = image;
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-02.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-03.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-04.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\data1\\sc-05.jpg");
    //        Mat inputImageMat = Highgui.imread("D:\\OpenCV_Library\\resources\\Scan_Img\\image\\web001.png");
    Debug.debugLog("[Image [Cols, Rows]: [" + inputImageMat.cols() + ", " + inputImageMat.rows() + "]]");
    //        imshow("Original", inputImageMat);
    ViewerUI.show("Original", inputImageMat, ViewableUI.SHOW_ORIGINAL);
    //        ViewerUI.show("Original-Histogram", Histogram.getHistogram(inputImageMat), ViewableUI.SHOW_HISTOGRAM_ORIGINAL);

    // Do some image processing on the image and display in another window.
    Mat filteredImage = new Mat();
    /**
     * We have explained some filters which main goal is to smooth an input
     * image. However, sometimes the filters do not only dissolve the noise,
     * but also smooth away the edges
     */
    //        Imgproc.bilateralFilter(inputImageMat, m2, -1, 50, 10); /*Previous line for noise filtering*/
    Imgproc.bilateralFilter(inputImageMat, filteredImage, -1, 50, 10);
    //        Imgproc.bilateralFilter(inputImageMat, filteredImage, -1, 150, 11);

    ViewerUI.show("Noise Filter", filteredImage, ViewableUI.SHOW_NOISE_FILTER);
    //        ViewerUI.show("Noise Filter-Histogram", Histogram.getHistogram(filteredImage), ViewableUI.SHOW_HISTOGRAM_NOISE_FILTER);
    Imgproc.Canny(filteredImage, filteredImage, 10, 150);
    //        Imgproc.bilateralFilter(filteredImage, filteredImage, -1, 50, 10);
    //        Imgproc.threshold(filteredImage, filteredImage, 250, 300,Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C );
    //Imgproc.cvtColor(m1, m1, Imgproc.COLOR_RGB2GRAY, 0);
    //        imshow("Edge Detected", m2);
    ViewerUI.show("Edge Detected", filteredImage, ViewableUI.SHOW_EDGE_DETECTION);
    //        ViewerUI.show("Edge Detected-Histogram", Histogram.getHistogram(filteredImage), ViewableUI.SHOW_HISTOGRAM_EDGE_DETECTION);

    Size sizeA = filteredImage.size();
    System.out.println("Width: " + sizeA.width + " Height: " + sizeA.height);
    int width = (int) sizeA.width;
    int height = (int) sizeA.height;
    int pointLength[][][] = new int[height][width][2];
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            //double[] data = m2.get(i, j);
            if (filteredImage.get(i, j)[0] != 0) {
                pointLength[i][j][0] = 0;
                pointLength[i][j][1] = 0;
                continue;
            }
            if (j != 0 && filteredImage.get(i, j - 1)[0] == 0) {
                pointLength[i][j][0] = pointLength[i][j - 1][0];
            } else {
                int count = 0;
                for (int k = j + 1; k < width; k++) {
                    if (filteredImage.get(i, k)[0] == 0) {
                        count++;
                    } else {
                        break;
                    }
                }
                pointLength[i][j][0] = count;
            }
            if (i != 0 && filteredImage.get(i - 1, j)[0] == 0) {
                pointLength[i][j][1] = pointLength[i - 1][j][1];
            } else {
                int count = 0;
                for (int k = i + 1; k < height; k++) {
                    if (filteredImage.get(k, j)[0] == 0) {
                        count++;
                    } else {
                        break;
                    }
                }
                pointLength[i][j][1] = count;
            }
        }
    }
    String temp = "";
    Mat convertArea = filteredImage.clone();

    int[][] blackWhite = new int[height][width];

    for (int i = 0; i < height; i++) {
        temp = "";
        for (int j = 0; j < width; j++) {
            if (i == 0 || j == 0 || i == height - 1 || j == width - 1) {
                temp = temp + "@";
                blackWhite[i][j] = 1;

                double[] data = filteredImage.get(i, j);
                data[0] = 255.0;
                convertArea.put(i, j, data);
            } else if (pointLength[i][j][0] > 150 && pointLength[i][j][1] > 6) {
                temp = temp + "@";
                blackWhite[i][j] = 1;

                double[] data = filteredImage.get(i, j);
                data[0] = 255.0;
                convertArea.put(i, j, data);
            } else if (pointLength[i][j][0] > 7 && pointLength[i][j][1] > 200) {
                temp = temp + "@";
                blackWhite[i][j] = 1;

                double[] data = filteredImage.get(i, j);
                data[0] = 255.0;
                convertArea.put(i, j, data);
            } else {
                temp = temp + " ";
                blackWhite[i][j] = 0;

                double[] data = filteredImage.get(i, j);
                data[0] = 0.0;
                convertArea.put(i, j, data);
            }

        }
    }
    ViewerUI.show("Convertion", convertArea, ViewableUI.SHOW_CONVERSION);
    //        ViewerUI.show("Convertion-Histogram", Histogram.getHistogram(convertArea), ViewableUI.SHOW_HISTOGRAM_CONVERSION);

    ImageDetection isImage = new ImageDetection();
    HeadlineDetection isHeadline = new HeadlineDetection();

    ImageBorderDetectionBFS imgBFS = new ImageBorderDetectionBFS();
    ArrayList<BorderItem> borderItems = imgBFS.getBorder(blackWhite, width, height, filteredImage,
            inputImageMat);
    // Mat[] subMat = new Mat[borderItems.size()];
    //        for (int i = 0; i < borderItems.size(); i++) {
    //            subMat[i] = m2.submat(borderItems.get(i).getMinX(), borderItems.get(i).getMaxX(),
    //                    borderItems.get(i).getMinY(), borderItems.get(i).getMaxY());
    //            if (isImage.isImage(subMat[i])) {
    //                System.out.println("subMat" + i + " is an image");
    //                imshow("Image" + i, subMat[i]);
    //
    //            }else if(isHeadline.isHeadLine(subMat[i])){
    //                System.out.println("subMat" + i + " is an Headline");
    //                imshow("Headline" + i, subMat[i]);
    //            }else{
    //                System.out.println("subMat" + i + " is an Column");
    //                imshow("Column" + i, subMat[i]);
    //            }
    //            //imshow("subMat" + i, subMat[i]);
    //            bw.close();
    //
    //        }

    boolean[] imageIndexer = new boolean[borderItems.size()];
    int[] lineHeight = new int[borderItems.size()];
    int highestLinheight = -1, lowestLineHeight = 10000;
    int totalHeight = 0, notImage = 0;

    for (int i = 0; i < borderItems.size(); i++) {
        lineHeight[i] = 0;
        BorderItem borderItem = borderItems.get(i);
        //            subMat[i] = m2.submat(borderItems.get(i).getMinX(), borderItems.get(i).getMaxX(),
        //                    borderItems.get(i).getMinY(), borderItems.get(i).getMaxY());
        //            if (isImage.isImage(subMat[i])) {
        //                System.out.println("subMat" + i + " is an image");
        //                imshow("Image" + i, subMat[i]);
        //                imageIndexer[i] = true;
        //                continue;
        //            }else{
        //                notImage++;
        //                imageIndexer[i] = false;
        //            }
        if (borderItem.getIsImage()) {
            System.out.println("subMat" + i + " is an image");
            //                imshow("Image" + i, borderItem.getBlock());
            ViewerUI.show("Image" + i, borderItem.getBlock(), ViewableUI.SHOW_IMAGE);
            //                ViewerUI.show("Image-Histogram" + i, Histogram.getHistogram(borderItem.getBlock()), ViewableUI.SHOW_HISTOGRAM_IMAGE);

            imageIndexer[i] = true;
            continue;
        } else {
            notImage++;
            imageIndexer[i] = false;
        }

        //            totalHeight += lineHeight[i] = getLineHeight(subMat[i]);
        Mat fake = new Mat();
        Imgproc.cvtColor(borderItem.getBlock(), fake, Imgproc.COLOR_RGB2GRAY, 0);
        totalHeight += lineHeight[i] = getLineHeight(fake);
        fake.release();
        System.out.println("line height " + i + ": " + lineHeight[i]);
        //            imshow("" + i, borderItems.get(i).getBlock());
        if (lineHeight[i] > highestLinheight) {
            highestLinheight = lineHeight[i];
        }
        if (lineHeight[i] < lowestLineHeight) {
            lowestLineHeight = lineHeight[i];
        }

        //            if(i==7)
        //                break;
    }

    int avgLineHeight = totalHeight / notImage;

    for (int i = 0; i < borderItems.size(); i++) {
        if (!imageIndexer[i]) {
            if (lineHeight[i] - lowestLineHeight > 13 && lineHeight[i] >= 45) {
                //                    imshow("Headline" + i, subMat[i]);
                //                    imshow("Headline" + i, borderItems.get(i).getBlock());
                ViewerUI.show("Headline" + i, borderItems.get(i).getBlock(), ViewableUI.SHOW_HEADING);
                //                    ViewerUI.show("Headline-Histogram" + i, Histogram.getHistogram(borderItems.get(i).getBlock()), ViewableUI.SHOW_HISTOGRAM_HEADING);

            } else if (lineHeight[i] - lowestLineHeight > 8 && lineHeight[i] >= 21 && lineHeight[i] < 45) {
                //                    imshow("Sub Headline" + i, borderItems.get(i).getBlock());
                ViewerUI.show("Sub Headline" + i, borderItems.get(i).getBlock(), ViewableUI.SHOW_SUB_HEADING);
                //                    ViewerUI.show("Sub Headline-Histogram" + i, Histogram.getHistogram(borderItems.get(i).getBlock()), ViewableUI.SHOW_HISTOGRAM_SUB_HEADING);

            } else {
                //                    imshow("Column" + i, subMat[i]);
                //                    imshow("Column" + i, borderItems.get(i).getBlock());
                ViewerUI.show("Column" + i, borderItems.get(i).getBlock(), ViewableUI.SHOW_COLUMN);
                //                    ViewerUI.show("Column-Histogram" + i, Histogram.getHistogram(borderItems.get(i).getBlock()), ViewableUI.SHOW_HISTOGRAM_COLUMN);

            }
        }
    }

}

From source file:edu.sust.cse.analysis.news.NewsAnalysis.java

private static int getLineHeight(Mat subMat) {
    int lineHeight = 0;
    float width = subMat.width();
    float height = subMat.height();

    if (height < 5 || width < 5) {
        return lineHeight;
    }//from w  w  w .j  a v  a 2 s  . com

    int start = -1, end = -1, biggest = -1;
    //        String blacks= "";

    for (int i = 0; i < height; i++) {
        int white = 0;
        for (int j = 0; j < width; j++) {

            if (subMat.get(i, j)[0] <= 140) {
                white++;
                if (start == -1) {
                    start = i;
                }
                //                    blacks +="1";
                //                    break;
            } else {
                //                    blacks +="0";
            }
        }
        //            blacks += "\n";

        //            if(white==0){
        //                for(int j=0; j<width; j++){
        //                    double[] data = subMat.get(i, j);
        //                    if(data != null){
        //                        data[0] = 0.0;
        //                        subMat.put(i, j, data);
        //                    }
        //                }
        //            }
        //            if(biggest < white){
        //                biggest = white;
        //            }
        //            System.out.println(blacks);
        if (white == 0 && start != -1) {
            if ((i - 1 - start) < 5) {
                lineHeight = i - 1 - start;
                start = -1;
                continue;
            }

            if (end == -1) {
                end = i - 1;
            }
            lineHeight = end - start;
            break;
        }

        if (i == height - 1 && end == -1) {
            end = i;
            lineHeight = end - start;
        }
    }
    //        System.out.println("start: "+start);
    //            System.out.println("end: "+end);
    //        if(lineHeight == 50){
    //        filewrile(blacks);
    //        filewrile("\n\n\n\n\n\n\n\n");
    //        }
    return lineHeight;

    // Read image as before
    //        Mat rgba = subMat.clone();
    ////        Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGB2GRAY, 0);
    //
    //        // Create an empty image in matching format
    //        BufferedImage gray = new BufferedImage(rgba.width(), rgba.height(), BufferedImage.TYPE_BYTE_GRAY);
    //
    //        // Get the BufferedImage's backing array and copy the pixels directly into it
    //        byte[] data = ((DataBufferByte) gray.getRaster().getDataBuffer()).getData();
    //        rgba.get(0, 0, data);
    //
    //  return largestBlackBatch1(gray)[1];
}

From source file:edu.sust.cse.detection.algorithm.ImageBorderDetectionBFS.java

private void eraseImges() {
    Mat mLocal = ImageBorderDetectionBFS.m1.clone();
    for (BorderItem imageItem : imageItems) {
        int iMinX = imageItem.getMinX(), iMinY = imageItem.getMinY(), iMaxX = imageItem.getMaxX(),
                iMaxY = imageItem.getMaxY();
        double[] data = null;
        for (int i = iMinX; i < iMaxX; i++) {
            for (int j = iMinY; j < iMaxY; j++) {
                data = mLocal.get(i, j);
                data[0] = 255.0;/*from  w  ww  .j  a  v  a  2 s.c  om*/
                data[1] = 255.0;
                data[2] = 255.0;
                mLocal.put(i, j, data);
            }
        }
    }

    NewsAnalysis.imshow("img_removed", mLocal);
    //        return;

    for (int i = 0; i < otherItems.size(); i++) {
        BorderItem otherItem = otherItems.get(i);

        Mat subMat = mLocal.submat(otherItem.getMinX(), otherItem.getMaxX(), otherItem.getMinY(),
                otherItem.getMaxY());
        otherItem.setBlock(subMat);

        otherItems.set(i, otherItem);
        borderItems.add(otherItem);
    }
}