加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ht_filtering_hadamard.py 1016 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shuai_Yan 提交于 2020-04-16 17:41 . Added some notes
import numpy as np
from scipy.linalg import hadamard
import math
def ht_filtering_hadamard(group_3D, sigma, lambdaHard3D, doWeight): # group_3D shape=(n*n, nSx_r)
"""
:hard threshold filtering after hadamard transform
:param group_3D:
:param sigma:
:param lambdaHard3D:
:param doWeight:
:return:
"""
nSx_r = group_3D.shape[-1]
coef_norm = math.sqrt(nSx_r)
coef = 1.0 / nSx_r
group_3D_h = hadamard_transform(group_3D)
# hard threshold filtering in this block
T = lambdaHard3D * sigma * coef_norm
T_3D = np.where(np.abs(group_3D_h) > T, 1, 0)
weight = np.sum(T_3D)
group_3D_h = np.where(np.abs(group_3D_h) > T, group_3D_h, 0.)
group_3D = hadamard_transform(group_3D_h)
group_3D *= coef
if doWeight:
weight = 1. / (sigma * sigma * weight) if weight > 0. else 1.
return group_3D, weight
def hadamard_transform(vec):
n = vec.shape[-1]
h_mat = hadamard(n).astype(np.float64)
v_h = vec @ h_mat
return v_h
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化