Ask Your Question

Silberlicht's profile - activity

2016-04-27 14:03:34 -0500 received badge  Scholar (source)
2016-04-21 13:48:22 -0500 commented question OpenCV4Android - BilateralFilter Problems

That did it... Thanks. I didn't even think that might cause a problem.

2016-04-21 10:17:18 -0500 commented question OpenCV4Android - BilateralFilter Problems

Updated Code to be a 3-Channel but something else must be wrong.

2016-04-21 08:59:59 -0500 asked a question OpenCV4Android - BilateralFilter Problems

So I'm attempting to use a bilateralFilter and it's crashing for reasons unknown to me.

I'm following these as a guide and I'm not seeing anything wrong:
http://opencvexamples.blogspot.com/20...
http://docs.opencv.org/2.4/doc/tutori...

private Mat sharpen(Mat passedImage)
{
    Mat bilateral = passedImage.clone();
    Imgproc.cvtColor(bilateral, bilateral, Imgproc.COLOR_BGRA2BGR);

    int iSize = 9;

    Imgproc.bilateralFilter(bilateral, bilateral, iSize, iSize*2, iSize/2);

    return bilateral;
}
2016-04-13 16:13:19 -0500 asked a question OpenCV4Android - calcCovarMatrix for image averages

So I have two RBG averages that I want to get a Mahalanobis distance for. The Mahalanobis function requires an inverse co-variance matrix. My question is how do I create a inverse co-variance matric for averages?

The averages would just be two 1x3 vectors but those averages come from a single image that's 27x27.

The image looks similar to this: enter image description here

One of the averages is for an estimate of the average RBG values for inside the circle and the other is outside the RBG values outside the circle. Is it as simple as creating two images one with the inside of the circle and filling the background with my average circle values and another with the background and filling in the circle with my average background values? From what I've read the inverse co-variance matrix would need to be a 3x3 so I don't think that can work...

Mat coloredImage = colorImage.clone();
Mat threshedImage = threshImage.clone();
Mat mask = new Mat(coloredImage.size(), CvType.CV_8UC1, Scalar.all(255));

Core.circle(mask, new Point(mask.rows() / 2, mask.cols() / 2), (int) mR, Scalar.all(0), -1, 8, 0);

Bitmap gridBitmap = Bitmap.createBitmap(mask.width(), mask.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mask, gridBitmap);

double externalRed = 0;
double externalGreen = 0;
double externalBlue = 0;
int externalCount = 0;

double internalRed = 0;
double internalGreen = 0;
double internalBlue = 0;
int internalCount = 0;

//FIXME: Revisit when I have a better understanding of masks in OpenCV - Masks appear to only effect 1 channel
for (int column=0; column<mask.cols(); column++)
{
    for (int row=0; row<mask.rows(); row++)
    {
        double[] maskValue = mask.get(row, column);
        double[] value = coloredImage.get(row, column);

        if (maskValue[0] == 255)
        {
            externalRed = externalRed + value[0];
            externalGreen = externalGreen + value[1];
            externalBlue = externalBlue + value[2];
            externalCount++;
        }
        else
        {
            internalRed = internalRed + value[0];
            internalGreen = internalGreen + value[1];
            internalBlue = internalBlue + value[2];
            internalCount++;
        }
    }
}

int externalAvgRed = (int)(externalRed / externalCount);
int externalAvgGreen = (int)(externalGreen / externalCount);
int externalAvgBlue = (int)(externalBlue / externalCount);

int internalAvgRed = (int)(internalRed / internalCount);
int internalAvgGreen = (int)(externalGreen / internalCount);
int internalAvgBlue = (int)(externalBlue / internalCount);

Mat smallColoredImage = new Mat();
Mat mean = new Mat();
Mat covar = new Mat();
MatOfFloat invcovar = new MatOfFloat(3,3);

Imgproc.resize(coloredImage, smallColoredImage, new Size(3, 3));

Core.calcCovarMatrix(smallColoredImage, covar, mean, Core.COVAR_NORMAL+Core.COVAR_ROWS, -1);

Core.invert(covar, invcovar, Core.DECOMP_SVD);

MatOfFloat mu0 = new MatOfFloat(3,1);
MatOfFloat mu1 = new MatOfFloat(3,1);

mu0.put(0, 0, externalAvgRed);
mu0.put(1, 0, externalAvgGreen);
mu0.put(2, 0, externalAvgGreen);

mu1.put(0, 0, internalAvgRed);
mu1.put(1, 0, internalAvgGreen);
mu1.put(2, 0, internalAvgBlue);

double d2 = Core.Mahalanobis(mu1, mu0, invcovar);
2015-10-06 07:18:58 -0500 received badge  Enthusiast
2015-09-30 08:12:42 -0500 asked a question OpenCV4Android - Utils.loadResource loading in a 48bit image
 private Mat loadMatFromResource(int resource)
{
    Mat image = new Mat();

    try
    {
        image = Utils.loadResource(getApplicationContext(), resource, Highgui.CV_LOAD_IMAGE_UNCHANGED);
    }
    catch(IOExecption e)
    {
        Log.e(TAG, "IOExecption: " + e);
    }

    return image;
}

Now that kind of works... As in the above code does load in an image but it's loading in a 24bit image as an CV_8UC3 (8-bits for 3 channels (RGB)). When I'm providing it a 48bit image.

Is there are way to improve what I have so it actually will load in the full 48bits?

Thanks.

2015-09-28 11:53:43 -0500 asked a question OpenCV4Android - Get 16bit pixel values?

Is there a way to get 16bit values back from a pixel on a Mat? Mat.get() seems to only return 8bit values... And I'd really like a more exact number there.

Thanks

2015-09-24 09:55:50 -0500 received badge  Editor (source)
2015-09-24 08:04:09 -0500 asked a question OpenCV4Android - balanceWhite()?

Does OpenCV4Android have a balanceWhite function? I know it's contained in xphoto but I can't seem to find that in the Java API docs.

Is xphoto in the OpenCV4Android Library? If it isn't is there another method I can use or do I need to roll my own?

I'm using OpenCV4Android 2.4.11