void loadParticleResults(String filename, ResultsTable res) { try { String line; FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); java.lang.String header = " Intensity X (px) Y (px) X (nm) Y (nm) Z (nm) Left-Width(px) Right-Width (px) Up-Height (px) Down-Height (px) X Symmetry (%) Y Symmetry (%) Width minus Height (px) Frame Number"; java.lang.String firstline = br.readLine(); if (!firstline.contains("X (px) Y (px) X (nm) Y (nm) Z (nm)")) { IJ.error("File does not seam to be a Particles Table file"); IJ.log("Found header: " + firstline); IJ.log("Expecting: " + header); return; } res.reset(); int counter = 1; java.util.concurrent.locks.Lock lock = new java.util.concurrent.locks.ReentrantLock(); ThreadedLoader tloader = new ThreadedLoader(); // java.lang.String txt = fr.read(); while ((line = br.readLine()) != null) { tloader = new ThreadedLoader(); tloader.mysetup(res, lock, line); tloader.start(); IJ.showStatus("Loading particle " + counter + "... sit back and relax."); counter++; } try { tloader.join(); } catch (Exception e) { IJ.error("" + e); } if (res.getCounter() < 5000000) { IJ.showStatus("Creating particle table, this should take a few seconds..."); res.show("Results"); } else IJ.showMessage( "Warning", "Results table has too many particles, they will not be shown but the data still exists within it\nyou can still use all the plugin functionality or save table changes though the 'Save Particle Table' command."); fr.close(); IJ.showStatus("Done loading table..."); } catch (FileNotFoundException e) { IJ.error("File not found exception" + e); return; } catch (IOException e) { IJ.error("IOException exception" + e); return; } catch (NumberFormatException e) { IJ.error("Number format exception" + e); return; } }
void loadTransformation(String filename, ResultsTable res) { try { String line; FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); if (!br.readLine().equals(" Z-Step Raw Width minus Heigh Calibration Width minus Height")) { IJ.error("File does not seam to be an Astigmatism calibration file"); return; } // java.lang.String [] elements = new java.lang.String [3]; java.lang.String[] elements; int counter = 1; res.reset(); while ((line = br.readLine()) != null) { IJ.showStatus("Loading element " + counter + "... sit back and relax."); counter++; line.trim(); elements = line.split("\t"); res.incrementCounter(); res.addValue("Z-Step", Double.parseDouble(elements[1])); res.addValue("Raw Width minus Heigh", Double.parseDouble(elements[2])); res.addValue("Calibration Width minus Height", Double.parseDouble(elements[3])); } fr.close(); } catch (FileNotFoundException e) { IJ.error("File not found exception" + e); return; } catch (IOException e) { IJ.error("IOException exception" + e); return; } catch (NumberFormatException e) { IJ.error("Number format exception" + e); return; } }
/** Performs actual projection using specified method. */ public void doProjection() { if (imp == null) return; sliceCount = 0; if (method < AVG_METHOD || method > MEDIAN_METHOD) method = AVG_METHOD; for (int slice = startSlice; slice <= stopSlice; slice += increment) sliceCount++; if (method == MEDIAN_METHOD) { projImage = doMedianProjection(); return; } // Create new float processor for projected pixels. FloatProcessor fp = new FloatProcessor(imp.getWidth(), imp.getHeight()); ImageStack stack = imp.getStack(); RayFunction rayFunc = getRayFunction(method, fp); if (IJ.debugMode == true) { IJ.log("\nProjecting stack from: " + startSlice + " to: " + stopSlice); } // Determine type of input image. Explicit determination of // processor type is required for subsequent pixel // manipulation. This approach is more efficient than the // more general use of ImageProcessor's getPixelValue and // putPixel methods. int ptype; if (stack.getProcessor(1) instanceof ByteProcessor) ptype = BYTE_TYPE; else if (stack.getProcessor(1) instanceof ShortProcessor) ptype = SHORT_TYPE; else if (stack.getProcessor(1) instanceof FloatProcessor) ptype = FLOAT_TYPE; else { IJ.error("Z Project", "Non-RGB stack required"); return; } // Do the projection. for (int n = startSlice; n <= stopSlice; n += increment) { IJ.showStatus("ZProjection " + color + ": " + n + "/" + stopSlice); IJ.showProgress(n - startSlice, stopSlice - startSlice); projectSlice(stack.getPixels(n), rayFunc, ptype); } // Finish up projection. if (method == SUM_METHOD) { fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else if (method == SD_METHOD) { rayFunc.postProcess(); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else { rayFunc.postProcess(); projImage = makeOutputImage(imp, fp, ptype); } if (projImage == null) IJ.error("Z Project", "Error computing projection."); }
ImagePlus doMedianProjection() { IJ.showStatus("Calculating median..."); ImageStack stack = imp.getStack(); ImageProcessor[] slices = new ImageProcessor[sliceCount]; int index = 0; for (int slice = startSlice; slice <= stopSlice; slice += increment) slices[index++] = stack.getProcessor(slice); ImageProcessor ip2 = slices[0].duplicate(); ip2 = ip2.convertToFloat(); float[] values = new float[sliceCount]; int width = ip2.getWidth(); int height = ip2.getHeight(); int inc = Math.max(height / 30, 1); for (int y = 0; y < height; y++) { if (y % inc == 0) IJ.showProgress(y, height - 1); for (int x = 0; x < width; x++) { for (int i = 0; i < sliceCount; i++) values[i] = slices[i].getPixelValue(x, y); ip2.putPixelValue(x, y, median(values)); } } if (imp.getBitDepth() == 8) ip2 = ip2.convertToByte(false); IJ.showProgress(1, 1); return new ImagePlus(makeTitle(), ip2); }