List of usage examples for org.opencv.core Mat put
public int put(int row, int col, byte[] data)
From source file:OCV_Blur.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat/* w w w . j a va 2 s .c o m*/ Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 16) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); short[] srcdst_shorts = (short[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_16S); Mat dst_mat = new Mat(imh, imw, CvType.CV_16S); // run src_mat.put(0, 0, srcdst_shorts); Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_shorts); } else if (ip.getBitDepth() == 24) { // dst int imw = ip.getWidth(); int imh = ip.getHeight(); int[] srcdst_ints = (int[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3); // run OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh); Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]); OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:OCV_LogPolar.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst/* ww w .j a v a2 s. c om*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_ar = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_ar); Imgproc.logPolar(src_mat, dst_mat, new Point(cx, cy), (double) rmax, TYPE_INT[type_ind]); dst_mat.get(0, 0, srcdst_ar); }
From source file:OCV_GrabCut.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src (RGB)/*w w w . j a va 2 s.co m*/ int[] src_arr = (int[]) imp_src.getChannelProcessor().getPixels(); int imw_src = imp_src.getWidth(); int imh_src = imp_src.getHeight(); Mat mat_src = new Mat(imh_src, imw_src, CvType.CV_8UC3); OCV__LoadLibrary.intarray2mat(src_arr, mat_src, imw_src, imh_src); // tmp (Gray) byte[] msk_arr = (byte[]) imp_msk.getChannelProcessor().getPixels(); int imw_msk = imp_msk.getWidth(); int imh_msk = imp_msk.getHeight(); int numpix_msk = imw_msk * imh_msk; // output Mat mat_msk = new Mat(imh_msk, imw_msk, CvType.CV_8UC1); Mat bgdModel = new Mat(); Mat fgdModel = new Mat(); // run mat_msk.put(0, 0, msk_arr); Imgproc.grabCut(mat_src, mat_msk, rect, bgdModel, fgdModel, iter, TYPE_VAL[ind_type]); mat_msk.get(0, 0, msk_arr); if (enFgd) { for (int i = 0; i < numpix_msk; i++) { if (msk_arr[i] == Imgproc.GC_FGD || msk_arr[i] == Imgproc.GC_PR_FGD) { msk_arr[i] = (byte) 255; } else { msk_arr[i] = (byte) 0; } } } }
From source file:OCV_Laplacian.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat/*from w w w .ja va 2s .c o m*/ Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.Laplacian(src_mat, dst_mat, dst_mat.depth(), ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 16) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); short[] srcdst_shorts = (short[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_16S); Mat dst_mat = new Mat(imh, imw, CvType.CV_16S); // run src_mat.put(0, 0, srcdst_shorts); Imgproc.Laplacian(src_mat, dst_mat, dst_mat.depth(), ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_shorts); } else if (ip.getBitDepth() == 24) { // dst int imw = ip.getWidth(); int imh = ip.getHeight(); int[] srcdst_ints = (int[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3); // run OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh); Imgproc.Laplacian(src_mat, dst_mat, dst_mat.depth(), ksize, scale, delta, INT_BORDERTYPE[indBorderType]); OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.Laplacian(src_mat, dst_mat, dst_mat.depth(), ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:OCV_DistanceTransform.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst//from w ww .ja v a2 s . c o m int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat_32f = new Mat(imh, imw, CvType.CV_32FC1); Mat src_mat_8u = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat_32f = new Mat(imh, imw, CvType.CV_32FC1); // run src_mat_32f.put(0, 0, srcdst_floats); src_mat_32f.convertTo(src_mat_8u, CvType.CV_8UC1); Imgproc.distanceTransform(src_mat_8u, dst_mat_32f, INT_DISTANCETYPE[indDistType], INT_DISTANCETRANSFORMMASKS[indMskSize]); dst_mat_32f.get(0, 0, srcdst_floats); }
From source file:OCV_Watershed.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src (RGB)//w ww . ja va2 s . c om int[] arr_src_rgb = (int[]) imp_src.getChannelProcessor().getPixels(); int imw_src = imp_src.getWidth(); int imh_src = imp_src.getHeight(); Mat mat_src_rgb = new Mat(imh_src, imw_src, CvType.CV_8UC3); // map (32bit) float[] arr_map_32f = (float[]) imp_map.getChannelProcessor().getPixels(); int imw_map = imp_map.getWidth(); int imh_map = imp_map.getHeight(); Mat mat_map_32f = new Mat(imh_map, imw_map, CvType.CV_32FC1); Mat mat_map_32s = new Mat(imh_map, imw_map, CvType.CV_32SC1); // run OCV__LoadLibrary.intarray2mat(arr_src_rgb, mat_src_rgb, imw_src, imh_src); mat_map_32f.put(0, 0, arr_map_32f); mat_map_32f.convertTo(mat_map_32s, CvType.CV_32SC1); Imgproc.watershed(mat_src_rgb, mat_map_32s); mat_map_32s.convertTo(mat_map_32f, CvType.CV_32FC1); mat_map_32f.get(0, 0, arr_map_32f); }
From source file:OCV_GaussianBlur.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat/*from ww w . ja v a 2 s . co m*/ Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 16) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); short[] srcdst_shorts = (short[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_16S); Mat dst_mat = new Mat(imh, imw, CvType.CV_16S); // run src_mat.put(0, 0, srcdst_shorts); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_shorts); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:OCV_BilateralFilter.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat// w ww.j a v a2s . com Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 24) { // dst int imw = ip.getWidth(); int imh = ip.getHeight(); int[] srcdst_ints = (int[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3); // run OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_bytes = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else { IJ.error("Wrong image format"); } }
From source file:OCV_EqualizeHist.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst/* ww w. j a va 2 s . c o m*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.equalizeHist(src_mat, dst_mat); dst_mat.get(0, 0, srcdst_bytes); }
From source file:OCV_HoughLinesP.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src/*from ww w. j a v a2 s . c o m*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] src_ar = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_lines = new Mat(); // run src_mat.put(0, 0, src_ar); Imgproc.HoughLinesP(src_mat, dst_lines, resDist, CV_PI / resAngFact, minVotes, minLen, maxGap); // fin showData(dst_lines); }