use of ij.ImageStack in project GDSC-SMLM by aherbert.
the class FRC method getComplexFFT.
/**
* Convert an image into a Fourier image with real and imaginary parts
*
* @param ip
* The image
* @return the real and imaginary parts
*/
public FloatProcessor[] getComplexFFT(ImageProcessor ip) {
FloatProcessor taperedDataImage = getSquareTaperedImage(ip);
FHT2 fht = new FHT2(taperedDataImage);
fht.setShowProgress(false);
fht.transform();
ImageStack stack1 = fht.getComplexTransform();
return getProcessors(stack1);
}
use of ij.ImageStack in project GDSC-SMLM by aherbert.
the class IJImageSource method initialise.
private boolean initialise(ImagePlus imp) {
imageArray = null;
imageStack = null;
if (imp == null)
return false;
ImageStack s = imp.getImageStack();
if (s.isVirtual()) {
// We must use the image stack to get the image data for virtual images
imageStack = s;
} else {
// We can access the image array directly
imageArray = s.getImageArray();
}
width = imp.getWidth();
height = imp.getHeight();
// Store the number of valid frames
if (singleFrame > 0)
frames = 1 + this.extraFrames;
else
frames = imp.getStackSize();
slice = 0;
FileInfo info = imp.getOriginalFileInfo();
if (info != null)
path = info.directory + info.fileName;
return true;
}
use of ij.ImageStack in project GDSC-SMLM by aherbert.
the class DoubletAnalysis method run.
/**
* Run.
*/
private void run() {
doubletResults = null;
final ImageStack stack = imp.getImageStack();
// Get the coordinates per frame
TIntObjectHashMap<ArrayList<Coordinate>> actualCoordinates = ResultsMatchCalculator.getCoordinates(results.getResults(), false);
final long[] sumCount = new long[1];
actualCoordinates.forEachValue(new TObjectProcedure<ArrayList<Coordinate>>() {
public boolean execute(ArrayList<Coordinate> list) {
sumCount[0] += list.size();
return true;
}
});
final double density = 1e6 * sumCount[0] / (simulationParameters.a * simulationParameters.a * results.getBounds().getWidth() * results.getBounds().getHeight() * actualCoordinates.size());
// Create a pool of workers
final int nThreads = Prefs.getThreads();
final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
List<Worker> workers = new LinkedList<Worker>();
List<Thread> threads = new LinkedList<Thread>();
Overlay overlay = (showOverlay) ? new Overlay() : null;
for (int i = 0; i < nThreads; i++) {
Worker worker = new Worker(jobs, stack, actualCoordinates, fitConfig, overlay);
Thread t = new Thread(worker);
workers.add(worker);
threads.add(t);
t.start();
}
// Fit the frames
long runTime = System.nanoTime();
totalProgress = actualCoordinates.size();
stepProgress = Utils.getProgressInterval(totalProgress);
progress = 0;
actualCoordinates.forEachKey(new TIntProcedure() {
public boolean execute(int frame) {
put(jobs, frame);
return true;
}
});
// Finish all the worker threads by passing in a null job
for (int i = 0; i < threads.size(); i++) {
put(jobs, -1);
}
// Wait for all to finish
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
threads.clear();
threads = null;
IJ.showProgress(1);
IJ.showStatus("Collecting results ...");
runTime = System.nanoTime() - runTime;
// Collect the results
int cic = 0, daic = 0, dbic = 0;
ArrayList<DoubletResult> results = null;
int maxH = 0, maxH2 = 0, maxH3 = 0;
for (Worker worker : workers) {
if (results == null)
results = worker.results;
else
results.addAll(worker.results);
cic += worker.cic;
daic += worker.daic;
dbic += worker.dbic;
maxH = Maths.max(maxH, worker.spotHistogram.length);
for (int k = 0; k < 3; k++) {
maxH2 = Maths.max(maxH2, worker.neighbourHistogram[k].length);
maxH3 = Maths.max(maxH3, worker.almostNeighbourHistogram[k].length);
}
}
if (cic > 0)
System.out.printf("Difference AIC %d, BIC %d, Total %d\n", daic, dbic, cic);
if (showHistograms) {
double[] spotHistogram = new double[maxH];
double[] resultHistogram = new double[maxH];
double[][] neighbourHistogram = new double[3][maxH2];
double[][] almostNeighbourHistogram = new double[3][maxH3];
for (Worker worker : workers) {
final int[] h1a = worker.spotHistogram;
final int[] h1b = worker.resultHistogram;
for (int j = 0; j < h1a.length; j++) {
spotHistogram[j] += h1a[j];
resultHistogram[j] += h1b[j];
}
final int[][] h2 = worker.neighbourHistogram;
final int[][] h3 = worker.almostNeighbourHistogram;
for (int k = 0; k < 3; k++) {
for (int j = 0; j < h2[k].length; j++) neighbourHistogram[k][j] += h2[k][j];
for (int j = 0; j < h3[k].length; j++) almostNeighbourHistogram[k][j] += h3[k][j];
}
}
showHistogram(0, spotHistogram);
showHistogram(1, resultHistogram);
showHistogram(2, neighbourHistogram[0]);
showHistogram(3, neighbourHistogram[1]);
showHistogram(4, neighbourHistogram[2]);
showHistogram(5, almostNeighbourHistogram[0]);
showHistogram(6, almostNeighbourHistogram[1]);
showHistogram(7, almostNeighbourHistogram[2]);
}
workers.clear();
workers = null;
if (overlay != null)
imp.setOverlay(overlay);
MemoryPeakResults.freeMemory();
Collections.sort(results);
summariseResults(results, density, runTime);
windowOrganiser.tile();
IJ.showStatus("");
}
use of ij.ImageStack in project GDSC-SMLM by aherbert.
the class DriftCalculator method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
// Require some fit results and selected regions
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
Roi[] rois = getRois();
String[] stackTitles = createStackImageList();
if (!showDialog(rois, stackTitles))
return;
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() < 2) {
IJ.error(TITLE, "There are not enough fitting results for drift correction");
return;
}
double[][] drift = null;
int[] limits = findTimeLimits(results);
if (method.equals(MARKED_ROIS)) {
drift = calculateUsingMarkers(results, limits, rois);
} else if (method.equals(STACK_ALIGNMENT)) {
ImageStack stack = showStackDialog(stackTitles);
if (stack == null)
return;
drift = calculateUsingImageStack(stack, limits);
} else if (method.equals(DRIFT_FILE)) {
drift = calculateUsingDriftFile(limits);
} else {
if (!showSubImageDialog())
return;
drift = calculateUsingFrames(results, limits, Integer.parseInt(reconstructionSize));
}
if (drift == null)
return;
Utils.log("Drift correction interpolated for frames [%d - %d] of [%d - %d] (%s%%)", interpolationStart, interpolationEnd, limits[0], limits[1], Utils.rounded((100.0 * (interpolationEnd - interpolationStart + 1)) / (limits[1] - limits[0] + 1)));
applyDriftCorrection(results, drift);
}
use of ij.ImageStack in project GDSC-SMLM by aherbert.
the class DepthMask method createMask.
private void createMask() {
ImagePlus impXY = WindowManager.getImage(titleXY);
ImagePlus impXZ = WindowManager.getImage(titleXZ);
if (impXY == null) {
IJ.error(TITLE, "No XY mask");
return;
}
if (impXZ == null) {
IJ.error(TITLE, "No XZ mask");
return;
}
if (impXY.getWidth() != impXZ.getWidth()) {
IJ.error(TITLE, "XY mask width does not match XZ mask width");
return;
}
final int maxx = impXY.getWidth();
final int maxy = impXY.getHeight();
final int maxz = impXZ.getHeight();
ImageStack stack = new ImageStack(maxx, maxy, maxz);
byte[] maskXY = getMask(impXY);
byte[] maskXZ = getMask(impXZ);
byte[] strip = new byte[maxx];
for (int z = 0, p = 0; z < maxz; z++, p += maxx) {
byte[] mask = maskXY.clone();
System.arraycopy(maskXZ, p, strip, 0, maxx);
for (int y = 0, i = 0; y < maxy; y++) {
for (int x = 0; x < maxx; x++, i++) {
if (strip[x] == 0)
mask[i] = 0;
}
}
stack.setPixels(mask, z + 1);
}
Utils.display(TITLE, stack);
}
Aggregations