资源简介

在一个经典的k-means算法程序上的改进,能够对图像进行分层输出,最大分层数位32.程序采用的是vs2005实现,内附有实验源码及实验结果图像,包括分2、4、8、32层的结果,希望对图像分割感兴趣的朋友有所帮助。

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 

#include “bmp.h“

using namespace std;

// **************************************************
// System Constant Definition
// **************************************************

// **************************************************
// Structures
// **************************************************

typedef struct MyBITMAPFILEHEADER_type {
char B;
char M;
unsigned int bfSize;
unsigned short int bfReserved1;
unsigned short int bfReserved2;
unsigned int bfOffBits;
char buf[14];
} MyBITMAPFILEHEADER;

typedef struct MyBITMAPINFOHEADER_type {
unsigned int biSize;
unsigned int biWidth;
unsigned int biHeight;
unsigned short int biPlanes;
unsigned short int biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXPelsPerMeter;
unsigned int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
char buf[40];
} MyBITMAPINFOHEADER;

typedef struct MyRGBQUAD_type {
unsigned char palette[256][4];
char buf[256*4];
} MyRGBQUAD;

typedef unsigned char *ImageData;

typedef struct MyBITMAP_type {
MyBITMAPFILEHEADER file_header;
MyBITMAPINFOHEADER info_header;
MyRGBQUAD rgbquad;
ImageData image_data;
int bmp_gap;
} MyBITMAP;

// **************************************************
// Prototypes
// **************************************************

static void load_bmp_image(char filename[] MyBITMAP *bmp);
static void save_bmp_image(char filename[] MyBITMAP *bmp);

inline static void get_bmp_pixel(MyBITMAP *bmp int x int y int* color_r int* color_g int* color_b);
inline static void set_bmp_pixel(MyBITMAP *bmp int x int y int color_r int color_g int color_b);

// **************************************************
// Globals
// **************************************************

static MyBITMAP bmp_tmp;
static MyBITMAP bmp_cell;
static int bmp_gap = 0;

// **************************************************
// Image Tools
// **************************************************

// **************************************************
// open_bmp
// Open and load a bitmap image file into memory (3 RGB arrays of 1024x1024).
// **************************************************

void open_bmp(char filename[] unsigned int bmp_r[MaxBMPSizeX][MaxBMPSizeY]  unsigned int bmp_g[MaxBMPSizeX][MaxBMPSizeY] unsigned int bmp_b[MaxBMPSizeX][MaxBMPSizeY] int& width int& height)
{
int r g b;
int x y;

load_bmp_image(filename &bmp_tmp);

width  = bmp_tmp.info_header.biWidth;
height = bmp_tmp.info_header.biHeight;

cout<<“width:“<
cout<<“height:“<
if ((width > MaxBMPSizeX) || (height > MaxBMPSizeY)) {
cout << “该图片大小超过处理范围“ << endl;
exit(1);
}

for (x = 0; x <= width - 1; x++) {
for (y = 0; y <= height - 1; y++) {
get_bmp_pixel(&

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     348160  2009-12-22 11:49  kmeans_image\debug\kmeans_image.exe

     文件    1217116  2009-12-22 11:49  kmeans_image\debug\kmeans_image.ilk

     文件    1797120  2009-12-22 11:49  kmeans_image\debug\kmeans_image.pdb

     文件      14928  2009-12-22 10:52  kmeans_image\kmeans_image\bmp.cpp

     文件       1243  2009-12-21 10:53  kmeans_image\kmeans_image\bmp.h

     文件     111526  2009-12-22 10:52  kmeans_image\kmeans_image\Debug\bmp.obj

     文件       7316  2009-12-22 11:49  kmeans_image\kmeans_image\Debug\BuildLog.htm

     文件        145  2009-12-22 11:49  kmeans_image\kmeans_image\Debug\kmeans_image.exe.intermediate.manifest

     文件     184340  2009-12-22 11:49  kmeans_image\kmeans_image\Debug\k_means_image.obj

     文件         67  2009-12-22 11:49  kmeans_image\kmeans_image\Debug\mt.dep

     文件     216064  2009-12-22 11:49  kmeans_image\kmeans_image\Debug\vc80.idb

     文件       3205  2009-12-19 16:53  kmeans_image\kmeans_image\kmeans_image.vcproj

     文件       1411  2009-12-22 21:17  kmeans_image\kmeans_image\kmeans_image.vcproj.JEROSON.lijiazhi.user

     文件       1427  2009-12-22 08:04  kmeans_image\kmeans_image\kmeans_image.vcproj.WWW-C9B62EF8BB0.Administrator.user

     文件       7166  2009-12-27 15:53  kmeans_image\kmeans_image\k_means_image.cpp

     文件       7042  2009-12-22 11:53  kmeans_image\kmeans_image\k_means_image.cpp.bak

     文件    1379328  2009-12-22 21:17  kmeans_image\kmeans_image.ncb

     文件        901  2009-12-19 16:48  kmeans_image\kmeans_image.sln

    ..A..H.     19456  2009-12-22 21:17  kmeans_image\kmeans_image.suo

     文件    2359350  2009-12-22 11:35  kmeans_image\resource\2\2.bmp

     文件    2359350  2009-12-22 11:38  kmeans_image\resource\2\xiamen_0.bmp

     文件    2359350  2009-12-22 11:38  kmeans_image\resource\2\xiamen_1.bmp

     文件    2359350  2009-12-22 11:38  kmeans_image\resource\2\xiamen_s_8.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\32.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_0.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_1.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_10.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_11.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_12.bmp

     文件    2359350  2009-12-22 11:45  kmeans_image\resource\32\xiamen_13.bmp

............此处省略63个文件信息

评论

共有 条评论