Hello all,
I am trying to do some preprocessing on an image. I load it as a bitmap,
convert it to a mat, and then convert to grayscale. This all works fine,
but I want to improve the contrast before thresholding by using
Imgproc.equalizeHist, but my application always seems to crash or get a
weird result when I call it. I havent been able to find much info on this
online anywhere.

Here's my code:

Mat rgbMat = Utils.bitmapToMat(bmp);
Mat grayMat = new Mat();
Mat bwMat = new Mat();

Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY, 1);
Imgproc.equalizeHist(grayMat, grayMat);
Imgproc.threshold(grayMat, bwMat, 127.5, 255.0, Imgproc.THRESH_OTSU);

Any advice is appreciated

--

Search Discussions

  • Andrey Pavlenko at Jan 17, 2013 at 2:14 pm
    what OpenCV version do you use?
    I've checked the latest 2.4.3.2 and the code works OK with minimal
    modifications:

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.
    wshed_exp);

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

    Mat grayMat = new Mat();
    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);


    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-opencv @
categoriesandroid
postedJan 14, '13 at 8:12a
activeJan 17, '13 at 2:14p
posts2
users2
websiteandroid.com

2 users in discussion

Andrey Pavlenko: 1 post Itsmike: 1 post

People

Translate

site design / logo © 2019 Grokbase