在 2009年6月16日星期二UTC+8下午9时54分50秒,tenveer写道:
Hi there,
I'm happen to see this problem. Here it goes;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ LR ] = matrix_downsampling( HR , window)
%matrix_downsampling_for_CCD_imaging This function is used to down sampling
%the input high rate image to low rate image combination window is
%determed by the reduce window.
% Detailed explanation goes here
[M, N]=size(HR); %输入矩阵的尺寸
[p, q]=size(window); %用于采样的窗口。由于模拟CCD的光强成像,窗口内为数据加和。
% 这里需要对M×N是否为p×q的整数倍进行判断。
% 如果不是整数倍,需要对原始图像进行填充。
r=mod(p-mod(M,p),p);c=mod(q-mod(N,q),q); %r,c为行列需要填充的个数
%p-mod(M,p)是为了求要填充的行数
%但当M正好是p倍数时,p-mod(M,p)为p
%而实际上不需要填充,故再做一次mod
HR_paded=padarray(HR, [r c], 'replicate', 'post'); %此填充方式参见冈萨雷斯matlab的P71
% 计算低速数据的输出矩阵结构
[M, N]=size(HR_paded); %新的M,N
m=M/p;n=N/q;
% 生成降速窗口的向量元
vp=ones(1,p);
vq=ones(1,q);
% 生成降速变换矩阵。CL为行降速变换矩阵,CR为列降速变换矩阵。
CL=kron(eye(M/p),vp);
CR=kron(eye(N/q),vq).';
% 对高速矩阵进行降速运算,及在原始矩阵的p*q大小的栅格单元内求和
LR=CL*HR_paded*CR;
end
%%%%%%%%%%%%%%%%%%%%%
here is the example to use this function as following:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Out_LR=matrix_downsampling(In_HR,ones(10,10));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
this example shows that the In_HR is down sampling by a window in 10 by 10.