⛄一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【肿瘤分割】基于matlab聚类乳腺肿瘤图像分割【含Matlab源码 1471期】
点击上面蓝色字体,直接付费下载,即可。
获取代码方式2:
付费专栏图像处理(Matlab)
备注:
点击上面蓝色字体付费专栏图像处理(Matlab),扫描上面二维码,付费299.9元订阅海神之光博客付费专栏,凭支付凭证,私信博主,可免费获得5份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:5份本博客上传CSDN资源代码
⛄二、图像分割简介
理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】
⛄三、部分源代码
clc
clear
close all
%% dataset:
for image=1:33
image
Iref=dicomread([‘RIDER dataset/ref/1 (’,num2str(image),‘).dcm’]);
Igt=dicomread([‘RIDER dataset/GT/1 (’,num2str(image),‘).dcm’]);
fim=(double(Iref)/(max(max(double(Iref)))));
GT=logical(Igt);
maxwin=0;
for i=30:5:size(GT,1)-100
for j=30:5:size(GT,2)-100
window=GT(i:i+90,j:j+90);
if sum(sum(window))>maxwin
maxwin=sum(sum(window));
bestwin=window;
besti=i;
bestj=j;
end
end
end
GT=bestwin;
fim=fim(besti:besti+90,bestj:bestj+90);
subplot(1,4,1)
imshow(GT);
title(‘Ground Truth’);
%% fcm
[bwfim,level]=threshold1(fim);
%% kmeans
[bwfim2,level2]=threshold2(fim);
%% Cuckoo + Kmeans
[bwfim3,level3]=threshold3(fim);
%%
result=(bwfim);
nResult=sum(sum(result1));
nGT=sum(sum(GT1));
nUNI=0;
for i=1:numel(GT)
if result(i)1 && GT(i)1
nUNI=nUNI+1;
end
end
Q_fcm= nUNI/nGT * nUNI/nResult;
subplot(1,4,2)
imshow(bwfim);
title([‘FCM/ Q=’,num2str(Q_fcm)]);
%%
result=(bwfim2);
nResult=sum(sum(result1));
nGT=sum(sum(GT1));
nUNI=0;
for i=1:numel(GT)
if result(i)1 && GT(i)1
nUNI=nUNI+1;
end
end
Q_km= nUNI/nGT * nUNI/nResult;
subplot(1,4,3)
imshow(bwfim2);
title([‘Kmeans/ Q=’,num2str(Q_km)]);
%%
result=bwfim3;
nResult=sum(sum(result1));
nGT=sum(sum(GT1));
nUNI=0;
for i=1:numel(GT)
if result(i)==1 && GT(i)==1
nUNI=nUNI+1;
end
end
Qc= nUNI/nGT * nUNI/nResult;
subplot(1,4,4)
imshow(bwfim3);
title([‘Cuckoo/ Q=’,num2str(Qc)]);
pause(0.1)
QQ=[Q_fcm,Q_km,Qc];
xlswrite(‘xl.xlsx’,QQ,1,[‘A’,num2str(image)])
end
function label = km( IM,k )
n=12; % # of nests
c=4; % # of cuckoos
Pa=0.2; % a fraction of worst solutions
worstN=round(Pa*n);
solutions=min(min(min(IM)))+ (max(max(max(IM)))-min(min(min(IM))))rand(n,k);
max_generation=5;
alpha=0.85;
cuckoo_solution=min(min(min(IM)))+ (max(max(max(IM)))-min(min(min(IM))))rand(c,k);
for t=1:max_generation
disp(['wait… ',num2str(t/max_generation80),‘%’]);
for i=1:c
index=randsrc(1,1,1:n);
if f(IM,cuckoo_solution(i,:),k)>f(IM,solutions(index,:),k)
solutions(index,:)=cuckoo_solution(i,:);
end
end
for i=1:n
fitness(i)=f(IM,solutions(i,:),k);
end
[~,idx]=sort(fitness);
best_solution=solutions(idx(end)😅;
wrst=idx(1:worstN);
solutions(wrst,:)=min(min(min(IM)))+ (max(max(max(IM)))-min(min(min(IM))))rand(length(wrst),k);
cuckoo_solution=cuckoo_solution+alphat.^(-(1.01+1.9rand(c,k)));% Levy Flights
end
[~,label]=f(IM,best_solution,k);
end
%%
function [fitness,label] = f(IM,sol,k)
data=reshape(IM,[],1);
data=data’;
maxi=100;
c=sol;
for i=1:length(data)
[~,label(i)]=min(abs(data(i)-c));
end
for iter=1:maxi
for i=1:k
c(i)=mean(data(labeli));
end
change=0;
for i=1:length(data)
[~,mindist]=min(abs(data(i)-c));
if mindist~=label(i)
label(i)=mindist;
change=1;
end
end
if change0
break;
end
end
level=(max(data(label1))+min(data(label2)))/2;
if isempty(level)
fitness=0;
else
bw=im2bw(IM,level);
if numel(size(IM))==3
I=rgb2gray(IM);
else
I=IM;
end
bwfim=medfilt2(double(bw));
PSNR=psnr(I,bwfim);
fitness=PSNR;
end
end
⛄四、运行结果
⛄五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]赵勇,方宗德,庞辉,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除