def translate_group(self, signalimg, group, translateaxis):
n_channels = len(self.locs)
all_xcorr = np.zeros((1, n_channels))
all_da = np.zeros((1, n_channels))
if translateaxis == 'x':
proplane = 'xy'
elif translateaxis == 'y':
proplane = 'xy'
elif translateaxis == 'z':
proplane = 'xz'
plotmode = 0
for j in range(n_channels):
if plotmode:
fig = plt.figure()
ax1 = fig.add_subplot(1, 3, 1)
plt.plot(signalimg[j])
ax2 = fig.add_subplot(1, 3, 2)
if self.dataset_dialog.checks[j].isChecked():
index = self.group_index[j][group].nonzero()[1]
x_rot = self.locs[j].x[index]
y_rot = self.locs[j].y[index]
z_rot = self.locs[j].z[index]
xcorr_max = 0.0
plane = self.render_planes(x_rot, y_rot, z_rot, proplane, self.pixelsize) #
if translateaxis == 'x':
projection = np.sum(plane, axis=0)
elif translateaxis == 'y':
projection = np.sum(plane, axis=1)
elif translateaxis == 'z':
projection = np.sum(plane, axis=1)
if plotmode:
plt.plot(projection)
#print('Step X')
#ax3 = fig.add_subplot(1,3,3)
#plt.imshow(plane, interpolation='nearest', cmap=plt.cm.ocean)
corrval = np.max(signal.correlate(signalimg[j],projection))
shiftval = np.argmax(signal.correlate(signalimg[j], projection))-len(signalimg[j])+1
all_xcorr[0,j] = corrval
all_da[0,j] = shiftval/self.oversampling
if plotmode:
plt.show()
#value with biggest cc value form table
maximumcc = np.argmax(np.sum(all_xcorr,axis = 1))
dafinal = np.mean(all_da[maximumcc,:])
for j in range(n_channels):
index = self.group_index[j][group].nonzero()[1]
if translateaxis == 'x':
self.locs[j].x[index] += dafinal
elif translateaxis == 'y':
self.locs[j].y[index] += dafinal
elif translateaxis == 'z':
self.locs[j].z[index] += dafinal*self.pixelsize
评论列表
文章目录