Ejemplo n.º 1
0
  public int[] outlineRect(Rectangle rect, int lineWeight) {
    int[] pixels = img.getPixelValues();
    Rectangle innerFrame =
        new Rectangle(
            rect.x + lineWeight,
            rect.y + lineWeight,
            rect.width - (2 * lineWeight),
            rect.height - (2 * lineWeight));
    for (int y = 0; y < img.getImageHeight(); y++) {
      for (int x = 0; x < img.getImageWidth(); x++) {
        if (rect.contains(x, y) && !innerFrame.contains(x, y)) {
          pixels[y * img.getImageWidth() + x] = this.color;
        }
      }
    }

    return pixels;
  }
Ejemplo n.º 2
0
  /**
   * Constructs an image information class based on the 5D image source, and the individual set of
   * pixels desired in that image. Needs Factory to query the database about statistics. (this might
   * not be a good thing)
   *
   * @param imageSource The image to store information about.
   * @param pixels The pixel source of the image.
   * @param dataSource The factory used to access the OME database. Is there a better way to do
   *     this?
   */
  public ImageInformation(Image imageSource, ImagePixels pixels, Factory dataSource) {
    this.imageSource = imageSource;
    this.pixels = pixels;
    this.pixelsAttribute = pixels.getPixelsAttribute();
    this.dataSource = dataSource;

    Map imageSourceMap = new HashMap();
    imageSourceMap.put("target", imageSource);

    // extract the channel/wavelength information for this image.
    List channelComponents = dataSource.findAttributes("PixelChannelComponent", imageSourceMap);

    final int pixelsID = pixelsAttribute.getID();

    // this taken straight out of the SVG viewer code
    // might be a faster/better/less OME-call-intensive way to do it
    channelComponents =
        Filter.grep(
            channelComponents,
            new GrepOperator() {
              public boolean eval(Object o) {
                Attribute attribute = (Attribute) o;
                Attribute pixels = attribute.getAttributeElement("Pixels");
                return pixels.getID() == pixelsID;
              }
            });

    channelInfo = new Wavelength[channelComponents.size()];
    for (int i = 0; i < channelComponents.size(); i++) {
      Attribute channel = (Attribute) channelComponents.get(i);
      channelInfo[i] = new Wavelength(channel.getIntElement("Index"));
    }

    CBS = ChannelBlackScaleData.getDefaultChannelScale(channelInfo);
    cbsMap = new HashMap();

    // hopefully this doesn't break right here

    // extract the proper stack statistics for this image,
    // this might be done the hard way (I dunno)

    Map moduleConstraints = new HashMap();
    moduleConstraints.put("name", "Fast Stack statistics");

    Module stackModule = (Module) dataSource.findObject("OME::Module", moduleConstraints);

    Map formalInputConstraints = new HashMap();
    formalInputConstraints.put("module_id", new Integer(stackModule.getID()));
    formalInputConstraints.put("name", "Pixels");

    Module.FormalInput formalInput =
        (Module.FormalInput)
            dataSource.findObject("OME::Module::FormalInput", formalInputConstraints);

    RemoteModuleExecution moduleExecution =
        (RemoteModuleExecution) pixelsAttribute.getModuleExecution();

    Map actualInputConstraints = new HashMap();
    actualInputConstraints.put("formal_input_id", new Integer(formalInput.getID()));
    actualInputConstraints.put("input_module_execution_id", new Integer(moduleExecution.getID()));

    ModuleExecution.ActualInput actualInput =
        (ModuleExecution.ActualInput)
            dataSource.findObject("OME::ModuleExecution::ActualInput", actualInputConstraints);

    final int stackAnalysisID = actualInput.getModuleExecution().getID();

    // retrieve statistics
    List stackMins = dataSource.findAttributes("StackMinimum", imageSourceMap);
    List stackMaxes = dataSource.findAttributes("StackMaximum", imageSourceMap);
    List stackMeans = dataSource.findAttributes("StackMean", imageSourceMap);
    List stackSigmas = dataSource.findAttributes("StackSigma", imageSourceMap);
    List stackGeomeans = dataSource.findAttributes("StackGeometricMean", imageSourceMap);
    List stackGeosigmas = dataSource.findAttributes("StackGeometricSigma", imageSourceMap);

    GrepOperator stackIDOperator =
        new GrepOperator() {
          public boolean eval(Object o) {
            Attribute attribute = (Attribute) o;
            RemoteModuleExecution execution =
                (RemoteModuleExecution) attribute.getModuleExecution();
            if (execution.getID() == stackAnalysisID) {
              return true;
            } else return false;
          }
        };

    List usableMins = Filter.grep(stackMins, stackIDOperator);
    List usableMaxes = Filter.grep(stackMaxes, stackIDOperator);
    List usableMeans = Filter.grep(stackMeans, stackIDOperator);
    List usableSigmas = Filter.grep(stackSigmas, stackIDOperator);
    List usableGeomeans = Filter.grep(stackGeomeans, stackIDOperator);
    List usableGeosigmas = Filter.grep(stackGeosigmas, stackIDOperator);

    sizeX = pixelsAttribute.getIntElement("SizeX");
    sizeY = pixelsAttribute.getIntElement("SizeY");
    sizeZ = pixelsAttribute.getIntElement("SizeZ");
    sizeC = pixelsAttribute.getIntElement("SizeC");
    sizeT = pixelsAttribute.getIntElement("SizeT");
    bitsPerPixel = pixelsAttribute.getIntElement("BitsPerPixel");

    stackStats = new StackStatistics[sizeC][sizeT];

    // initialize array
    for (int i = 0; i < sizeC; i++) {
      for (int j = 0; j < sizeT; j++) {
        stackStats[i][j] = new StackStatistics();
      }
    }

    // populate internal data structures
    for (Iterator iter = usableMins.iterator(); iter.hasNext(); ) {
      Attribute stackMin = (Attribute) iter.next();
      int theC = stackMin.getIntElement("TheC");
      int theT = stackMin.getIntElement("TheT");
      stackStats[theC][theT].setMin(stackMin.getIntElement("Minimum"));
    }

    for (Iterator iter = usableMaxes.iterator(); iter.hasNext(); ) {
      Attribute stackMax = (Attribute) iter.next();
      int theC = stackMax.getIntElement("TheC");
      int theT = stackMax.getIntElement("TheT");
      stackStats[theC][theT].setMax(stackMax.getIntElement("Maximum"));
    }

    for (Iterator iter = usableMeans.iterator(); iter.hasNext(); ) {
      Attribute stackMean = (Attribute) iter.next();
      int theC = stackMean.getIntElement("TheC");
      int theT = stackMean.getIntElement("TheT");
      stackStats[theC][theT].setMean(stackMean.getFloatElement("Mean"));
    }

    for (Iterator iter = usableSigmas.iterator(); iter.hasNext(); ) {
      Attribute stackSigma = (Attribute) iter.next();
      int theC = stackSigma.getIntElement("TheC");
      int theT = stackSigma.getIntElement("TheT");
      stackStats[theC][theT].setSigma(stackSigma.getFloatElement("Sigma"));
    }

    for (Iterator iter = usableGeomeans.iterator(); iter.hasNext(); ) {
      Attribute stackMean = (Attribute) iter.next();
      int theC = stackMean.getIntElement("TheC");
      int theT = stackMean.getIntElement("TheT");
      stackStats[theC][theT].setGeoMean(stackMean.getFloatElement("GeometricMean"));
    }

    for (Iterator iter = usableGeosigmas.iterator(); iter.hasNext(); ) {
      Attribute stackSigma = (Attribute) iter.next();
      int theC = stackSigma.getIntElement("TheC");
      int theT = stackSigma.getIntElement("TheT");
      stackStats[theC][theT].setGeoSigma(stackSigma.getFloatElement("GeometricSigma"));
    }
  }