Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to implement CLAHE algorithm in android using opencv 3?

hello, i am new in opencv, i trying to convert grayscale bitmap to CLAHE but i can't. i use this code

CLAHE clahe = Imgproc.createCLAHE(); CLAHEmat = new Mat(grayscale.getHeight(),grayscale.getWidth(), CvType.CV_8UC4); clahe.apply(labImage, CLAHEmat);

but i got this error

CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/clahe.cpp:354: error: (-215) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function virtual void {anonymous}::CLAHE_Impl::apply(cv::InputArray, cv::OutputArray)]

please help me..

thanks in advance

How to implement CLAHE algorithm in android using opencv 3?

hello, i am new in opencv, i trying to convert grayscale bitmap to CLAHE but i can't. i use this code

CLAHE clahe = Imgproc.createCLAHE(); 
CLAHEmat = new Mat(grayscale.getHeight(),grayscale.getWidth(), CvType.CV_8UC4);
clahe.apply(labImage, CLAHEmat);

CLAHEmat);

but i got this error

CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/clahe.cpp:354: CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/clahe.cpp:354: error: (-215) _src.type() == CV_8UC1 CV_8UC1 || _src.type() == CV_16UC1 in function function virtual void {anonymous}::CLAHE_Impl::apply(cv::InputArray, void {anonymous}::CLAHE_Impl::apply(cv::InputArray, cv::OutputArray)]

please help me..

thanks in advance

How to implement CLAHE algorithm in android using opencv 3?

hello, i am new in opencv, i trying to convert grayscale bitmap to CLAHE but i can't. i use this code

ImageView img;

Bitmap original, grayscale, histogram, resize, threshold; int fixedwidth = 480; int fixedheight = 800; Button btn_original, btn_grayscale, btn_histogram, btn_resize, btn_threshold; Mat rgbMat; Mat grayMat; Mat CLAHEmat;

static { System.loadLibrary("opencv_java3"); }

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

img = (ImageView) findViewById(R.id.imageView);

btn_original = (Button) findViewById(R.id.btn_original);
btn_grayscale = (Button) findViewById(R.id.btn_grayscale);
btn_histogram = (Button) findViewById(R.id.btn_histogram);
btn_resize = (Button) findViewById(R.id.btn_resize);
btn_threshold = (Button) findViewById(R.id.btn_threshold);

original = BitmapFactory.decodeResource(getResources(), R.drawable.sample);

btn_original.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        img.setImageBitmap(original);
    }
});

btn_grayscale.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        /*grayscale = getGrayscale(original);
        img.setImageBitmap(grayscale);*/
        grayscale = BitmapFactory.decodeResource(getResources(), R.drawable.sample);

        rgbMat = new Mat();
        Utils.bitmapToMat(grayscale, rgbMat);

        grayMat = new Mat(grayscale.getHeight(), grayscale.getWidth(),
                CvType.CV_8U, new Scalar(1));
        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 1);
        Utils.matToBitmap(grayMat, grayscale);
        img.setImageBitmap(grayscale);
        Log.e("Width & Height:-", grayscale.getWidth() + "-" + grayscale.getHeight());
    }
});

btn_histogram.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //histogram=HistogramEqualization.histogramEqualization(resize);

        int lnth = grayscale.getByteCount();

        ByteBuffer dst = ByteBuffer.allocate(lnth);
        grayscale.copyPixelsToBuffer(dst);
        byte[] byteArray = dst.array();

        Log.e("byte array", byteArray + "");
        Mat orgImage = new Mat();
        orgImage.put(0, 0, byteArray);

        Mat labImage = new Mat(grayscale.getHeight(), grayscale.getWidth(), CvType.CV_8UC1);
        Imgproc.cvtColor(orgImage, labImage, Imgproc.COLOR_BGR2Lab);

        CLAHE clahe = Imgproc.createCLAHE(); 
Imgproc.createCLAHE();
        CLAHEmat = new Mat(grayscale.getHeight(),grayscale.getWidth(), CvType.CV_8UC4);
Mat(grayscale.getHeight(), grayscale.getWidth(), CvType.CV_8UC1);
        clahe.apply(labImage, CLAHEmat);

        Utils.matToBitmap(CLAHEmat, histogram);
        img.setImageBitmap(histogram);
    }
});

btn_threshold.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.sheet);

        Mat rgbMat = new Mat();
        Utils.bitmapToMat(bmp, rgbMat);

        Mat grayMat = new Mat(histogram.getHeight(), histogram.getWidth(),
                CvType.CV_8U, new Scalar(1));
        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 1);
        Mat bwMat = new Mat();

        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY);
        Imgproc.equalizeHist(grayMat, grayMat);

        Imgproc.threshold(grayMat, bwMat, 127.5, 255.0, Imgproc.THRESH_OTSU);
        Utils.matToBitmap(bwMat, bmp);
        Imgproc.createCLAHE();
        img.setImageBitmap(bmp);
    }
});

}}

but i got this error

CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/clahe.cpp:354: error: (-215) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function virtual void {anonymous}::CLAHE_Impl::apply(cv::InputArray, cv::OutputArray)]

please help me..

thanks in advance

How to implement CLAHE algorithm in android using opencv 3?

hello, i am new in opencv, i trying to convert grayscale bitmap to CLAHE but i can't. i use this code

ImageView img;

img;

Bitmap original, grayscale, histogram, resize, threshold; threshold;

int fixedwidth = 480; int fixedheight = 800; Button btn_original, btn_grayscale, btn_histogram, btn_resize, btn_threshold; Mat rgbMat; Mat grayMat; Mat CLAHEmat;

static { System.loadLibrary("opencv_java3"); }

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

img = (ImageView) findViewById(R.id.imageView);

btn_original = (Button) findViewById(R.id.btn_original);
btn_grayscale = (Button) findViewById(R.id.btn_grayscale);
btn_histogram = (Button) findViewById(R.id.btn_histogram);
btn_resize = (Button) findViewById(R.id.btn_resize);
btn_threshold = (Button) findViewById(R.id.btn_threshold);

original = BitmapFactory.decodeResource(getResources(), R.drawable.sample);

btn_original.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        img.setImageBitmap(original);
    }
});

btn_grayscale.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        /*grayscale = getGrayscale(original);
        img.setImageBitmap(grayscale);*/
        grayscale = BitmapFactory.decodeResource(getResources(), R.drawable.sample);

        rgbMat = new Mat();
        Utils.bitmapToMat(grayscale, rgbMat);

        grayMat = new Mat(grayscale.getHeight(), grayscale.getWidth(),
                CvType.CV_8U, new Scalar(1));
        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 1);
        Utils.matToBitmap(grayMat, grayscale);
        img.setImageBitmap(grayscale);
        Log.e("Width & Height:-", grayscale.getWidth() + "-" + grayscale.getHeight());
    }
});

btn_histogram.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //histogram=HistogramEqualization.histogramEqualization(resize);

        int lnth = grayscale.getByteCount();

        ByteBuffer dst = ByteBuffer.allocate(lnth);
        grayscale.copyPixelsToBuffer(dst);
        byte[] byteArray = dst.array();

        Log.e("byte array", byteArray + "");
        Mat orgImage = new Mat();
        orgImage.put(0, 0, byteArray);

        Mat labImage = new Mat(grayscale.getHeight(), grayscale.getWidth(), CvType.CV_8UC1);
        Imgproc.cvtColor(orgImage, labImage, Imgproc.COLOR_BGR2Lab);

        CLAHE clahe = Imgproc.createCLAHE();
        CLAHEmat = new Mat(grayscale.getHeight(), grayscale.getWidth(), CvType.CV_8UC1);
        clahe.apply(labImage, CLAHEmat);

        Utils.matToBitmap(CLAHEmat, histogram);
        img.setImageBitmap(histogram);
    }
});

btn_threshold.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.sheet);

        Mat rgbMat = new Mat();
        Utils.bitmapToMat(bmp, rgbMat);

        Mat grayMat = new Mat(histogram.getHeight(), histogram.getWidth(),
                CvType.CV_8U, new Scalar(1));
        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 1);
        Mat bwMat = new Mat();

        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY);
        Imgproc.equalizeHist(grayMat, grayMat);

        Imgproc.threshold(grayMat, bwMat, 127.5, 255.0, Imgproc.THRESH_OTSU);
        Utils.matToBitmap(bwMat, bmp);
        Imgproc.createCLAHE();
        img.setImageBitmap(bmp);
    }
});

}}

but i got this error

CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/clahe.cpp:354: error: (-215) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function virtual void {anonymous}::CLAHE_Impl::apply(cv::InputArray, cv::OutputArray)]

please help me..

thanks in advance