Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算二值图像中每个区域的像素数(Android)_Android_Image Processing_Computer Vision - Fatal编程技术网

如何计算二值图像中每个区域的像素数(Android)

如何计算二值图像中每个区域的像素数(Android),android,image-processing,computer-vision,Android,Image Processing,Computer Vision,我给两个物体拍照。I去除噪声,将RGB转换为灰度,提高对比度,并将灰度转换为二进制。最后,我想计算每个区域可以看到图片的像素数。我如何计算android中的每个区域?我必须提前检测正方形区域吗?以及使用像素正方形区域减少像素总数?有什么想法吗?我应该使用什么算法 好的,例如,如果您想“计数”所有黑色像素,您需要在图像上执行两个循环(一个水平循环,一个垂直循环)。大概是这样的: Drawable d = imageView.getDrawable(); Bitmap bitmap = ((Bitm

我给两个物体拍照。I去除噪声,将RGB转换为灰度,提高对比度,并将灰度转换为二进制。最后,我想计算每个区域可以看到图片的像素数。我如何计算android中的每个区域?我必须提前检测正方形区域吗?以及使用像素正方形区域减少像素总数?有什么想法吗?我应该使用什么算法

好的,例如,如果您想“计数”所有黑色像素,您需要在图像上执行两个循环(一个水平循环,一个垂直循环)。大概是这样的:

Drawable d = imageView.getDrawable();
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
for(int x = 0; x < imageView.getWidth();x++){
    for(int y = 0; y < imageView.getWidth();y++){
        int color = bitmap.getPixel(x, y);
        // here you have the color
    }
}
Drawable d=imageView.getDrawable();
位图位图=((BitmapDrawable)d).getBitmap();
对于(int x=0;x

您可以反转图像,然后将轮廓边界矩形中的每个像素相加。由于黑色=0,白色=1,反转黑色的总和将是轮廓中的黑色像素数。只要您的边界矩形中没有其他轮廓,它就可以正常工作。

您能展示一下您尝试过的步骤吗?谢谢。但在这种情况下,我想计算每个区域的像素数,正方形区域的像素数和其他区域的像素数。不计算所有的黑色像素。我有一个问题,从二值图像中的两个对象计算每个区域。你能帮我解决我的问题吗?非常感谢您的关注首先,您的图像必须是“可绘制”的实例,好吗?图像总是有两种颜色?