指定窗函数在图像中的对应中心,将图像除窗函数外全补为0
可以方便的实现矩阵运算!
代码
function OutWin = FspecialWindow(InWin,CentreCoorX,CentreCoorY,SizeImRow,SizeImColumn)
% 指定中心、窗函数和图像大小,将图像除窗函数外全补为0
% 要求窗函数为矩阵,长宽奇偶不限
% Input:
% InWin(m*n)
% CentreCoorX(1*1)
% CentreCoorY(1*1)
% SizeImRow(1*1)
% SizeImColumn(1*1)
% Output:
% OutWin(SizeImRow*SizeImColumn)
%
% X.F.Zhang (2010/11/25, v1.0)
%
[SizeInWinRow,SizeInWinColumn] = size(InWin);
if mod(SizeInWinRow,2) == 0 % 使窗的行为奇数
SizeInWinRow = SizeInWinRow+1;
InWin(SizeInWinRow,:) = 0;
end
if mod(SizeInWinColumn,2) == 0 % 使窗的列为奇数
SizeInWinColumn = SizeInWinColumn+1;
InWin(:,SizeInWinColumn) = 0;
end
RadiusInWinRow = (SizeInWinRow-1)/2; % 计算输入窗的行半径
RadiusInWinColumn = (SizeInWinColumn-1)/2; % 计算输入窗的列半径
StartX = CentreCoorX - RadiusInWinRow;
EndX = CentreCoorX + RadiusInWinRow;
StartY = CentreCoorY - RadiusInWinColumn;
EndY = CentreCoorY + RadiusInWinColumn;
if StartX < 1
StartX = 1;
elseif StartX >= SizeImRow
error('(1)The Central Coordination isn''t in the image!');
end
if EndX > SizeImRow
EndX = SizeImRow;
elseif EndX <= 0
error('(2)The Central Coordination isn''t in the image!');
end
if StartY < 1
StartY = 1;
elseif StartY >= SizeImColumn
error('(3)The Central Coordination isn''t in the image!');
end
if EndY > SizeImColumn
EndY = SizeImColumn;
elseif EndY <= 0
error('(4)The Central Coordination isn''t in the image!');
end
ZerosWin = zeros(SizeImRow,SizeImColumn); % 与图像等大小
% 窗与图像在边缘叠加时,依然成立
for i_row = StartX : EndX
for j_column = StartY : EndY
ZerosWin(i_row,j_column) = ZerosWin(i_row,j_column) + ...
InWin(1+i_row-(CentreCoorX - RadiusInWinRow), ...
1+j_column-(CentreCoorY - RadiusInWinColumn));
end
end
OutWin = ZerosWin;
版权归原创作者所有!