资源简介
这是分水岭算法的纯C实现,针对8位灰度图做处理。结果和Matlab自带分水岭算法效果类似。
代码片段和文件信息
#include “waterthreshold.h“
#include “malloc.h“
#include “stdio.h“
#include “FIFO.H“
#include “math.h“
#include “filter.h“
#include “debug.h“
#define INIT -1
#define MASK -2
#define ENFIFOED -3 //表示该像素标号是MASK,并且已经被加入到队列当中了
#define WSHED 0
#define FICTITIOUS 0xFFFF
const QElemType BREAKPOINT={FICTITIOUSFICTITIOUS};
int * PixLabel=0;
PixInfor * SortedPixTable=0;
GrayStartPosition PixGrayStartPosition[256]={0};
#define PixAmount(x) (PixGrayStartPosition[x].amount) //灰度为x的像素的总个数
#define PixStart(x) (PixGrayStartPosition[x].start) //SortedPixTable中第一个灰度为x的像素所处位置
#define PixSet(x) (SortedPixTable+PixStart(x)) //灰度为x的像素集合
#define PixRow(x) ((x).row)
#define PixColumn(x) ((x).column)
/*******私有变量申明,仅用于本文件内私有函数间参数传递,以减少参数个数*********/
static Uint16 ImgWidth;
static Uint16 ImgHeight;
static FIFO queue;
static int CurLabel;
static int ErrorCode;
/*******私有函数申明,这些函数仅用于本文件内*************************/
static void SortPixs(Uint8 * inImgUint16 WidthUint16 Height);
static int GetNumberOfNeighbourWithPositiveLabel(Uint16 rowUint16 column);
static int doLabelPix(QElemType Pix);
static void ShowResult(Uint8 * outImgUint8 * inImgUint16 WidthUint16 Height);
static void WaterThreshold(Uint8 * inImg Uint16 WidthUint16 Height);
static void WTInit(Uint16 WidthUint16 Height);
static int CreateNewBasin(QElemType CurrentPix);
static int Grad(Uint8 * inImgint columnint row);
static void QuantizeImage(Uint8 * inImgUint8 * outImgUint16 WidthUint16 HeightUint8 Qsize);
static void ReverseImage(Uint8 * inImgUint8 * outImgUint16 WidthUint16 Height);
void ReverseImage(Uint8 * inImgUint8 * outImgUint16 WidthUint16 Height)
{
int i=0;
int imgsize = Width*Height;
for(i=0;i {
outImg[i] = 255-inImg[i];
}
}
void QuantizeImage(Uint8 * inImgUint8 * outImgUint16 WidthUint16 HeightUint8 QSize)
{
int i=0;
int imgsize = Height*Width;
for(i=0;i {
outImg[i] = (inImg[i]/QSize)*QSize;
}
}
void WTInit(Uint16 WidthUint16 Height)
{
int * ptr;
int ij;
SortedPixTable = (PixInfor*)malloc(sizeof(PixInfor)*((Width-2)*(Height-2)));
PixLabel = (int*)malloc(sizeof(int)*Width*Height);
ptr = PixLabel;
for(i=0;i {
for(j=0;j {
if( i==0 || j==0 || i==Height-1 || j==Width-1 )
{
*ptr = WSHED ; //将图像边缘像素的标号设为WSHED
}
else
{
*ptr = INIT;
}
ptr++;
}
}
}
void WTDeInit()
{
free(SortedPixTable);
free(PixLabel);
}
void WaterThrdMain(Uint8 * inImg Uint8 * outImgUint16 WidthUint16 Height)
{
WTInit(WidthHeight);
// ReverseImage(inImginImgWidthHeight);
// SmoothImage(inImgWidthHeight);
// FiltNoise(inImgWidthHeight);
// FiltNoise(inImgWidthHeight);
QuantizeImage(inImginImgWidthHeight6);
WaterThreshold(inImg WidthHeight);
ShowResult(outImginImgWidthHeight);
WTDeInit();
}
void ShowResult(Uint8 * outImgUint8 * inIm- 上一篇:班级通讯录管理系统C语言课程设计
- 下一篇:语音信号处理与提取.zip
相关资源
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
- 尚观培训linux许巍老师关于c语言的课
川公网安备 51152502000135号
评论
共有 条评论