• 大小: 16KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: C/C++
  • 标签:

资源简介

在传统SRG算法的基础进行改进,利用颜色空间的像素与其邻域的颜色差异及相对欧式距离自动选择种子;应用SRG技术由已知的种子生长出初始分割区域;根据融合了颜色空间和邻接关系的区域距离对初始区域进行分级合并。

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “iostream.h“
#include “stdio.h“
#include “stdlib.h“
#include “string.h“
#include “cv.h“
#include “highgui.h“
#include “math.h“
#include “fstream.h“

#define height 227
#define width 303
int  K;//种子区域的数量
int DX[4]={100-1};
int DY[4]={01-10};
int Di[8]={100-1-111-1};
int Dj[8]={01-10-1-111};
double Data[width][height][3];//原图像的BGR值
double pData[width][height][3];//转化后的图像像素值
double SD[width][height][3];//Lab的标准方差
double D[width][height];//归一化总的方差
double ccenter[width*height][3];//种子区域的平均像素值
double limen;//相似度阈值
double limen_dis=0.022;//距离阈值
double H[width][height];//相似度
double d_max[width][height];//与邻域的最大距离
int c_seed[width*height][2];//种子的坐标
int seed_num;//种子的数量
int Flag[width][height]={0};//标记图像各点是否列入数组T中
int Lable[width][height]={0};//标记图像各点所处的种子区域
double Distance[width*height];//某像素点与其邻域的最大距离
int T_num=0;//数组T中像素点的数量
int T[height*width][3];//数组T用于存放待处理的像素点,分别存放点的横坐标、纵坐标以及与种子区域的距离
int Top[width*height]={0};//种子区域中像素点的数量
double Low_num[width*height]={0};
double Low_sum[width*height]={0};
double diff[width*height];
double ostu[width*height];
double sum[width][height][3];
double **dr;//相邻区域的距离
//距离最短的相邻区域的区域号
int min_x;
int min_y;

//函数声明
double dis(double *bdouble *c);//定义相对欧式距离
void remove_back(int a);//将数组T中的元素依次向后移一位
void remove_ahead();//将数组T中的元素依次向前移一位
void insert_T(int xxint yyint idouble d);//将某一像素点插入数组T中
void update_center(int iint xint y);//重新计算种子区域的像素平均值
void init();//将所有种子区域的邻域象素记录在数组T中,按其与区域距离的大小升序排列
void process();//处理数组T中的第一个像素点,并将其归入某一种子区域
void sign();//将各种子区域的边界标记出来
//定义的两个区域的颜色距离
double color_dis(int num1int num2)
{
double mntdis;
m=n=t=0;
for(int i=0;i<3;i++)
{
n+=(ccenter[num1][i]-ccenter[num2][i])*(ccenter[num1][i]-ccenter[num2][i]); 
    m+=ccenter[num1][i]*ccenter[num1][i];
t+=ccenter[num2][i]*ccenter[num2][i];
}
n=sqrt(n);
m=sqrt(m);
t=sqrt(t);
if(m>t) dis=((Top[num1]*Top[num2])/(Top[num1]+Top[num2]))*(n/t);
else
dis=((Top[num1]*Top[num2])/(Top[num1]+Top[num2]))*(n/m);
return dis;
}
//计算所有相邻区域的距离
void caculate_dis()
{
int ijkxxyyid1id2;
dr=new double* [sizeof(double*)*K];
for(i=0;i
dr[i]=new double[sizeof(double)*K];
}
for(i=0;i
for(k=0;k dr[i][k]=0;
}
for(j=2;j {
for(i=2;i {
for(k=0;k<4;k++)
{
xx=i+DX[k];
yy=j+DY[k];
if(Lable[i][j]!=Lable[xx][yy])
{
id1=Lable[i][j]-1;
id2=Lable[xx][yy]-1;
dr[id1][id2]=color_dis(id1id2);
}
}
}
}
}
//寻找相邻区域的最短距离
 double min_dis()
 {
 int ij;
 double min;
 for(i=0;i {
for(j=i+1;j {
if(dr[i][j]!=0)
{
min=dr[i][j];
break;
}
}
 }
 for(i=0;i {
for(j=i+1;j {
if(dr[i][j] {
min=dr[i][j];
min_x=i;
min_y=j;
}
}
 }
return min;
 }
//区域合并后,将相关数据更新

评论

共有 条评论

相关资源