Last active
October 22, 2020 09:27
-
-
Save lacan/f20223c199a33d628cbc0e196fa0b045 to your computer and use it in GitHub Desktop.
Reslices a dataset, fits gaussians in 2D before performing a 1D fit in Z #ImageJ #Macro #Fiji #BIOP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saveDir = getDirectory("Save Directory"); | |
image = getTitle(); | |
run("Grouped Z Project...", "projection=[Max Intensity] group=25"); | |
groups = getTitle(); | |
getDimensions(gx,gy,gc,gz,gt); | |
setBatchMode(true); | |
for(g=0;g<gt;g++) { | |
selectImage(groups); | |
setSlice(g+1); | |
run("Gaussian Fit", "smoothing=0.40 box_size=3 background=195 min_height=0 fraction_above_background=0 min_width=0 top_n=0 block_find_algorithm border=15 fit_function=Circular fit_background fit_criteria=[Least-squared error] max_iterations=20 significant_digits=4 coord_delta=0.0100 single_fit single_region_size=5 initial_stddev=0.000"); | |
selectWindow("Fit Results"); | |
saveAs("Text", saveDir+"temp.csv"); | |
run("Close"); | |
open( saveDir+"temp.csv"); | |
selectImage(image); | |
run("Duplicate...", "duplicate range="+((g*25)+1)+"-"+((g+1)*25)+" use"); | |
fitFWHMz(g); | |
close(); | |
selectWindow("Results"); | |
saveAs("Text", saveDir+image+"_xyz_"+g+".txt"); | |
run("Close"); | |
run("Clear Results"); | |
} | |
setBatchMode(false); | |
function fitFWHMz(offset) { | |
x = newArray(nResults); | |
y = newArray(nResults); | |
xsd = newArray(nResults); | |
ysd = newArray(nResults); | |
name = getTitle(); | |
size=6; | |
setLineWidth(4); | |
for(i=0; i<nResults; i++) { | |
selectImage(name); | |
print("Bead "+i+" of "+nResults); | |
x[i] = getResult("X", i); | |
y[i] = getResult("Y", i); | |
xsd[i] = getResult("X SD", i); | |
ysd[i] = getResult("Y SD", i); | |
makeRectangle(x[i]-size/2+0.5, y[i]-size/2+0.5, size, size); | |
//waitForUser; | |
run("Reslice [/]...", "output=4.000 start=Top avoid"); | |
run("Z Project...", "projection=[Max Intensity]"); | |
makeLine(size/2, 2, size/2, 23); | |
//waitForUser; | |
ypoints = getProfile(); | |
xpoints = Array.getSequence(ypoints.length); | |
Fit.doFit("Gaussian", xpoints, ypoints); | |
d = Fit.p(3); | |
fwhm = 2*sqrt(2*log(2))*d; | |
r = Fit.rSquared; | |
setResult("FWHM Z", i, fwhm); | |
setResult("R2 Z", i, r); | |
zPos = Fit.p(2)+offset*25; | |
setResult("Z Position", i, zPos); | |
updateResults(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment