资源简介
层次聚类.zip
代码片段和文件信息
#include
#include
#include
#include
using namespace cv;
using namespace std;
class center //聚类中心点
{
public:
int center_r;
int center_g;
int center_b;
int center_num; //此类的像元个数
center()
{
center_r = 0; center_g = 0; center_b = 0;
}
};
int num = 3; //聚类数目
int main()
{
//显示RGB图像并显示
IplImage* rgb = cvLoadImage(“1.jpg“ 1);
std::cout << “图片高像素:“ << rgb->height << endl; //33
std::cout << “图片宽像素“ << rgb->width << endl; //50
cvNamedWindow(“RGB“ WINDOW_NORMAL);
cvShowImage(“RGB“ rgb);
//int **type = new int *[rgb->height];
//for (int i = 0; i < rgb->height; i++)
// type[i] = new int[rgb->width];
int height = 33;
int width = 50;
//图像转换:RGB对应三个二维矩阵
double ** r = new double *[33]; //红波段
for (int i = 0; i < 33; i++)
r[i] = new double[50];
double ** g = new double *[33]; //绿波段
for (int i = 0; i < 33; i++)
g[i] = new double[50];
double ** b = new double *[33]; //蓝波段
for (int i = 0; i < 33; i++)
b[i] = new double[50];
//获取图像的颜色值
for (int i = 0; i < 33; i++)
{
for (int j = 0; j < 50; j++)
{
CvScalar s = cvGet2D(rgb i j); //i代表y轴,即height;j代表x轴,即width
b[i][j] = s.val[0]; //将颜色值导入矩阵
g[i][j] = s.val[1];
r[i][j] = s.val[2];
}
}
//将每一个像元存为一个类
center lei[1650];
int k = 0;
for (int i = 0; i < 33; i++)
{
for (int j = 0; j < 50; j++)
{
lei[k].center_r = r[i][j];
lei[k].center_g = g[i][j];
lei[k].center_b = b[i][j];
lei[k].center_num = 1;
k++;
}
}
int dis;//欧氏距离的平方
int tmpr tmpg tmpb;
int tmpi = 0;
int tmpj = 0;
int centernum = 1650; //现在分成多少类
while (centernum > num)
{
int distmp = 300000;
for (int i = 0; i < 1650; i++)//找出类间最短距离
{
for (int j = i + 1; j < 1650; j++)
{
tmpr = (lei[i].center_r - lei[j].center_r)*(lei[i].center_r - lei[j].center_r);
tmpg = (lei[i].center_g - lei[j].center_g)*(lei[i].center_g - lei[j].center_g);
tmpb = (lei[i].center_b - lei[j].center_b)*(lei[i].center_b - lei[j].center_b);
dis = tmpr + tmpg + tmpb;
if (dis < distmp)
{
distmp = dis;
tmpi = i;
tmpj = j;
}
}
}
//合并距离最短的两个类
for (int i = 0;i<)
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-22 17:19 层次聚类\
目录 0 2018-04-20 10:33 层次聚类\.vs\
目录 0 2018-04-20 10:33 层次聚类\.vs\层次聚类\
目录 0 2018-04-20 10:33 层次聚类\.vs\层次聚类\v14\
文件 19456 2018-04-22 17:19 层次聚类\.vs\层次聚类\v14\.suo
目录 0 2018-04-20 13:17 层次聚类\Debug\
目录 0 2018-04-22 15:52 层次聚类\层次聚类\
文件 19595264 2018-04-22 17:19 层次聚类\层次聚类.sdf
文件 1318 2018-04-20 10:33 层次聚类\层次聚类.sln
目录 0 2018-04-20 13:17 层次聚类\层次聚类\Debug\
目录 0 2018-04-20 13:17 层次聚类\层次聚类\Debug\层次聚类.tlog\
文件 7381 2018-04-22 11:25 层次聚类\层次聚类\层次聚类.vcxproj
文件 944 2018-04-22 11:25 层次聚类\层次聚类\层次聚类.vcxproj.filters
文件 2471 2018-04-22 15:52 层次聚类\层次聚类\源.cpp
相关资源
- 英文版uml
- password_silence_4090716.zip
- 离散数学及其应用.rar
- SFHelper-Setup.exe
- STM32F103双ADC模式同步采集两通道电压
- DLT645_2007forkeil4.rar
- 1117325模型车牌生成器.rar
- _61850规约服务.pdf
- CFA_2018_Level_1_Schweser_Quicksheet.pdf
- 10519365.zip
- Imagis_CN——适普三维地理信息系统.
- Linearalgebrasolutionmanual.pdf
- SAPERPHCM葵花宝典系列之咨询指南(电
- Groovy-in-Action[文字版][中文].pdf
- tianshiqqjiedong.zip
- SysCalc4.rar
- shaanxizm_6931461.zip
- 网络调试助手.7z
- IDM器-绿色版.7z
- 线性代数.zip
- UCI.rar
- wKh2BFxCHryAAQh9AEg2DAzxD_o173.pdf
- ComputerSystemsAProgrammersPerspective(3rd)
- BT3-BT4.rar
- MIL-STD-1760E-2007_Aircraft_Store_Electrical_I
- UDS14229入门视频配套Pdf.zip
- DevExpressv15.2.xzh-CHS汉化包(完美汉化)
- bs_student_score_sys.rar
-
haoman_ba
se.rar - 知识付费阅读店铺5.1.0.zip
评论
共有 条评论