Java Code Examples for org.opencv.imgproc.Imgproc#filter2D()
The following examples show how to use
org.opencv.imgproc.Imgproc#filter2D() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureWeight.java From OptimizedImageEnhance with MIT License | 6 votes |
public static Mat LocalContrast(Mat img) { double[] h = { 1.0 / 16.0, 4.0 / 16.0, 6.0 / 16.0, 4.0 / 16.0, 1.0 / 16.0 }; Mat mask = new Mat(h.length, h.length, img.type()); for (int i = 0; i < h.length; i++) { for (int j = 0; j < h.length; j++) { mask.put(i, j, h[i] * h[j]); } } Mat localContrast = new Mat(); Imgproc.filter2D(img, localContrast, img.depth(), mask); for (int i = 0; i < localContrast.rows(); i++) { for (int j = 0; j < localContrast.cols(); j++) { if (localContrast.get(i, j)[0] > Math.PI / 2.75) localContrast.put(i, j, Math.PI / 2.75); } } Core.subtract(img, localContrast, localContrast); return localContrast.mul(localContrast); }
Example 2
Source File: ImgDecompose.java From OptimizedImageEnhance with MIT License | 6 votes |
public static Mat[] buildGaussianPyramid(Mat img, int level) { Mat[] gaussPyr = new Mat[level]; Mat mask = filterMask(img); Mat tmp = new Mat(); Imgproc.filter2D(img, tmp, -1, mask); gaussPyr[0] = tmp.clone(); Mat tmpImg = img.clone(); for (int i = 1; i < level; i++) { // resize image Imgproc.resize(tmpImg, tmpImg, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR); // blur image tmp = new Mat(); Imgproc.filter2D(tmpImg, tmp, -1, mask); gaussPyr[i] = tmp.clone(); } return gaussPyr; }
Example 3
Source File: WeightCalculate.java From ImageEnhanceViaFusion with MIT License | 6 votes |
public static Mat LocalContrast(Mat img) { double[] h = { 1.0 / 16.0, 4.0 / 16.0, 6.0 / 16.0, 4.0 / 16.0, 1.0 / 16.0 }; Mat mask = new Mat(h.length, h.length, img.type()); for (int i = 0; i < h.length; i++) { for (int j = 0; j < h.length; j++) { mask.put(i, j, h[i] * h[j]); } } Mat localContrast = new Mat(); Imgproc.filter2D(img, localContrast, img.depth(), mask); for (int i = 0; i < localContrast.rows(); i++) { for (int j = 0; j < localContrast.cols(); j++) { if (localContrast.get(i, j)[0] > Math.PI / 2.75) localContrast.put(i, j, Math.PI / 2.75); } } Core.subtract(img, localContrast, localContrast); return localContrast.mul(localContrast); }
Example 4
Source File: MainActivity.java From MOAAP with MIT License | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { //Put it there, just in case:) super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch(requestCode) { case SELECT_PHOTO: if(resultCode == RESULT_OK && read_external_storage_granted){ try { final Uri imageUri = imageReturnedIntent.getData(); final InputStream imageStream = getContentResolver().openInputStream(imageUri); final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); src = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC4); Utils.bitmapToMat(selectedImage, src); src_gray = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC1); switch (ACTION_MODE) { case HomeActivity.GAUSSIAN_BLUR: Imgproc.GaussianBlur(src, src, new Size(9, 9), 0); break; case HomeActivity.MEAN_BLUR: Imgproc.blur(src, src, new Size(9, 9)); break; case HomeActivity.MEDIAN_BLUR: Imgproc.medianBlur(src, src, 9); break; case HomeActivity.SHARPEN: Mat kernel = new Mat(3, 3, CvType.CV_16SC1); //int[] values = {0, -1, 0, -1, 5, -1, 0, -1, 0}; Log.d("imageType", CvType.typeToString(src.type()) + ""); kernel.put(0, 0, 0, -1, 0, -1, 5, -1, 0, -1, 0); Imgproc.filter2D(src, src, src_gray.depth(), kernel); break; case HomeActivity.DILATE: Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY); Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY); Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3)); Imgproc.dilate(src_gray, src_gray, kernelDilate); Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4); break; case HomeActivity.ERODE: Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY); Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY); Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5)); Imgproc.erode(src_gray, src_gray, kernelErode); Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4); break; case HomeActivity.THRESHOLD: Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY); Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY); Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4); break; case HomeActivity.ADAPTIVE_THRESHOLD: Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY); Imgproc.adaptiveThreshold(src_gray, src_gray, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 3, 0); Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4); break; } Bitmap processedImage = Bitmap.createBitmap(src.cols(), src.rows(), Bitmap.Config.ARGB_8888); Log.i("imageType", CvType.typeToString(src.type()) + ""); Utils.matToBitmap(src, processedImage); ivImage.setImageBitmap(selectedImage); ivImageProcessed.setImageBitmap(processedImage); Log.i("process", "process done"); } catch (FileNotFoundException e) { e.printStackTrace(); } } break; } }