【图像分割】基于WFCM算法的图像分割matlab源码

215 阅读1分钟

 

%% Image segmentation by WFCM
%  WFCM refer to 'Fuzzy cluster analysis and its application' by Teacher
%  Gao, Published by xidian
%  we first implement one thresholding segmentation, then auto
%  multi-thresholding
%  we also used two-dimentional gray histogram
%  Algorithm by Teacher Xinbo Gao, implemented by Lin Zhao, VIPS Lab;
%% Code Follows
clear;clc;close all;
inputim = imread('TestImage\lena.bmp'); inputim = rgb2gray(inputim);
figure;imshow(inputim,[]);
% count 1D histogram or 2D histogram
[h,x] = imhist(inputim); figure;stem(x,h);
nst = imhist2(inputim);
count = 0:1:255;
% count = nst;
% compute the weighted coefficient wi
w = h'./sum(h');
% iteration to compute the center of clustering,here c=2
vc1 = 64; vc2 = 192; % initialization
v1 = 0; v2 = 0; n = 0;
while (abs(v1-vc1)>2)||(abs(v2-vc2)>2)
    if n ~= 0
        vc1 = v1; vc2 = v2;
    end
    % update uij
    for j = 1:1:2
        if j == 1
            vc = vc1;
        else
            vc = vc2;
        end
 
end
% compute the threholding
t = (vc1+vc2)/2;
T = repmat(t,size(inputim,1),size(inputim,2));
outputim = inputim>T;
outputim = double(outputim);
figure;imshow(outputim,[]);

完整代码或者仿真咨询添加QQ1575304183