资源简介
图像处理连通域算法 c++ ,vc 6.0

代码片段和文件信息
/* Copyright (c) 2001 C. Grigorescu */
#include
#include
#include “ByteImage.h“
#include “IntImage.h“
#include “ConnectedComponents.h“
int ConnectedComponents(IntImage &img CONN_TYPE connectivity IntImage &out)
{
out = img;
int nr_comp = ConnectedComponents(out connectivity);
return (nr_comp);
}
int ConnectedComponents(ByteImage &img CONN_TYPE connectivity IntImage &out)
{
out.makeImage(img.getWidth() img.getHeight());
for (int i=0;i for (int j=0;j out[i][j] = img[i][j];
int nr_comp = ConnectedComponents(out connectivity);
return (nr_comp);
}
int ConnectedComponents(IntImage &img CONN_TYPE connectivity = FOUR)
{
/*
Computes “Connected Components“ using Tarjan‘s Union-Find algorithm;
the result is returned in the same buffer as gray_level image with values
equal to the label of the component.
Returns: the number of connected components */
int l p r curlab=1;
int i j n_up n_left n_right;
int lab[img.getSize()];
int *pixels = img.getPixels();
/* Start Tarjan‘s algorithm */
int w = img.getWidth();
int h = img.getHeight();
for (i=0; i for (j=0; j if (pixels[i*w+j] >= 0) {
p = pixels[i*w+j];
l = i*w+j;
lab[l] = l;
n_up = i-1;
if ((n_up >= 0) && (pixels[n_up*w+j] == p))
Union(l n_up*w+j lab);
n_left = j-1;
if ((n_left >= 0) && (pixels[i*w+n_left] == p))
Union(l i*w+n_left lab);
n_right = j+1;
if (connectivity == EIGHT) {
if ((n_right < w) && (n_up >= 0) &&
(pixels[n_up*w+n_right] == p))
Union(l n_up*w+n_right lab);
if ((n_left >= 0) && (n_up >= 0) &&
(pixels[n_up*w+n_left] == p))
Union(l n_up*w+n_left lab);
}
}
else
lab[i*w+j] = 0;
}
for (i=0; i for (j=0; j r = lab[i*w+j];
if (r == i*w+j) {
pixels[i*w+j] = curlab;
lab[i*w+j] = curlab++;
} else {
lab[i*w+j] = lab[r];
pixels[i*w+j] = lab[r];
}
}
return (curlab-1);
}
int Root(int r int *lab int size_x int size_y)
{
int p;
p = lab[(r/size_x)*size_x+(r%size_x)];
while (p != r) {
r = p;
p = lab[(r/size_x)*size_x+(r%size_x)];
}
return p;
}
int FindRoot(int r int *lab)
{
if ( r != lab[r] )
lab[r] = FindRoot(lab[r] lab);
return lab[r];
}
void Union(int x int y int *lab)
{
int r0 r1;
r0 = FindRoot(x lab);
r1 = FindRoot(y lab);
if (r0 > r1)
lab[r0] = r1;
else
lab[r1] = r0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2508 2001-08-08 23:53 ConnectedComponents.h
文件 679 2004-03-25 09:35 EightConnectedSE.hpp
文件 671 2004-03-25 09:35 FourConnectedSE.hpp
文件 2619 2001-07-17 19:15 ConnectedComponents.cpp
文件 886 2004-03-25 09:35 EightConnectedSE.cpp
文件 755 2004-03-25 09:35 FourConnectedSE.cpp
----------- --------- ---------- ----- ----
8118 6
- 上一篇:单片机c头文件at89X51/AT89X52
- 下一篇:IP流量检测
相关资源
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 用C语言进行数字图像处理
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
评论
共有 条评论