本文介绍了图像中白色像素的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我的图像只包含白色和黑色像素,如何找到白色像素的中心
hi all
i have an image contains white and black pixels only, how can i find the center of white pixels
推荐答案
//the width and height of your screen.
int width = 640;
int height = 480;
//The average white pixels of x and y.
int average_x;
int average_y;
//counts the x and y axis.
int count_x = 0;
int count_y = 0;
//tells you how many white pixels there are.
int count = 0;
//Make a for loop for the x axis and the y axis.
for(int a = 0; a < width; a = a+1;){
for(int b = 0; a < height; b = b+1;){
//If the pixel is white
if(pixel(a, b) == white)
{
count = count+1;
count_x = count_x+a;
count_y = count_y+b;
}
}
}
//Calculate the average x and y axis for the white pixels.
average_x = count_x/count;
average_y = count_y/count;
平均值_x和平均值_y是您想要的中心轴.
The average_x and average_y are the center axis you want.
这篇关于图像中白色像素的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!