These are chat archives for thunder-project/thunder
squeeze()keeps one extra dim:
reference = datCrop[refR:refR,:,:,:].mean() # taking 20 stacks average as a ref stack reference.shape (1, 500, 500, 20) datCrop.shape (1200, 500, 500, 20) register = CrossCorr() model = register.fit(datCrop, reference=reference) Exception: Image shape (500, 500, 20) and reference shape (1, 500, 500, 20) must match
squeeze()keeps 1-st dimention in ref. image no matter what :(
reference = datCrop[refR:refR,:,:,:].mean().toarray()
squeeze()thing has become confusing, and we might need to change it
sorry, I am stuck again. In older Thunder version, registration model transformations were lists, and I used to extract the xy shift from them like
xy_shifts = np.array([model.transformations[x].delta for x in range(len(model.transformations))])
This would give me an array of xy displacements for each stack, ordered by Z. But now it seems to be a dictionary or some key-value pairs. How do I access them now?
My full code would be, in old Thunder, like
zStart = 10 #starting plane of registration zEnd = 30 #ending plane window = 500 #width and height of the registration ROI datCrop = dat.crop((dims/3,dims/2,zStart), \ (dims/3 + window,dims/2 + window,zEnd)) # take sub-stack, (length, width, z) regCrop = Registration('planarcrosscorr').prepare(datCrop,startIdx=refR, stopIdx=refR) regParamsCrop = regCrop.fit(datCrop.medianFilter(3)) # extrapolate all missing planes from known registration shifts xysCrop = np.array([regParamsCrop.transformations[x].delta for x in range(len(regParamsCrop.transformations))]) xysNew = np.zeros((numFrames,dims,2)) for i in range(zStart): #extrapolate xysNew[:,i,:] = np.median(xysCrop,axis = 1) for i in range(zStart,zEnd): # populate with real values xysNew[:,i,:] = xysCrop[:,i-zStart,:] for i in range(zEnd,dims): #extrapolate xysNew[:,i,:] = np.median(xysCrop,axis = 1) # apply registration to full data for x in range(xysNew.shape): regParamsCrop.transformations[x].delta = list(xysNew[x,:,:]) dat = regParamsCrop.transform(dat) xys = np.array([regParamsCrop.transformations[x].delta for x in range(len(regParamsCrop.transformations))]) distsX, distsY = xys[:,:,0], xys[:,:,1]
and then I would plot the
distsX, distsY to know how much the sample shifted during experiment. Is there any way to do the same thing in new Thunder?
model.transformations, if possible.
@nvladimus You should be able to use the
toarray() method mentioned above. Do something like:
model.toarray()[:,0] for x and
model.toarray()[:,1] for y values.
.toarray() will make it into a numpy array (or bolt array possibly with distributed data, I'm not sure off the top of my head) so you don't need to call np.array() on it.
At least for the registration method with Thunder 1.0, the examples have been updated on the docs page (http://docs.thunder-project.org/) under the registration tutorial. I was able to work out most of the changes by looking through those tutorials.
2 * Nshifts (
Nbeing number of planes in a stack, shifts were in
x, y). The new registration method does it by 3D volume, and for every stack returns 3 shifts, now in
x,y,z, but they do not agree with previously calculated (correct) plane-by-plane shifts.
# run registration on cropped data zStart = 10 #starting plane of registration zEnd = 30 #ending plane window = 500 #width and height of the registration ROI datCrop = dat[:,dims/3:dims/3 + window,dims/2:dims/2 + window,zStart:zEnd] # take sub-stack, (length, width, z) reference = datCrop[refR:refR,:,:,:].mean().toarray() register = CrossCorr() model = register.fit(datCrop.median_filter(3), reference=reference) deltas = model.toarray() plt.plot(deltas[:,1]) #plot x shifts for every time point
CrossCorrnow has an option
axiswhich allows you to restrict the registration to a subset of axes
register.fit()function. Will try now.
CrossCorr(axis=2)should do the "planar" registration from before
ok, there is something wrong in how I load the data:
dat = td.images.frombinary(rawDir, shape = dims, ext='stack', npartitions=numFrames, engine=sc)
then I try to plot one plane:
plt.figure(figsize = (10,20)) plt.imshow(dat[0,:,:,20].toarray())
and I get some mosaic image instead of fish brain.