python与matlab代码等价切换

python与matlab代码等价切换

1、高斯模糊与过滤函数

1.1、在matlab中:

kersiz = 2*ratio - 1;
sig = (1/(2*(2.7725887)/ratio^2))^0.5;
BlurD.K = fspecial('gaussian',[kersiz kersiz],sig);
I_HS = imfilter(I_REF, BlurD.K, 'circular');

1.2、在python中:

sig = 1 / (2 * (2.7725887) / math.pow(ratio, 2)) ** 0.5
    kernel = np.multiply(cv2.getGaussianKernel(9, sig), cv2.getGaussianKernel(9, sig).T)
    new_lrhs = []
    for i in range(Data.shape[2]):
        temp = signal.convolve2d(Data[:, :, i], kernel, boundary='wrap', mode='same')
        temp = np.expand_dims(temp, -1)
        new_lrhs.append(temp)
    Data = np.concatenate(new_lrhs, axis=-1)

这两个计算的结果是等价的。

2、三维快速傅里叶变换函数(fft2)

2.1、在matlab中:

d = ifft2(c);

2.2、在python中:

G = []
for i in range(NB):
      G.append(np.fft.fft2(a[:, :, i]))
G = np.array(G)
G = G.swapaxes(0, 1)
G = G.swapaxes(1, 2)

3、三维数据的reshape

3.1、在matlab中:

a = reshape(X', NW, NH, NB);

3.2、在python中:

a = np.reshape(np.transpose(X),(NW,NH,NB),order="F")

4、奇异值分解

4.1、在matlab中

[U,S,V] = svd(Xn,'econ');
S = max(S-lam,0);
Y(:,idx) = U(:,1:size(S,1))*S*V(:,1:size(S,2))';

4.2、在python中

[U, S, V] = svd(Xn, 'econ')
S[:] = [x - lam for x in S]
S[S < 0] = 0
S = np.diag(S)
Y[:, idx] = U[:,0:S.shape[0]].dot(S).dot(V[0:S.shape[1],:])

5、插值函数

5.1、在matlab中:

R(i,:) = spline(x, ikonos_sp(valid_ik_bands,i+1), xx);

5.2、在python中

ipo3 = spi.splrep(x, ik[valid_ik_bands-1,i+1])  # Generate model parameters
 R[i,:] = spi.splev(xx, ipo3)  # Generate interpolation points
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值