clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
name = 5;
% Initialise the maximum split level
level = 0;
% Initialise the maximum block size permitted
pmax = 0;
% default image number and type
N = 2; type = '.bmp';
% Set the Image name
switch name
case 1
str = 'clock';
case 2
str = 'lab';
case 3
str = 'pepsi';
case 4
str = 'OpenGL';
case 5
str = 'flower';
case 6
str = 'disk';
case 7
str = 'toy'; N = 3;
end
fprintf('Processing Image %s :\n', str);
for opt = 2
% Get dimensions of multi-focus images
inImg = double(imread (strcat('example images\',str,num2str(1),type)));
[p1,p2,p3] = size(inImg);
% Extend the image dimensions to 2 ^ X; X <= 512
dim = max(p1, p2);
maxDim = 1024;
while(dim < maxDim || dim == maxDim)
maxDim = maxDim / 2;
end
maxDim = maxDim * 2;
% if the maxDim == 2048, exit the program
if (maxDim == 2048)
disp('Image size is too big, it cannot process!');
return;
end
% Store the multi-focus source images
mImg=zeros(p1,p2,N);
for q=1:N
% Read the image data
inImg = imread (strcat('example images\',str,num2str(q),type));
[p1,p2,p3] = size(inImg);
% Convert image data from uint8 to double
inImg = double(inImg);
% Store the temp image
mImg(:,:,q)=inImg;
end
tic
% Weighted Block Size
sz = 17;
% Initialize the focus measure maps
FMs = zeros(p1, p2, N);
if opt == 1
disp('Fused method 1: Sum of Modified laplacian');
for kk = 1 : N
f = SML(mImg( : , : , kk), 1, 5);
FMs(:,:,kk) = f;
end
method = 'SML';
elseif opt == 2
disp('Fused method 2: Sum of Weighted Modified laplacian');
for kk = 1 : N
f = SML(mImg( : , : , kk), 1, 5);
FM = Local_Saliency(f, sz);
FMs(:,:,kk) = FM;
end
method = 'SWML';
end
%% Extend Imgs and Salmaps to maxDim( 2 ^ X )
Imgs = zeros(maxDim, maxDim, N);
dx = ceil((maxDim - p1) / 2);
dy = ceil((maxDim - p2) / 2);
Imgs(dx + 1 : dx + p1, dy + 1 : dy + p2, : ) = mImg;
Salmaps = zeros(maxDim, maxDim, N);
Salmaps(dx + 1 : dx + p1, dy + 1 : dy + p2, : ) = FMs;
%% Decomposition level and max permitted block-size must be restricted!!!
pmaxDim = maxDim / 2;
% Set the Default level, when not set level
if level == 0
level = log2(maxDim);
end
% Set the default maximum block size permitted
if pmax == 0
pmax = maxDim;
end
%% Quad tree docomposition process
pmin = 2;
Num = N;
[S, Fusion_tag, maxFM] = qt_sm_fusion(Imgs, Salmaps, Num, level);
Fusion_decision_map = Fusion_tag(dx + 1 : dx + p1, dy + 1 : dy + p2);
maxFM = maxFM(dx + 1 : dx + p1, dy + 1 : dy + p2);
%% 1. First Filter: Open and Close morphilogical filtering
Iter = 1;
Fusion_decision_map = morph_filter(Fusion_decision_map, N, Iter);
%% 2. Second Filter: Fiter small blocks inside
smallsz = p1 * p2 / 40;
Fusion_decision_map = Small_Block_Filter(Fusion_decision_map, N, smallsz);
FImg = zeros(p1,p2);
%% 1. the defined part, copied directly according to the decision map
for ii = 1 : Num
FImg = FImg + mImg(:,:,ii) .* (Fusion_decision_map == ii);
end
%% 2. the non-defined part, copied by maximum selection method
max_tag = zeros(p1, p2, N);
img_tag = zeros(p1, p2);
% Find the maximum FM in each FM
for ii = 1 : N
tag = (FMs(:,:,ii) == maxFM);
max_tag(:,:,ii) = tag;
img_tag = img_tag + tag .* ii;
end
% The nonpart images and maximum selection
non_part = (Fusion_decision_map < 1);
nonImgs = mImg;
part1 = zeros(p1,p2);
for ii = 1 : N
nonImgs(:,:,ii) = nonImgs(:,:,ii) .* non_part;
part1 = part1 + nonImgs(:,:,ii) .* max_tag(:,:,ii);
end
% The positions where more than one FM(i) have the maxFM
max_num = sum(max_tag, 3);
% The sigle and multiple positions
single_num = (max_num == 1);
multi_num = 1 - single_num;
% If there are more than one FMi equal to maxFM
part2 = sum(nonImgs, 3) ./ N;
% As to the whole nonpart
nonPart = part1 .* single_num + part2 .* multi_num;
% Final Fused image FImg
FImg = FImg + nonPart;
FImg = uint8(FImg);
figure,imshow(FImg);
figure,imshow(mat2gray(Fusion_decision_map))
%--------------------------------------------------------------------------
% Store the Fusion decision map and the fusion image
%--------------------------------------------------------------------------
imwrite((Fusion_decision_map ./ N), strcat('fusion decision maps\', method, '_', str, '.bmp'));
imwrite(FImg, strcat('fusion results\', method, '_', str, '.bmp'));
end
matlab-基于加权焦点度量和四叉树的多焦点图像分割算法matlab仿真-源码
版权申诉
103 浏览量
2021-09-11
21:50:35
上传
评论
收藏 3KB RAR 举报
mYlEaVeiSmVp
- 粉丝: 1919
- 资源: 19万+
最新资源
- CISCN2024-re3-rust-baby(Frida多字节程序插桩爆破)
- soft:磁盘清理工具
- .netcore控制台使用Nssm打包windows服务,加winform管理服务界面
- db-college.sql
- wpf-dragdrop-treeview(WPF较好拖拽效果).7z
- img-1716258776282bf88540b0e387ddd2ea677d02c7f3594ad72383f796d86b02fb7d2ae2543915d.jpg
- 《伦敦共享单车数据分析与代码》
- SKIP-v2.1.1.apk
- IMG20240521103815.jpg
- 松下A4系列伺服参数调试软件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈