List of usage examples for org.opencv.imgproc Imgproc createCLAHE
public static CLAHE createCLAHE()
From source file:com.example.root.dipproj.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == 1) { File f = new File(Environment.getExternalStorageDirectory().toString()); for (File temp : f.listFiles()) { if (temp.getName().equals("temp.jpg")) { f = temp;//from w w w .ja va2s . c o m break; } } try { Bitmap bitmap; BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions); viewImage.setImageBitmap(bitmap); String path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Phoenix" + File.separator + "default"; f.delete(); OutputStream outFile = null; File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"); try { outFile = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile); outFile.flush(); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } else if (requestCode == 2) { Uri selectedImage = data.getData(); String[] filePath = { MediaStore.Images.Media.DATA }; Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePath[0]); String picturePath = c.getString(columnIndex); c.close(); Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath)); Log.w("path of image", picturePath + ""); Mat imgMat = new Mat(); Mat imgMat2 = new Mat(); Mat imgMat3 = new Mat(); Utils.bitmapToMat(thumbnail, imgMat); Imgproc.cvtColor(imgMat, imgMat, Imgproc.COLOR_RGB2GRAY); org.opencv.core.Size s = new Size(3, 3); Imgproc.createCLAHE(); Imgproc.GaussianBlur(imgMat, imgMat, s, 2); Imgproc.erode(imgMat, imgMat2, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2))); Imgproc.dilate(imgMat2, imgMat3, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2))); Imgproc.Sobel(imgMat, imgMat, CvType.CV_8UC1, 1, 0); Core.absdiff(imgMat, imgMat3, imgMat); Imgproc.threshold(imgMat, imgMat, 123, 255, Imgproc.THRESH_OTSU); Utils.matToBitmap(imgMat, thumbnail); viewImage.setImageBitmap(thumbnail); saveBitmaptoSDCard(thumbnail); } } }