目录
- 一、创建用于分类的高斯混合模型函数
- 二、代码和效果展示
- 三、相关函数
一、创建用于分类的高斯混合模型函数
create_class_gmm( : : NumDim, NumClasses, NumCenters, CovarType, Preprocessing, NumComponents, RandSeed : GMMHandle)
create_class_gmm创建用于分类的高斯混合模型(GMM)。
NumDim指定了特征空间的维数,
NumClasses指定了类别的数量。
NumCenters指定了每一类高斯中心的数量。不仅可以指定要使用的中心数量,还可以根据参数的数量指定中心数量的上下界:
一个参数:
该参数指定要用于所有类的中心的确切数量。
两个参数:
对于所有类,第一个参数确定最小中心数,第二个参数确定最大中心数。
2*NumClasses个参数:
分别地,每个第一个参数决定每个类的最小中心数,每个第二个参数决定每个类的最大中心数
CovarType:指定了协方差矩阵的类型。Cj协方差矩阵,Pj混合系数,中心mj
CovarType = ‘spherical’
CovarType = ‘diag’,
CovarType = ‘full’,Cj是一个正定矩阵
概率密度函数 p(x)
二、代码和效果展示
* This example program shows how to segment an RGB image with a GMM
* classifier. The classifier is trained with four different colors. In contrast to
* other classifiers, colors that have not been trained can be rejected easily.
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 735, 485, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_colored (6)
dev_set_line_width (3)
read_image (Image, 'patras')
dev_display (Image)
Color := ['indian red', 'cornflower blue', 'white', 'black', 'yellow']
* Create regions that contain the training samples of the four classes
gen_rectangle1 (Sea, 10, 10, 120, 270)
gen_rectangle2 (Deck, [170, 400], [350, 375], [-0.56, -0.75], [64, 104], [26, 11])
union1 (Deck, Deck)
gen_rectangle1 (Walls, 355, 623, 420, 702)
gen_rectangle2 (Chimney, 286, 623, -0.56, 64, 33)
concat_obj (Sea, Deck, Classes)
concat_obj (Classes, Walls, Classes)
concat_obj (Classes, Chimney, Classes)
dev_set_color (Color[0])
dev_display (Deck)
dev_set_color (Color[1])
dev_display (Sea)
dev_set_color (Color[2])
dev_display (Walls)
dev_set_color (Color[3])
dev_display (Chimney)
Message := 'Training regions for the color classifier'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Create the classifier and add the samples.
create_class_gmm (3, 4, [1, 10], 'full', 'none', 2, 42, GMMHandle)
add_samples_image_class_gmm (Image, Classes, GMMHandle, 2.0)
dev_display (Image)
Message := 'Training ...'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* Train the classifier.
train_class_gmm (GMMHandle, 500, 1e-4, 'uniform', 1e-4, Centers, Iter)
Message := Message + ' ready.'
Message[1] := 'Segment image using the classifier ...'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* Segment (classify) the image.
classify_image_class_gmm (Image, ClassRegions, GMMHandle, 0.0001)
region_to_mean (ClassRegions, Image, ImageClass)
dev_display (ImageClass)
Message[1] := Message[1] + ' ready.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
create_class_gmm ->add_samples_image_class_gmm ->train_class_gmm ->classify_image_class_gmm ->region_to_mean
创建一个gmm分类器,对四个不同颜色的区域进行分类。
三、相关函数
add_samples_image_class_gmm //将图像中的训练样本添加到高斯混合模型的训练数据中。
train_class_gmm //训练一个高斯混合模型
classify_image_class_gmm //用高斯混合模型对图像进行分类。
region_to_mean //用平均灰度值绘制区域