/** Perform the algorithm here */
  @Override
  public boolean run(JEXEntry entry, HashMap<String, JEXData> inputs) {
    try {
      /*
       * inputNames[2] = new TypeName(IMAGE, "Outer Boundary Image"); inputNames[3] = new TypeName(IMAGE, "Inner Boundary Image"); inputNames[4] = new TypeName(IMAGE, "Image To Quantify");
       */
      // Collect the inputs
      JEXData maximaData = getInputAs(inputs, "Maxima", ROI);
      if (maximaData == null) {
        return false;
      }
      JEXData segData = getInputAs(inputs, "Segmented Image", IMAGE);
      if (segData == null) {
        return false;
      }
      JEXData maskData = getInputAs(inputs, "Mask Image", IMAGE);
      if (maskData == null) {
        return false;
      }
      JEXData imageData = getInputAs(inputs, "Image To Quantify", IMAGE);
      if (imageData == null) {
        return false;
      }

      // Gather parameters
      // String op = this.parameters.getValueOfParameter("Measurement");

      DimTable imageTable = imageData.getDimTable();

      TreeMap<DimensionMap, ROIPlus> maximaMap = RoiReader.readObjectToRoiMap(maximaData);
      TreeMap<DimensionMap, String> segMap = ImageReader.readObjectToImagePathTable(segData);
      TreeMap<DimensionMap, String> maskMap = ImageReader.readObjectToImagePathTable(maskData);
      TreeMap<DimensionMap, String> imageMap = ImageReader.readObjectToImagePathTable(imageData);
      TreeMap<DimensionMap, Double> results = new TreeMap<DimensionMap, Double>();

      double count = 0;
      double total = imageTable.mapCount();

      for (DimensionMap map : imageTable.getMapIterator()) {
        if (this.isCanceled()) {
          return false;
        }
        this.runStuff(map, maximaMap, segMap, maskMap, imageMap, results, this);
        count = count + 1;
        JEXStatics.statusBar.setProgressPercentage((int) (100 * count / total));
      }

      String resultsFile = JEXTableWriter.writeTable(this.outputNames[0].getName(), results);
      JEXData output0 = FileWriter.makeFileObject(this.outputNames[0].getName(), null, resultsFile);

      // Set the outputs
      this.realOutputs.add(output0);

      // Return status
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
示例#2
0
  @Override
  public boolean run(JEXEntry optionalEntry) {
    if (imageData == null || !imageData.getTypeName().getType().equals(JEXData.IMAGE)) {
      return false;
    }

    // Run the function
    TreeMap<DimensionMap, String> images = ImageReader.readObjectToImagePathTable(imageData);
    TreeMap<DimensionMap, String> outputMap = new TreeMap<DimensionMap, String>();

    int count = 0;
    int total = images.size();
    for (DimensionMap dim : images.keySet()) {

      if (this.isCanceled()) {
        return false;
      }

      String path = images.get(dim);
      // File f = new File(path);

      // get the image
      ImagePlus im = new ImagePlus(path);
      ij.process.ImageProcessor imProc = im.getProcessor();
      if (imProc == null) continue;
      FloatProcessor imp =
          (FloatProcessor) im.getProcessor().convertToFloat(); // should be a float processor

      int newWidth = (int) (imp.getWidth() * scale);
      imp.setInterpolationMethod(ImageProcessor.BILINEAR);
      imp = (FloatProcessor) imp.resize(newWidth);

      ImagePlus toSave = FunctionUtility.makeImageToSave(imp, "false", bitDepth);
      String finalPath = JEXWriter.saveImage(toSave);

      outputMap.put(dim.copy(), finalPath);
      Logs.log("Finished processing " + count + " of " + total + ".", 1, this);
      count++;

      // Status bar
      int percentage = (int) (100 * ((double) count / (double) images.size()));
      JEXStatics.statusBar.setProgressPercentage(percentage);
    }

    // Set the outputs
    output = ImageWriter.makeImageStackFromPaths("temp", outputMap);
    output.setDataObjectInfo("Stack binned using binning function");

    // Return status
    return true;
  }
示例#3
0
  AdjustImageHelperFunction(
      JEXData imset, JEXEntry entry, TypeName[] outputNames, ParameterSet parameters) {
    // Pass the variables
    this.imset = imset;
    this.params = parameters;
    this.entry = entry;
    this.outputNames = outputNames;

    // //// Get params
    auto = Boolean.parseBoolean(params.getValueOfParameter("Automatic"));
    oldMin = Double.parseDouble(params.getValueOfParameter("Old Min"));
    oldMax = Double.parseDouble(params.getValueOfParameter("Old Max"));
    newMin = Double.parseDouble(params.getValueOfParameter("New Min"));
    newMax = Double.parseDouble(params.getValueOfParameter("New Max"));
    gamma = Double.parseDouble(params.getValueOfParameter("Gamma"));
    depth = Integer.parseInt(params.getValueOfParameter("Output Bit Depth"));

    TreeMap<DimensionMap, JEXDataSingle> map = imset.getDataMap();
    int length = map.size();

    images = new String[length];
    dimensions = new DimensionMap[length];
    int i = 0;
    TreeMap<DimensionMap, String> pathMap = ImageReader.readObjectToImagePathTable(imset);
    for (DimensionMap dim : pathMap.keySet()) {
      String path = pathMap.get(dim);
      dimensions[i] = dim;
      images[i] = path;
      i++;
    }

    // Prepare the graphics
    imagepanel = new ImagePanel(this, "Adjust image");
    displayImage(index);
    wrap = new GraphicalFunctionWrap(this, params);
    wrap.addStep(
        0,
        "Select roi",
        new String[] {"Automatic", "Old Min", "Old Max", "New Min", "New Max", "Output Bit Depth"});
    wrap.setInCentralPanel(imagepanel);
    wrap.setDisplayLoopPanel(true);
  }
示例#4
0
  /** Apply the roi to all other images */
  public void finishIT() {
    auto = Boolean.parseBoolean(params.getValueOfParameter("Automatic"));
    oldMin = Double.parseDouble(params.getValueOfParameter("Old Min"));
    oldMax = Double.parseDouble(params.getValueOfParameter("Old Max"));
    newMin = Double.parseDouble(params.getValueOfParameter("New Min"));
    newMax = Double.parseDouble(params.getValueOfParameter("New Max"));
    gamma = Double.parseDouble(params.getValueOfParameter("Gamma"));
    depth = Integer.parseInt(params.getValueOfParameter("Output Bit Depth"));

    output = new JEXData(JEXData.IMAGE, outputNames[0].getName(), "Adjusted image");

    // Run the function
    // TreeMap<DimensionMap,JEXDataSingle> map = imset.getDataMap();
    TreeMap<DimensionMap, String> pathMap = ImageReader.readObjectToImagePathTable(imset);
    int count = 0;
    int total = pathMap.size();
    JEXStatics.statusBar.setProgressPercentage(0);

    TreeMap<DimensionMap, String> imMap = new TreeMap<DimensionMap, String>();
    for (DimensionMap dim : pathMap.keySet()) {
      // JEXDataSingle ds = map.get(dim);
      // String imagePath = ds.get(JEXDataSingle.FOLDERNAME) +
      // File.separator + ds.get(JEXDataSingle.FILENAME);
      String imagePath = pathMap.get(dim);
      // File imageFile = new File(imagePath);
      // String imageName = imageFile.getName();

      // get the image
      im = new ImagePlus(imagePath);
      imp = (FloatProcessor) im.getProcessor().convertToFloat(); // should
      // be a
      // float
      // processor

      // //// Begin Actual Function
      adjustImage();
      // //// End Actual Function

      // //// Save the results
      ImagePlus toSave = FunctionUtility.makeImageToSave(imp, "false", depth);
      String imPath = JEXWriter.saveImage(toSave);

      // Put into imMap
      imMap.put(dim, imPath);

      // String localDir = JEXWriter.getEntryFolder(entry);
      // String newFileName = FunctionUtility.getNextName(localDir,
      // imageName, "A");
      // String newImagePath = localDir + File.separator + newFileName;
      // FunctionUtility.imSave(imp, "false", depth, newImagePath);
      //
      // // Put into imMap
      // imMap.put(dim, localDir + File.separator + newFileName) ;

      // JEXDataSingle outputds = new DefaultJEXDataSingle();
      // outputds.put(JEXDataSingle.FOLDERNAME, localDir);
      // outputds.put(JEXDataSingle.FILENAME, newFileName);
      // output.addData(dim,outputds);

      // Increment count
      Logs.log("Finished processing " + count + " of " + total + ".", 1, this);
      count++;

      // Status bar
      int percentage = (int) (100 * ((double) count / (double) pathMap.size()));
      JEXStatics.statusBar.setProgressPercentage(percentage);
    }

    output = ImageWriter.makeImageStackFromPaths(outputNames[0].getName(), imMap);
  }
  /** Perform the algorithm here */
  @Override
  public boolean run(JEXEntry entry, HashMap<String, JEXData> inputs) {
    // Collect the inputs
    JEXData data1 = inputs.get("Image to quantify");
    JEXData data2 = inputs.get("Mask");
    if (data1 == null || !data1.getTypeName().getType().equals(JEXData.IMAGE)) return false;

    // Run the function
    TreeMap<DimensionMap, String> images = ImageReader.readObjectToImagePathTable(data1);
    TreeMap<DimensionMap, String> masks = ImageReader.readObjectToImagePathTable(data2);

    // Prepare the outputs
    TreeMap<DimensionMap, String> means = new TreeMap<DimensionMap, String>();
    TreeMap<DimensionMap, String> areas = new TreeMap<DimensionMap, String>();
    TreeMap<DimensionMap, String> intdens = new TreeMap<DimensionMap, String>();

    // Do the calculation
    for (DimensionMap dim : images.keySet()) {
      // prepare the variables
      double mean = 0;
      double area = 0;
      double intden = 0;

      // Open the image to quantify
      String imPath = images.get(dim);
      ImagePlus imp = new ImagePlus(imPath);

      // Open the mask
      String maskPath = masks.get(dim);
      ImagePlus imm = new ImagePlus(maskPath);

      // calculate integrated intensity in the image to quantify
      ImageStatistics imStat = imp.getStatistics();
      intden = imStat.mean * imStat.area;

      // Calculate the area of the mask
      ImageStatistics maskStat = imm.getStatistics();
      area = maskStat.mean * maskStat.area / maskStat.max;

      // Calculate the mean intensity in the image to quanfity
      mean = intden / area;

      // save the variables
      means.put(dim, "" + mean);
      areas.put(dim, "" + area);
      intdens.put(dim, "" + intden);
    }

    // Make the outputs
    JEXData output1 = ValueWriter.makeValueTable(outputNames[0].getName(), means);
    JEXData output2 = ValueWriter.makeValueTable(outputNames[1].getName(), areas);
    JEXData output3 = ValueWriter.makeValueTable(outputNames[2].getName(), intdens);

    // Set the outputs
    realOutputs.add(output1);
    realOutputs.add(output2);
    realOutputs.add(output3);

    // Return status
    return true;
  }