分水岭算法代码C++

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

弄了快一周了,分水岭算法代码终于出来了,这个算法太有难度了,通过自己敲一遍后,终于明白了为什么这么多人可以不厌其烦的该进这样经典的算法,他们对算法其实根本就没有改进和创新,只是对图像进行一些预处理和改变一下微分算子,其实最核心的还是分水岭算法本身,到至今为止我还没有看到有那篇论文能对分水岭算法本身有所改进,即便是效率上的提高也没有,甚至还没有发现有那个论文能把分水岭算法本身流程给描述清楚(也许没找到),通过这段时间的读论文,我发现很多论文只有开头(背景)和结论,中间过程就写得很随意,我想一个算法结论固然重要,但没有过程拿来的结论,那只能认为这是拍脑壳拍出来的。下面是我这几天用c++实现的分水岭算法,该算法基于的是LUV颜色空间,若有人要用,需要把RGB转化为LUV。

// ImageSegWatershed.cpp: implementation of the CImageSegWatershed class. //

///////////////////////////////////////////////////////////////////// /

#include "ImageSegWatershed.h"

#include "math.h"

#include "qstring.h"

#include "qqueue.h"

using namespace std;

#define MAXV 256

static const double

RGB[3][3]={ double(3.2405),double(-1.5371),double(-0.4985),

double(-0.9693),double(1.8760),doub

le(0.0416),

double(0.0556),double(-2040),double (1.0573)

};

static const int

XYZ[3][3]={4125,3576,1804,2125,7154,721,193,1192,9502};

static const double Xn=double(0.9505);

static const double Yn=double(1.0);

static const double Zn=double(1.0888);

static const double Un_prime=double(0.1978);

static const double Vn_prime=double(0.4683);

static const double Lt=double(0.008856);

///////////////////////////////////////////////////////////////////// /

// Construction/Destruction

///////////////////////////////////////////////////////////////////// /

CImageSegWatershed::CImageSegWatershed(int ImageHeight,int ImageWidth,int *ImageData)

{

PicHeight=ImageHeight;

PicWidth=ImageWidth;

PicData=ImageData;

luvData=new Myluv[ImageHeight*ImageWidth];

RgbtoLuvPcm(ImageData,ImageWidth,ImageHeight,luvData);

}

CImageSegWatershed::~CImageSegWatershed()

{

}

void CImageSegWatershed::WaterShedArith()

{

long Piclen=PicHeight*PicWidth;

int i,j,temp;

//梯度模数组

double *deltar=new double[Piclen];

//梯度角度数组

double *deltasita=new double[Piclen];

//个点标识数组

int *flag=new int[Piclen];

int *gradientfre=new int[256]; //图像中各点梯度值的频数

int *gradientadd=new int[257]; //各梯度起终位置 memset(gradientfre,0,sizeof(int)*256);

memset(gradientadd,0,sizeof(int)*257);

//得到各点的梯度值

GetGradient(deltar,deltasita);

//以下统计各梯度频数;

MyImageGraPt* graposarr = new MyImageGraPt[Piclen];

long xstart, imagepos, deltapos;

xstart = imagepos = deltapos = 0;

for (int y=0; y

{

xstart = y*PicWidth;

for (int x=0; x

{

deltapos = xstart + x;

if (deltar[deltapos]>255)

{

相关文档
最新文档