📄 mfocus.m
字号:
function [imageout] = mfocus_1(im1,im2,bs,TH,consistency)
%
%mfocus.m, v 1.2 2002/05/09 17:52:40
%===========================================================================
% Eduardo Fernandez Canga - University of Bath
%
% Copyright (c) 2002
%===========================================================================
%
% [imageout] = mfocus(im1,im2,bs,TH,consistency)
%
% im1: input image 1
% im2: input image 2
% bs: block size
% TH: threshold
% consistency: apply consistency
% 1=yes (default)
% 0=no
%
%===========================================================================
if nargin < 5, consistency=1;end
if any (size(im1)~=size(im2))
error('Error: Different Size Images')
end
if ( (bs < 1) | (bs > (min(size(im1)))) )
error(sprintf('Wrong blocksize'));
end
sx=size(im1,1); % check row size of the input images
x=mod(sx,bs);
if x % if they are NOT multiple of bs then
im1=rowpad(im1,bs-x); % add rows to make the size multiple of bs
im2=rowpad(im2,bs-x);
end
sy=size(im1,2); % check col size of the input images
y=mod(sy,bs);
if y % if they are NOT multiple of bs then
im1=colpad(im1,bs-y); % add cols to make the size multiple of bs
im2=colpad(im2,bs-y);
end
[maxi,maxj] = size(im1);
decision=zeros(maxi/bs,maxj/bs);
for i = 1 :bs: maxi-bs+1 %for each block
for j = 1 : bs : maxj-bs+1
block1 = im1(i : i+bs-1,j : j+bs-1);
block2 = im2(i : i+bs-1,j : j+bs-1);
SF1=spfreq(block1); %calculate spatial freq
SF2=spfreq(block2); %for both images
if SF2 > (SF1 + TH) %then compare and build block decision mask
decision((i-1)/bs+1,(j-1)/bs+1)=-1;
elseif SF2 < (SF1 - TH)
decision((i-1)/bs+1,(j-1)/bs+1)=1;
end
end
end
if consistency==1 % apply consistency check if it is active
mask=ones(3,3)/9; % use 3x3 window mask
decision=impad(decision,1);
decision=round(conv2(decision,mask,'valid'));
end
% expand the block decision mask to a pixel decision mask
[maxi,maxj] = size(decision);
dec=zeros(maxi*bs,maxj*bs);
for i = 1:bs
for j = 1:bs
dec(i:bs:bs*maxi,j:bs:bs*maxj)=decision;
end
end
imageout=im1.*(dec==1)+im2.*(dec==-1)+(im1+im2)/2.*(dec==0);
imageout=imageout(1:sx,1:sy);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -