def threshold_components_parallel(pars):
A_i, i , dims, medw, d, thr_method, se, ss, maxthr, nrgthr, extract_cc = pars
A_temp = np.reshape(A_i, dims[::-1])
A_temp = median_filter(A_temp, medw)
if thr_method == 'max':
BW = (A_temp>maxthr*np.max(A_temp))
elif thr_method == 'nrg':
Asor = np.sort(np.squeeze(np.reshape(A_temp, (d, 1))))[::-1]
temp = np.cumsum(Asor**2)
ff = np.squeeze(np.where(temp < (1 - nrgthr) * temp[-1]))
if ff.size > 0:
if ff.ndim == 0:
ind = ff
else:
ind = ff[-1]
A_temp[A_temp < Asor[ind]] = 0
BW = (A_temp >= Asor[ind])
else:
BW = (A_temp >= 0)
Ath = np.squeeze(np.reshape(A_temp, (d, 1)))
Ath2 = np.zeros((d))
BW = binary_closing(BW.astype(np.int), structure=se)
if extract_cc:
labeled_array, num_features = label(BW, structure=ss)
BW = np.reshape(BW, (d, 1))
labeled_array = np.squeeze(np.reshape(labeled_array, (d, 1)))
nrg = np.zeros((num_features, 1))
for j in range(num_features):
nrg[j] = np.sum(Ath[labeled_array == j + 1]**2)
indm = np.argmax(nrg)
#Ath2[labeled_array == indm + 1] = A_i[labeled_array == indm + 1]
Ath2[labeled_array == indm + 1] = Ath[labeled_array == indm + 1]
else:
BW = BW.flatten()
Ath2[BW] = Ath[BW]
return Ath2, i
#%% lars_regression_noise
评论列表
文章目录