for ratio in skipRatios: for iterations in maxIterations: for filterB in filters: for contact in contacts: for step in steps: f = open(logfilename, 'ab') sourceName = workingDir+localDir+image print(sourceName) print(rep) i = ImgOpener(); sourceImg = i.openImgs(sourceName).get(0) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1,1,1] units = ["","",""] source = ImgPlus(sourceImg,image,axes,calibration,units) name = source.getName() print("name: "+name) imp = IJ.openImage(sourceName) # need for skeletonization imp.show() name = name+"-runs-"+str(rep)+"-weighted-"+str(wa)+"-maxShift-"+str(maxShift)+"-vectors-"+str(vectors)+"-ratio-"+str(ratio)+"-maxIts-"+str(iterations)+"-filter-"+str(filterB)+"-contact-"+str(contact)+"-step-"+str(step*1.0/2.3) startTime = time.time() wrapper = cs.run("org.bonej.wrapperPlugins.EllipsoidFactorWrapper",False,["inputImgPlus",source,"nVectors", vectors, "vectorIncrement", step*1.0/2.3, "skipRatio",ratio,"contactSensitivity",contact,"maxIterations",iterations, "maxDrift",maxShift*1.73,"minimumSemiAxis",filterB,"seedOnDistanceRidge",True,"seedOnTopologyPreserving",True,"showSecondaryImages",True,"runs",rep,"weightedAverageN",wa,"distanceThreshold",distanceThreshold]) wrapperInstance = wrapper.get() outputs = wrapperInstance.getOutput("ellipsoidFactorOutputImages"); seeds = wrapperInstance.getOutput("seedPointImage"); parameters = [image,rep,wa,maxShift,vectors,ratio,iterations,filterB,contact,distanceThreshold,time.time()-startTime] print(len(outputs)) EF = outputs.get(0)# 0 item is EF image imp.close()
quoting=csv.QUOTE_MINIMAL) for image in files: for points in maxSeedPoints: for threshold in thresholds: for nDirections in nSearchDirections: sourceName = workingDir + localDir + image print(sourceName) startTime = time.time() i = ImgOpener() sourceImg = i.openImgs(sourceName).get(0) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1, 1, 1] units = ["", "", ""] source = ImgPlus(sourceImg, image, axes, calibration, units) name = source.getName() name = name + "_" + str(points) + "_points_" + str( threshold) + "_threshold_" + str( nDirections) + "_directions_" wrapper = cs.run( "org.bonej.wrapperPlugins.EllipsoidFactorWrapper", True, [ "inputImage", source, "nSphere", nDirections, "approximateMaximumNumberOfSeeds", points, "thresholdForBeingARidgePoint", threshold, "showSecondaryImages", True ]) wrapperInstance = wrapper.get() EF = wrapperInstance.getOutput("efImage") d = DefaultDataset(ctxt, EF)
for directions in nDirections: for skipRatio in skipRatios: try: sourceName = workingDir+localDir+image; i = ImgOpener(); print(i) print(sourceName); print("directions = ", directions, " skipRatio = ", skipRatio) sourceImg = i.openImgs(sourceName).get(0) print(sourceImg) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1,1,1] units = ["","",""] source = ImgPlus(sourceImg,image,axes,calibration,units) #ds.createDisplay(source) name = source.getName() name = name + "_dir_" + str(directions) + "_sr_"+str(skipRatio) startTime = time.time() wrapper = cs.run("org.bonej.wrapperPlugins.EllipsoidFactorWrapper",False,["inputImgPlus",source,"nVectors", directions, "vectorIncrement", 1/2.3, "skipRatio",skipRatio,"contactSensitivity",1,"maxIterations",100, "maxDrift",1.73,"sigma",0,"showSecondaryImages",True]) wrapperInstance = wrapper.get() EF = wrapperInstance.getOutput("efImage") timeTaken = time.time()-startTime print("done") print(timeTaken) table = wrapperInstance.getOutput("resultsTable") print(table) print(table[0]) print(len(table)) d = DefaultDataset(ctxt,EF) io.save(d, "/media/alessandro/A6E8FE87E8FE5551/Users/afelder/Desktop/EF-ported/"+name+"-EF.tif")
delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) parameter_writer.writerow(["name", histoBins]) for image in files: sourceName = workingDir + "EF/" + image + "-runs-6-weighted-1-maxShift-1-vectors-100-ratio-1-maxIts-50-filter-0-contact-5-step-0.217391304348" + "-EF.tif" print(sourceName) startTime = time.time() i = ImgOpener() sourceImg = i.openImgs(sourceName).get(0) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1, 1, 1] units = ["", "", ""] source = ImgPlus(sourceImg, image, axes, calibration, units) name = source.getName() histoMapper = Real1dBinMapper(-1, 1, 50, False) histo = Histogram1d(histoMapper) histo.countData(source) print(histoBins) histoBinFreqs = histo.toLongArray() print("freq: ", histoBinFreqs) histoMults = [ abs(histoBinFreqs[i] * histoBins[i] / 100.0) for i in range(len(histoBins)) ] print(histoMults) total = histo.distributionCount() print(total)
quotechar='"', quoting=csv.QUOTE_MINIMAL) for image in files: for nDirections in nSearchDirections: sourceName = workingDir + localDir + "../EF-ported/" + image + "_" + str( nDirections) + "-EF.tif" print(sourceName) startTime = time.time() i = ImgOpener() sourceImg = i.openImgs(sourceName).get(0) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1, 1, 1] units = ["", "", ""] source = ImgPlus(sourceImg, image, axes, calibration, units) name = source.getName() name = name + "_" + str(nDirections) histoMapper = Real1dBinMapper(-1, 1, 50, False) histo = Histogram1d(histoMapper) histo.countData(source) print(histoBins) histoBinFreqs = histo.toLongArray() print(histoBinFreqs) histoMults = [ histoBinFreqs[i] * histoBins[i] / 100.0 for i in range(len(histoBins)) ] print(histoMults) total = histo.distributionCount()
parameter_writer.writerow(["name",histoBins]) for image in files: for filterB in filters: for contact in contacts: for step in steps: sourceName = workingDir+"EF/"+image+"-runs-6-weighted-1-maxShift-1-vectors-100-ratio-1-maxIts-50-filter-"+str(filterB)+"-contact-"+str(contact)+"-step-"+str(step+"-EF.tif"; print(sourceName); startTime = time.time() i = ImgOpener(); sourceImg = i.openImgs(sourceName).get(0) axes = [Axes.X, Axes.Y, Axes.Z] calibration = [1,1,1] units = ["","",""] source = ImgPlus(sourceImg,image,axes,calibration,units) name = source.getName() histoMapper = Real1dBinMapper(-1,1,50,False) histo = Histogram1d(histoMapper) histo.countData(source) print(histoBins) histoBinFreqs = histo.toLongArray() print("freq: ",histoBinFreqs) histoMults = [abs(histoBinFreqs[i]*histoBins[i]/100.0) for i in range(len(histoBins))] print(histoMults) total = histo.distributionCount() print(total) meanEFestimate = sum(histoMults)/total#not exact, based on histogram! print(meanEFestimate) print("done")