图像中白色像素的中心 [英] the center of white pixels in image

查看:108
本文介绍了图像中白色像素的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我的图像只包含白色和黑色像素,如何找到白色像素的中心

hi all
i have an image contains white and black pixels only, how can i find the center of white pixels

推荐答案

如果这是重心:

首先,定义一些任意点(例如,在中心),并计算它们相对于该点的位置,并按其质量加权,然后将其分配给1.然后按照以下算法进行操作:http://en.wikipedia.org/wiki/Center_of_mass [
If this is a center of gravity to be found:

First, define some arbitrary point (say, in the center) and calculate their positions relative to this points, weighted by their masses, which you can assign to 1. Then follow this algorithm: http://en.wikipedia.org/wiki/Center_of_mass[^]. That''s it.

—SA


[更新]

我应该做的是:

[UPDATED]

What i should do is:

//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.



怎么样 (sum(x)/count(x),sum(y)/count(y))
How about
(sum(x)/count(x), sum(y)/count(y))


这篇关于图像中白色像素的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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