Created
November 14, 2012 14:12
Multiplicative ART
This file contains 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
// MART: Multiplicative ART | |
// Jean-Christophe Taveau | |
// 5 nov 2012 | |
// http://crazybiocomputing.blogspot.com | |
// ART Parameters | |
var nbCycles=5; | |
var relax=0.33; | |
// 1- Get sinogram information | |
var imp = IJ.getImage(); | |
var w=imp.getWidth(); | |
var nbProj=imp.getHeight(); | |
var step=180/nbProj; | |
// Create output and temporary images/stack | |
var rec = IJ.createImage("Rec2D", "32-bit Black", w, w, 1); | |
var recStack = IJ.createImage("Rec2D_Cycles", "32-bit Black", w, w, nbCycles); | |
var a = IJ.createImage("tmp", "32-bit Black", w, 1, 1); | |
var ic = new ImageCalculator(); | |
var stats = imp.getStatistics(); | |
var avg=stats.mean; | |
rec.getProcessor().setValue(avg); | |
rec.getProcessor().fill(); | |
// M a i n l o o p | |
// Comment out the following lines to see the ART in action | |
// rec.show(); | |
// recStack.show(); | |
for (var i=0;i<nbCycles;i++) | |
{ | |
for (var j=0;j<nbProj;j++) | |
{ | |
// 2- Compute projection from temporary 2D-rec | |
calcProj(rec,step*j); | |
// 3- Extract a 1D-projection (one row of sinogram) | |
imp.setRoi(0,j,imp.getWidth(), 1); | |
var proj = imp.duplicate(); | |
// 4- Compute the error between sinogram and calculated projections | |
ic.run("Divide",proj,a); | |
IJ.run(proj, "Macro...", "code=[v=pow(v,"+relax+");]"); | |
// 5- Create the backprojected ray from this err pixel and add it to rec; | |
IJ.run(proj, "Size...", "width="+w+" height="+w+" average interpolation=None"); | |
IJ.run(proj, "Rotate... ", "angle="+(-j * step)+" grid=1 interpolation=Bilinear fill"); | |
ic.run("Multiply",rec,proj); | |
} | |
recStack.setSlice(i+1); | |
recStack.setProcessor(rec.getProcessor().duplicate()); | |
} | |
rec.show(); | |
recStack.show(); | |
// F U N C T I O N S | |
function calcProj(img, rotangle) | |
{ | |
var tmp = img.duplicate(); | |
tmp.getProcessor().setBackgroundValue(0.0); | |
tmp.getProcessor().rotate(rotangle); | |
tmp.setRoi(0,0,tmp.getWidth(), tmp.getHeight()); | |
var plot = new ProfilePlot(tmp); | |
var data = plot.getProfile(); | |
for (var x in data) | |
a.getProcessor().putPixelValue(x,0,data[x]); | |
tmp.close(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment