如何计算图像像素
how to count image pixel
我想知道如何应用这个"水平位置,从图像左边缘开始计算像素,最小矩形框的中心,可以用框内所有"上"像素绘制。请注意,框==图像
使用 OpenCV 代码
任何帮助
我不确定我是否正确理解了你,但这是我计算图像像素的建议。
我在下面使用的垫子图像是灰度的,如果要计算 3 通道 RGB 图像上的像素,则需要拆分其通道并单独处理它们。
Mat image= imread( "C:\1.jpg" );// load your image by giving the path here.
Mat grayscale_image;
cvtColor(image,grayscale_image,CV_RGB2GRAY);/* this converts "image" to
"grayscale_image" which is a one channel image.*/
//Now you can play with its pixels
int sumPixels=0;
for(int i=0; i<image.rows; i++)
{
for(int j=0;j<image.cols;j++)
sumPixels+=image.at<uchar>(i,j);
}
/* value of a pixel on a gray scale image(if it is a 8 bit image) varies between
0 and 255. "sumPixels" variable will contain the total pixel values of image.*/
此代码尝试通过将每列的所有白色像素相加来查找每行的白色像素。
int sum_of_x = 0;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
if(data[i*step + j]==255)
sum_of_x = sum_of_x + 1;
}
cout<<"Row No #"<<i<<", White Pixel at each ROW = "<<sum_of_x<<endl;
}
干杯。
相关文章:
- 访问随机图像像素的快速方法,最多一次
- 计算另一个图像像素满足条件的像素值的平均值
- OPENCV C .在for循环中在不同的图像像素上绘制一个圆圈(应在每个循环运行时将图像打开)
- 尝试递归地重新绘制所有图像像素
- 访问图像像素;MatIterator_<> 和 Mat::at 运算符的比较
- 在OpenCV中使用遮罩和ROI计算轮廓内浮器的图像像素值(例如平均值)
- C++在编译时将图像像素嵌入向量中
- 通过二进制处理图像像素
- OpenCV读取图像像素值
- 如何计算图像像素
- 图像像素的总和
- big_endian和little_endian的图像像素读取
- 如何使用Imebra库修改DICOM文件中的图像像素
- 为什么图像像素应该平铺在内存的 WORD 单元中
- 检查图像像素强度的方法
- 获取具有K近邻的特定像素值的所有图像像素
- OpenCV积分图像像素访问错误
- 三维相机对二维图像像素的变换效果
- 获取投影图像像素位置
- 使用掩码获取图像像素