1 Star 0 Fork 0

X_C/imageSegmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.m 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
fzy 提交于 2017-05-18 16:09 . imageSegmentation
clear;
clc;
%-----------------------ȡͼ---------------------------
figure
% I = imread('D:\ImageSource\Weizmann_Seg_DB_1obj\100_0109\src_color\100_0109.png');
I = imread('D:\ImageSource\cmuGeometricContextDataset\alley07.jpg');
subplot(1,2,1);imshow(I);
I = rgb2gray(I);
subplot(1,2,2);imshow(I);
title('ԭͼ');
m=size(I,1);
n=size(I,2);
gray=reshape(I,m*n,1);
options = [2;1000;1e-5;0];
claNum = 2;
% C(1,:) = rand(1,1)*(m*n);
% C(2,:) = rand(1,1)*(m*n);
[uk,Ck] = kmeans(double(gray),claNum,'maxiter',1000,'Display','final','Replicates',1);
[centerf,uf,objf] = fcm(double(gray),claNum,options);
[centerkf,ukf,objkf] = kfcmFun(double(gray),claNum,1000,2);
[~,indk] = sort(Ck);
[~,indf] = sort(centerf);
[~,indkf] = sort(centerkf);
for i = 1 : size(uk,1)
uk(i) = indk(uk(i));
end
uf = uf(indf,:);
ukf = ukf(indkf,:);
step = fix(256./claNum);
[~,indexf] = max(uf);
[~,indexkf] = max(ukf);
for i = 1 : claNum
grayk(uk==i,:) = i*step;
grayf(indexf==i,:) = i*step;
graykf(indexkf==i,:) = i*step;
end
imgk = reshape(grayk,m,n);
imgf = reshape(grayf,m,n);
imgkf = reshape(graykf,m,n);
imwrite(uint8(imgk),'kmean_result.jpg');
imwrite(uint8(imgf),'fcm_result.jpg');
imwrite(uint8(imgkf),'kfcm_result.jpg');
figure;
subplot(1,3,1);imshow(uint8(imgk));
subplot(1,3,2);imshow(uint8(imgf));
subplot(1,3,3);imshow(uint8(imgkf));
title('ͼ');
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/x_c9311/imageSegmentation.git
git@gitee.com:x_c9311/imageSegmentation.git
x_c9311
imageSegmentation
imageSegmentation
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385