如何在Android OpenCV中执行图像RGB标准化? [英] How to perform Image RGB Normalization in Android OpenCV?

查看:160
本文介绍了如何在Android OpenCV中执行图像RGB标准化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行图像规范化,使用OpenCV 2.4.8为Android。我的测试设备是一个三星S3。



我写了一个JNI函数,如下所示执行图像规范化。



我的图像规范化定义如下:

  r'是255 * r /(r + g + b)
g'是255 * g /(r + g + b)
b'是255 * b /(r + g + b)

现在我需要实现这个。我已经写了一个函数来执行这个。这似乎不工作。我有信心我的应用程序的其他部分(即他们是没有bug)。只有这部分会导致问题。



我可能没有正确写入此功能。 Pls帮助。



我还附上了我的结果的屏幕截图。如果你看这个图像,只有一半的部分看起来规范化(但实际上没有规范化,它只是看起来那样)&另一半不是。为了解决这个问题,我尝试在for循环中更改cols的行,结果是一样的。





还会显示此代码。



期待一些帮助。 (FYI - 我是openCV的新手)。感谢您的理解。

  void NormalizeRGB(JNIEnv *,jobject,jlong​​ img)
{
Mat& imgM = *(Mat *)img;
vector< Mat> rgb;
int cols = imgM.cols;
int rows = imgM.rows;
for(int i = 0; i< rows; i ++)
{
for(int j = 0; j {
Vec3b bgrPixel = imgM.at< Vec3b>(i,j);
float total = bgrPixel.val [0] + bgrPixel.val [1] + bgrPixel.val [2] + 0.00001;
bgrPixel.val [0] =(uchar)255 * bgrPixel.val [0] / total;
bgrPixel.val [1] =(uchar)255 * bgrPixel.val [1] / total;
bgrPixel.val [2] =(uchar)255 * bgrPixel.val [2] / total;
imgM.at< Vec3b>(i,j)= bgrPixel;
}
}
}


解决方案>

我找到了我的问题的解决方案。



我试图使用这个函数来读取RGBA矩阵图像。一个RGBA矩阵图像是Vec4类型的。



我试图读它为一个Vec3〜这用来导致上述问题。



有了这个小小的变化,我就能得到预期的结果。


I am trying to perform image normalization, using OpenCV 2.4.8 for Android. My test device is a samsung S3.

I have written a JNI function as shown below to perform Image Normalization.

My definition of Image Normalization is as follows :

r' is 255* r/(r+g+b)
g' is 255* g/(r+g+b)
b' is 255* b/(r+g+b)

Now I need to implement this. And I have written a function to perform this. This doesnt seem to work. I am confident of my other portions of my App (i.e. they are bug free). Only this part causes a problem.

I may have not written this function properly. Pls help.

I have also attached a screenshot of my result. If you look at this image, only half portion looks normalized (but its actually not normalized, it just looks that way) & the other half is not. To fix this, I tried changing the rows with cols in the for-loop, and the result was the same.

The code for this is also presented.

Looking forward to some help. (FYI - I am totally new to openCV). Thanks for understanding.

void NormalizeRGB(JNIEnv*, jobject, jlong img)
{
    Mat& imgM  = *(Mat*)img;
    vector<Mat> rgb;
    int cols = imgM.cols;
    int rows = imgM.rows;
    for(int i = 0; i<rows; i++)
    {
        for(int j = 0; j<cols; j++)
        {
            Vec3b bgrPixel = imgM.at<Vec3b>(i, j);
            float total = bgrPixel.val[0] + bgrPixel.val[1] + bgrPixel.val[2] + 0.00001;
            bgrPixel.val[0] = (uchar) 255*bgrPixel.val[0]/total;
            bgrPixel.val[1] = (uchar) 255*bgrPixel.val[1]/total;
            bgrPixel.val[2] = (uchar) 255*bgrPixel.val[2]/total;
            imgM.at<Vec3b>(i, j) = bgrPixel;
        }
    }
}

解决方案

I found the solution to my problems.

I was trying to use this function to read an RGBA Matrix image. A RGBA Matrix image is of type Vec4.

I was trying to read it as a Vec3 ~ this used to cause the above problem.

With this small change, I was able to get my expected results.

这篇关于如何在Android OpenCV中执行图像RGB标准化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆