[Image segmentation] Image segmentation based on fuzzy clustering algorithm FCM [Matlab Issue 119] [Image Processing 36]

With the formation, development and deepening of fuzzy set theory, RusPini took the lead in proposing the concept of fuzzy division. With this as the starting point and foundation, fuzzy clustering theory and methods have developed rapidly. For different applications, people have proposed many fuzzy clustering algorithms. Typical ones are methods based on similarity relations and fuzzy relations, transitive closure methods based on fuzzy equivalence relations, maximum support tree methods based on fuzzy graph theory, and Methods such as convex decomposition based on data sets, dynamic programming and difficult to distinguish relations. However, none of the above methods can be applied to the situation of large data volume, and it is difficult to meet the occasions with high real-time requirements, so the actual application is not widespread.

Fuzzy cluster analysis can be roughly divided into three categories according to the clustering process:

(1) Classification based on fuzzy relationship: including pedigree clustering algorithm (also known as systematic clustering method), clustering algorithm based on equivalence relationship, clustering algorithm based on similarity relationship and graph theory clustering algorithm, etc. It is an earlier research method, but because it cannot be applied to large data volumes, it is not widely used in practice.

(2) Fuzzy clustering algorithm based on objective function: This method reduces the clustering analysis to a constrained nonlinear programming problem, and obtains the optimal fuzzy partition and clustering of the data set through optimization. The method is simple in design and has a wide range of problem solving. It can also be transformed into an optimization problem and solved with the help of classical mathematics nonlinear programming theory, and it is easy to implement on a computer. Therefore, with the application and development of computers, fuzzy clustering algorithms based on objective functions have become a new research focus.

(3) Fuzzy clustering algorithm based on neural network: It is a relatively late algorithm, mainly using competitive learning algorithm to guide the clustering process of the network.

Before introducing the algorithm, first introduce the knowledge of fuzzy sets.

HCM clustering algorithm

    首先说明隶属度函数的概念。隶属度函数是表示一个对象x 隶属于集合A 的程度的函数,通常记做μA(x),其自变量范围是所有可能属于集合A 的对象(即集合A 所在空间中的所有点),取值范围是[0,1],即0<=μA(x),μA(x)<=1。μA(x)=1 表示x 完全隶属于集合A,相当于传统集合概念上的x∈A。一个定义在空间X={x}上的隶属度函数就定义了一个模糊集合A,或者叫定义在论域X={x}上的模糊子集A’。对于有限个对象x1,x2,……,xn 模糊集合A’可以表示为:

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
FCM algorithm flow chart

The FCM algorithm is a relatively popular fuzzy clustering algorithm. The reasons are as follows: First, the fuzzy C-mean functional Jm is still a natural extension of the traditional hard C-mean functional J1; The mean functional J1 is a very widely used clustering criterion, and its theoretical research has been quite perfect, which provides good conditions for the research of Jm; mathematically, Jm and RS Hilbert The spatial structure (orthogonal projection and mean square approximation theory) is closely related, so it has a deeper mathematical foundation than other functionals. Finally, and most importantly, the objective function has not only obtained very successful applications in many fields, And based on the FCM algorithm, people proposed fuzzy clustering algorithms based on other prototypes, forming a large number of FCM-type algorithms: such as fuzzy C-line (FCL), fuzzy C-plane (FCP) and other clustering algorithms, respectively. Detection of subsets (or clusters) of linear and hyperplanar structure patterns.

FCM algorithm applied to color migration

    钱小燕等人将聚类算法应用到色彩迁移中,提出了一种基于图像模糊颜色聚类的自适应色彩迁移算法。该算法首先将源图像和目标图像分别转换到lαβ颜色空间:利用FCM 算法把源图像和目标图像划分为具有不同颜色特征的聚类,然后分析图像中的颜色特征:分别算出每个域的匹配权值,对每个目标图像的匹配权值,从源图像中选取一个最接近域作为最佳匹配域;最后根据目标图像各聚类域与源图像中的匹配域之间的关系,引入隶属度因子,两个域的处理结果分别进行加权平均,获得色彩迁移结果。使用FCM的思想对图像进行聚类域划分的思路是:设准备处理图像I的大小是S×H,即对颜色聚类颜色分析的个数是N,N = S×H,则图像I可表示成集合,I={p1 ,p2 ...,pn }。图像被分为c类,每个类的聚类中心为V={v1,v2 ...,vc },用uik表示像素pk隶属于聚类中心Vi的隶属度,定义图像的隶属度矩阵U。具体算法如下:

Step 1: Convert the source image and target image from RGB to lαβ space respectively.

Step 2: Determine the number c of clustering domains of the image to be processed, and then initialize the cluster centers. Assuming that the weighting index m=2, the maximum number of iterations of the processing is set to 50.

Step 3: When the number of iterations T is less than 50, the membership matrix is ​​calculated according to the initial cluster centers. If pk≠vi, then for all vi (i=1,2,...,C), use the following formula to calculate the membership matrix.

Insert picture description here
Insert picture description here

%% 程序分享 
%--------------------------------------
 
clear
close all
clc
%% %%%%%%%%%%%%%%%图像%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 I=imread('3096.jpg');
 
if size(I,3) == 3
   I=rgb2gray(I);
else
end
I=im2double(I);
figure;imshow(I);title('(a)原始图像')
% I=I;%不加噪声
%I=imnoise(I,'speckle',deta_2);
% I=imnoise(I,'salt & pepper',0.05); %加噪图
% I=imnoise(I,'gaussian',0,0.01); % 加高斯噪声
figure;imshow(I);title('(b)加噪图像');
imwrite(I,'2.jpg');
[m,n]=size(I);
%k 聚类数目
k=2;
% k=3;
 
I4 = I(:);  %% 将图像灰度按列排列
%% ------------------------ fcm算法------------------------
fcm_spatial_mean_label=zeros(m*n,1);
t=cputime;
tic;
[O2, U2, obj_fcn2] = fcm(I4, k);
toc;
time_fcm_spatial_mean=cputime-t;
%% 最大隶属度原则
maxU2 = max(U2);   %隶属度最大  
for j=1:k
    index = find(U2(j, :) == maxU2);  %隶属度最大对应的像素位置
    fcm_spatial_mean_label(index) = j;    
end
labels2=reshape(fcm_spatial_mean_label,[m n]);
labels2=uint16(labels2);
 
%% 显示聚类分割图
labels2(find(labels2==1))=0;
labels2(find(labels2==2))=255;
labels2(find(labels2==3))=180;
labels2(find(labels2==4))=100;
labels2=uint8(labels2);
figure;imshow(labels2,[]);title('(c)聚类分割图');
imwrite(labels2,'3.1.tiff','tiff','Resolution',300);%输出结果,保存为tif图片
 

Insert picture description here
Insert picture description here
Note: complete code or writing add QQ2449341593 past review
>>>>>>
[Matlab 024] [Image Processing 1] Image Compression of Matlab Image Processing Tutorial Series
[Matlab 025] [Image Processing 2] Matlab Image Processing Tutorial Series of image segmentation (1)
[Matlab 026] [Image processing 3] Matlab image processing tutorial series of image segmentation (2)
[Matlab 029] [Image processing 4] Matlab fingerprint recognition
[Matlab 030] [Image processing 5 】Bank card number recognition matlab source code
[Matlab 074 issue] [Image processing 6] [Image clustering] Based on FCM and improved FCM brain CT image clustering processing
[Matlab 075] [Image processing 7] [Image evaluation] Based on CCF Algorithmic image quality evaluation
[Matlab 076] [Image processing 8] [Image enhancement] CLAHE algorithm based on local contrast enhancement-histogram enhancement
[Matlab 077] [Image processing 9] [Image fusion] Image based on Frequency Partition Fusion
[Matlab Issue 078] [Image Processing 10] [Image Evaluation] Image quality evaluation based on svm without reference
[Image edge detection] Matlab source code for ellipse edge detection based on least squares method [Matlab Issue 079] [Image Processing 11]
[Image Encryption] Image encryption and decryption based on chaos system matlab source code with GUI [Matlab 080] [Image processing 12]
[Image processing] Based on DWT+DCT+PBFO to improve image watermark hiding and extraction matlab source code with GUI [Matlab 081] [Image processing 13】
[Image registration] Image registration matlab source code based on sift algorithm [Matlab 082] [Image processing 14]
[Image fusion] Image fusion matlab source code based on CBF algorithm [Matlab 083] [Image processing 15]
[Image segmentation] Image segmentation matlab source code based on random walk algorithm [Matlab 084] [Image processing 16]
[Image filtering] Image two-dimensional bilateral Gaussian filtering [Matlab 085] [Image processing 17]
[Image denoising] Based on adaptive morphology Image denoising [Matlab 086 period] [Image processing 18]
[Image enhancement] DEHAZENET and HWD based underwater scattering image enhancement [Matlab 087] [Image processing 19]
[Image enhancement] PSO optimization ACE image enhancement matlab Source code [Matlab 088] [Image processing 20]
[Image enhancement] Gray-scale image enhancement based on region similarity transformation function and dragonfly algorithm [Matlab 089] [Image processing 21]
[Image reconstruction] ASTRA algorithm for image reconstruction [Matlab 090 [Image processing 22]
[Image segmentation] Image segmentation based on quadtree matlab source code [Matlab 091] [Image processing 23]
[Image segmentation] Heart centerline extraction [Matlab 092] [Image processing 24]
[Image recognition ] Based on svm plant leaf disease detection and classification [Matlab 093] [Image processing 25]
[Image recognition] Based on template matching handwritten number recognition system GUI interface [Matlab 094] [Image processing 26]
[Image recognition] based on unchanged Moment’s digital verification code recognition with GUI interface [Matlab 095] [Image processing 27]
[Image recognition] Barcode recognition system [Matlab 096] [Image processing 28]
[Image recognition] RMB recognition system based on RGB and BP neural network with GUI interface [Matlab 097] [Image processing 29]
[Image recognition] Matlab source code recognition based on cnn convolutional neural network [Matlab 098] [Image Processing 30]
[Image classification] Classification of remote sensing images based on extreme learning classifier [Matlab 099] [Image processing 31]
[Image straight line fitting] Image straight line fitting based on least squares method and bisect angle bisector [Matlab 100 [Image processing 32]
[Image defogging] Image defogging based on dark channel [Matlab 101 issue] [Image processing 33]
[Image transformation] DIBR-3D image transformation (3D Image Warping) [Matlab 117 issue] [Image processing 34 ]
[image segmentation algorithm] improved FCM (FRFCM) of image segmentation based on morphological reconstruction filter and Matlab 118 [period] [35] the image processing

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/112647194