Skip to content

Commit

Permalink
Completed multi drift correction
Browse files Browse the repository at this point in the history
  • Loading branch information
outlace committed Jul 10, 2015
1 parent 77c3e3a commit 3327e55
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Drift-Correction/MultiDriftCorrection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

from ij import IJ
from ij.plugin.frame import RoiManager

print "Testing 123..."

#converts microns (or whatever the physical dist is to pixels)
'''
def getPixelPos(x,y, imp):
point = [0,0]
point[0] = (x / cal.piXelW)
point[1] = (imp.height * (y / 100))
return point
'''
rm = RoiManager.getInstance() #get the open ROI manager instance
ra = rm.getRoisAsArray() #get all the ROIs in an array
#print r1.getPosition()
imp = IJ.getImage() #get current image
stack = imp.getStack() #get current
rm = RoiManager.getInstance()
ra = rm.getRoisAsArray()
nRois = len(ra)
proc = IJ.getProcessor() #get the image processor
cal = imp.getCalibration();
#print cal.pixelWidth
#print imp.width
nSlices = int(stack.getSize())
#print stack.getSize()
#print r1.getFloatPolygon().xpoints[0] #get xpoint
#first convert our ROIs to something more useful, a tuple containing the point (x,y) and the Z position => (x,y,z)
for i in range(0, nRois-1):
roi1 = rm.getRoi(i)
roi2 = rm.getRoi(i+1)
pt1 = (roi1.getFloatPolygon().xpoints[0],roi1.getFloatPolygon().ypoints[0],roi1.getPosition())
pt2 = (roi2.getFloatPolygon().xpoints[0],roi2.getFloatPolygon().ypoints[0],roi2.getPosition())
xcorrect = (pt1[0]-pt2[0]);
ycorrect = (pt1[1]-pt2[1]);
print "Point pair: "
print pt1
print pt2

IJ.setSlice(pt1[2]) #set starting slice
driftx = xcorrect/nSlices;
offsetx = 0;
startSlice = pt1[2]
endSlice = pt2[2]
print "startSlice: %s ;endSlice: %s" % (startSlice, endSlice)
for j in range(startSlice,endSlice):
IJ.setSlice(j)
offsetx += driftx
IJ.run("Translate...", "interpolation=Bicubic slice y=0 x="+str(offsetx));

drifty = ycorrect/nSlices;
offsety = 0;
for k in range(startSlice,endSlice):
IJ.setSlice(k)
offsety += drifty
IJ.run("Translate...", "interpolation=Bicubic slice x=0 y="+str(offsety));


0 comments on commit 3327e55

Please sign in to comment.