unsamplingmatlab代码的简单介绍
admin 发布:2022-12-19 05:58 123
今天给各位分享unsamplingmatlab代码的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
matlab m文件代码能否生成模型
你是指用m文件写的数学模型,然后放在Simulink里面仿真是不?
如果是这样,Simulink里面有库中User-Defined
Functions/Embedded
MATLAB
Function
把这个块拖到新建模型中,双击打开,把你的m文件拷进去就行了。记得在m文件最前面加上
[y1,
y2
,
y3
...yn]
=
function(u1,u2,...un)
其中yi为你的模型的输出,ui为你模型的输入。
拉普拉斯金字塔图像融合的具体Matlab仿真程序
function lap_fusion()
%Laplacian Pyramid fusion
mul= imread('images\ms1.png');
pan= imread('images\pan.png');
figure(1);
imshow(mul);title('MS原始图像');axis fill;
figure(2);
imshow(pan);title('Pan原始图像');axis fill;
mul = double(rgb2gray(mul))/255;
pan = double(rgb2gray(pan))/255;
%普拉斯金塔变换参数
mp = 1;zt =4; cf =1;ar = 1; cc = [cf ar];
Y_lap = fuse_lap(mul,pan,zt,cc,mp);
figure(3);
imshow(Y_lap);title('lap fusion 后的图像');axis fill;
imwrite(Y_lap,'images\lap fusion后的图像.jpg','Quality',100);
%main function end
function Y = fuse_lap(M1, M2, zt, ap, mp)
%Y = fuse_lap(M1, M2, zt, ap, mp) image fusion with laplacian pyramid
%
% M1 - input image A
% M2 - input image B
% zt - maximum decomposition level
% ap - coefficient selection highpass (see selc.m)
% mp - coefficient selection base image (see selb.m)
%
% Y - fused image
% (Oliver Rockinger 16.08.99)
% check inputs
[z1 s1] = size(M1);
[z2 s2] = size(M2);
if (z1 ~= z2) | (s1 ~= s2)
error('Input images are not of same size');
end;
% define filter
w = [1 4 6 4 1] / 16;
% cells for selected images
E = cell(1,zt);
% loop over decomposition depth - analysis
for i1 = 1:zt
% calculate and store actual image size
[z s] = size(M1);
zl(i1) = z; sl(i1) = s;
% check if image expansion necessary
if (floor(z/2) ~= z/2), ew(1) = 1; else, ew(1) = 0; end;
if (floor(s/2) ~= s/2), ew(2) = 1; else, ew(2) = 0; end;
% perform expansion if necessary
if (any(ew))
M1 = adb(M1,ew);
M2 = adb(M2,ew);
end;
% perform filtering
G1 = conv2(conv2(es2(M1,2), w, 'valid'),w', 'valid');
G2 = conv2(conv2(es2(M2,2), w, 'valid'),w', 'valid');
% decimate, undecimate and interpolate
M1T = conv2(conv2(es2(undec2(dec2(G1)), 2), 2*w, 'valid'),2*w', 'valid');
M2T = conv2(conv2(es2(undec2(dec2(G2)), 2), 2*w, 'valid'),2*w', 'valid');
% select coefficients and store them
E(i1) = {selc(M1-M1T, M2-M2T, ap)};
% decimate
M1 = dec2(G1);
M2 = dec2(G2);
end;
% select base coefficients of last decompostion stage
M1 = selb(M1,M2,mp);
% loop over decomposition depth - synthesis
for i1 = zt:-1:1
% undecimate and interpolate
M1T = conv2(conv2(es2(undec2(M1), 2), 2*w, 'valid'), 2*w', 'valid');
% add coefficients
M1 = M1T + E{i1};
% select valid image region
M1 = M1(1:zl(i1),1:sl(i1));
end;
% copy image
Y = M1;
function Y = es2(X, n)
%Y = ES2(X, n) symmetric extension of a matrix on all borders
%
% X - input matrix
% n - number of rows/columns to extend
%
% Y - extended matrix
% (Oliver Rockinger 16.08.99)
[z s] = size(X);
Y = zeros(z+2*n, s+2*n);
Y(n+1:n+z,n:-1:1) = X(:,2:1:n+1);
Y(n+1:n+z,n+1:1:n+s) = X;
Y(n+1:n+z,n+s+1:1:s+2*n) = X(:,s-1:-1:s-n);
Y(n:-1:1,n+1:s+n) = X(2:1:n+1,:);
Y(n+z+1:1:z+2*n,n+1:s+n) = X(z-1:-1:z-n,:);
function Y = dec2(X);
%Y = dec2(X) downsampling of a matrix by 2
%
% X - input matrix
%
% Y - output matrix
% (Oliver Rockinger 16.08.99)
[a b] = size(X);
Y = X(1:2:a, 1:2:b);
function Y = undec2(X)
%Y = undec2(X) upsampling of a matrix by 2
%
% X - input matrix
%
% Y - output matrix
% (Oliver Rockinger 16.08.99)
[z s] = size(X);
Y = zeros(2*z, 2*s);
Y(1:2:2*z,1:2:2*s) = X;
function Y = selb(M1, M2, mp)
%Y = selb(M1, M2, mp) coefficient selection for base image
%
% M1 - coefficients A
% M2 - coefficients B
% mp - switch for selection type
% mp == 1: select A
% mp == 2: select B
% mp == 3: average A and B
%
% Y - combined coefficients
% (Oliver Rockinger 16.08.99)
switch (mp)
case 1, Y = M1;
case 2, Y = M2;
case 3, Y = (M1 + M2) / 2;
otherwise, error('unknown option');
end;
function Y = selc(M1, M2, ap)
%Y = selc(M1, M2, ap) coefficinet selection for highpass components
%
% M1 - coefficients A
% M2 - coefficients B
% mp - switch for selection type
% mp == 1: choose max(abs)
% mp == 2: salience / match measure with threshold == .75 (as proposed by Burt et al)
% mp == 3: choose max with consistency check (as proposed by Li et al)
% mp == 4: simple choose max
%
% Y - combined coefficients
% (Oliver Rockinger 16.08.99)
% check inputs
[z1 s1] = size(M1);
[z2 s2] = size(M2);
if (z1 ~= z2) | (s1 ~= s2)
error('Input images are not of same size');
end;
% switch to method
switch(ap(1))
case 1,
% choose max(abs)
mm = (abs(M1)) (abs(M2));
Y = (mm.*M1) + ((~mm).*M2);
case 2,
% Burts method
um = ap(2); th = .75;
% compute salience
S1 = conv2(es2(M1.*M1, floor(um/2)), ones(um), 'valid');
S2 = conv2(es2(M2.*M2, floor(um/2)), ones(um), 'valid');
% compute match
MA = conv2(es2(M1.*M2, floor(um/2)), ones(um), 'valid');
MA = 2 * MA ./ (S1 + S2 + eps);
% selection
m1 = MA th; m2 = S1 S2;
w1 = (0.5 - 0.5*(1-MA) / (1-th));
Y = (~m1) .* ((m2.*M1) + ((~m2).*M2));
Y = Y + (m1 .* ((m2.*M1.*(1-w1))+((m2).*M2.*w1) + ((~m2).*M2.*(1-w1))+((~m2).*M1.*w1)));
case 3,
% Lis method
um = ap(2);
% first step
A1 = ordfilt2(abs(es2(M1, floor(um/2))), um*um, ones(um));
A2 = ordfilt2(abs(es2(M2, floor(um/2))), um*um, ones(um));
% second step
mm = (conv2((A1 A2), ones(um), 'valid')) floor(um*um/2);
Y = (mm.*M1) + ((~mm).*M2);
case 4,
% simple choose max
mm = M1 M2;
Y = (mm.*M1) + ((~mm).*M2);
otherwise,
error('unkown option');
end;
上采样(UnSampling)、反卷积(Deconvolution)与上池化(UnPooling)
反卷积(Deconvolution)、上采样(UnSampling)与上池化(UnPooling)的对比图示如下(图片出处见水印):
FCN、U-net等网络结构中都有使用上采样。上采样是指使图像分辨率变高的方法。
最简单的方式是重采样和插值:将输入图片进行rescale到一个想要的尺寸,并计算每个点的像素值,使用如 双线性插值 等插值方法对其余点进行插值来完成上采样过程。
反卷积在CNN中常用于表示一种反向卷积 ,但它并不是一个符合严格数学定义的反卷积操作。与上池化不同,使用反卷积来对图像进行上采样是可以习得的。通常用来对卷积层的结果进行上采样,使其回到原始图片的分辨率。
上池化是在CNN中常用的来表示max pooling的逆操作。最早来源于2013年纽约大学Matthew D. Zeiler和Rob Fergus发表的《Visualizing and Understanding Convolutional Networks》。
鉴于max pooling不可逆,因此使用近似的方式来反转得到max pooling操作之前的原始情况。
简单来说,记住做max pooling的时候的最大item的位置,比如一个3x3的矩阵,max pooling的size为2x2,stride为1,反卷积记住其位置,其余位置至为0就行:
unsamplingmatlab代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、unsamplingmatlab代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-17做公司网页,做公司网页有什么简单的方法
- 05-12深圳seo公司的简单介绍
- 05-11设计一个简单的网页,独立站建站平台有哪些
- 05-09网页代码,网页代码快捷键
- 05-09hao123网址之家官网的简单介绍
- 05-07孝感seo的简单介绍
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接