【发布时间】:2014-05-19 19:55:01
【问题描述】:
我目前正在尝试创建一些 Java 代码来执行连接组件标签。
这里有一个关于它是如何工作的解释:http://aishack.in/tutorials/labelling-connected-components-example/
我已经在我的代码中找到了一个点,我正在查看一个像素并比较它周围的所有像素。我现在完全迷失了,我很难找出我用什么来存储像素是背景像素、以前发现的对象还是新对象。
我的问题是我应该调用或更改什么来允许我存储这些值。提前谢谢你。
(为了清楚起见,这是我的代码)
private void connectedComponentLabelling(ImageProcessor ip) {
int w = ip.getWidth();
int h = ip.getHeight();
int background = 255; //black
int foreground = 0; //white
int nextLabel = 1;
int [] linked;
int [][] NEIGHBOUR = new int [w][h];
for (int v=0; v<h; v++){
for (int u=0; u<w; u++){
if (ip.getPixel(v,u) != background){
for (int j=-1; j<=1; j++){
for (int i=-1; i<=1; i++){
int p = ip.getPixel(v+j, u+i);
if (p != background){
//linked[nextLabel];
NEIGHBOUR[v][u] = nextLabel;
}else{
nextLabel++;
}
}
}
}
}
}
【问题讨论】:
标签: java components