Example usage for org.opencv.core Core normalize

List of usage examples for org.opencv.core Core normalize

Introduction

In this page you can find the example usage for org.opencv.core Core normalize.

Prototype

public static void normalize(Mat src, Mat dst, double alpha, double beta, int norm_type, int dtype) 

Source Link

Usage

From source file:ch.zhaw.facerecognitionlibrary.PreProcessor.PreProcessor.java

License:Open Source License

public void normalize01(Mat norm) {
    Core.normalize(norm, norm, 0.0, 1.0, Core.NORM_MINMAX, CvType.CV_64FC1);
    Core.MinMaxLocResult minmax = Core.minMaxLoc(norm);
    Scalar min = new Scalar(minmax.minVal);
    Core.subtract(norm, min, norm);//from   ww  w  . j a  v  a2  s.c o m
    minmax = Core.minMaxLoc(norm);
    Scalar max = new Scalar(minmax.maxVal);
    Core.divide(norm, max, norm);
}

From source file:ch.zhaw.facerecognitionlibrary.PreProcessor.PreProcessor.java

License:Open Source License

public void normalize0255(Mat norm) {
    Core.normalize(norm, norm, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC1);
}

From source file:karthik.Barcode.MatrixBarcode.java

License:Open Source License

private void calcGradientDirectionAndMagnitude() {
    // calculates magnitudes and directions of gradients in the image
    // results are stored in appropriate matrices in img_details object

    Imgproc.Scharr(img_details.src_grayscale, img_details.scharr_x, CvType.CV_32F, 1, 0);
    Imgproc.Scharr(img_details.src_grayscale, img_details.scharr_y, CvType.CV_32F, 0, 1);

    // calc angle using Core.phase function - quicker than using atan2 manually
    Core.phase(img_details.scharr_x, img_details.scharr_y, img_details.gradient_direction, true);

    // convert angles from 180-360 to 0-180 range and set angles from 170-180 to 0
    Core.inRange(img_details.gradient_direction, scalarDict.get(180), scalarDict.get(360), img_details.mask);
    Core.add(img_details.gradient_direction, scalarDict.get(-180), img_details.gradient_direction,
            img_details.mask);//from www.  j  a v a2 s.co m
    Core.inRange(img_details.gradient_direction, scalarDict.get(170), scalarDict.get(180), img_details.mask);
    img_details.gradient_direction.setTo(ZERO_SCALAR, img_details.mask);

    // convert type after modifying angle so that angles above 360 don't get truncated
    img_details.gradient_direction.convertTo(img_details.gradient_direction, CvType.CV_8U);
    if (DEBUG_IMAGES)
        write_Mat("angles.csv", img_details.gradient_direction);

    // calculate magnitude of gradient, normalize and threshold
    Core.magnitude(img_details.scharr_x, img_details.scharr_y, img_details.gradient_magnitude);
    Core.normalize(img_details.gradient_magnitude, img_details.gradient_magnitude, 0, 255, Core.NORM_MINMAX,
            CvType.CV_8U);
    Imgproc.threshold(img_details.gradient_magnitude, img_details.gradient_magnitude, 50, 255,
            Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);

    // set angle to DUMMY_ANGLE = 255 at all points where gradient magnitude is 0 i.e. where there are no edges
    // these angles will be ignored in the histogram calculation since that counts only up to 180
    Core.inRange(img_details.gradient_magnitude, ZERO_SCALAR, ZERO_SCALAR, img_details.mask);
    img_details.gradient_direction.setTo(scalarDict.get(DUMMY_ANGLE), img_details.mask);
    // add 1 to gradient directions so that gradients of 0 can be located
    Core.add(img_details.gradient_direction, new Scalar(1), img_details.gradient_direction);

    // calculate integral image for edge density
    img_details.edgeDensity = calcEdgeDensityIntegralImage();

    // calculate histograms for each tile
    calcHistograms();

    if (DEBUG_IMAGES) {
        write_Mat("magnitudes.csv", img_details.gradient_magnitude);
        write_Mat("angles_modified.csv", img_details.gradient_direction);
    }
}

From source file:openbjk.Identificador.java

public Mat norm_0_255(Mat input) {

    Mat dst = null;// w  w  w . j  a va 2s  .c  o m
    switch (input.channels()) {
    case 1:
        Core.normalize(input, dst, 0, 255, 2, CvType.CV_8UC1);
        break;
    case 3:
        Core.normalize(input, dst, 0, 255, 2, CvType.CV_8UC3);
        break;
    default:
        input.copyTo(dst);
    }

    return dst;
}