示例#1
0
  /**
   * This method exists for the following reason:
   *
   * <p>The segmenter receives at each frame a cropped image to operate on, depending on the user
   * specifying a ROI. It therefore returns spots whose coordinates are with respect to the top-left
   * corner of the ROI, not of the original image.
   *
   * <p>This method modifies the given spots to put them back in the image coordinate system.
   * Additionally, is a non-square ROI was specified (e.g. a polygon), it prunes the spots that are
   * not within the polygon of the ROI.
   *
   * @param spotsThisFrame the spot list to inspect
   * @param settings the {@link Settings} object that will be used to retrieve the image ROI and
   *     cropping information
   * @return a list of spot. Depending on the presence of a polygon ROI, it might be a new, pruned
   *     list. Or not.
   */
  protected List<Spot> translateAndPruneSpots(
      final List<Spot> spotsThisFrame, final Settings settings) {
    // Get Roi
    final Polygon polygon;
    if (null == settings.imp || null == settings.imp.getRoi()) {
      polygon = null;
    } else {
      polygon = settings.imp.getRoi().getPolygon();
    }

    // Put them back in the right referential
    final float[] calibration = settings.getCalibration();
    TMUtils.translateSpots(
        spotsThisFrame,
        settings.xstart * calibration[0],
        settings.ystart * calibration[1],
        settings.zstart * calibration[2]);
    List<Spot> prunedSpots;
    // Prune if outside of ROI
    if (null != polygon) {
      prunedSpots = new ArrayList<Spot>();
      for (Spot spot : spotsThisFrame) {
        if (polygon.contains(
            spot.getFeature(Spot.POSITION_X) / calibration[0],
            spot.getFeature(Spot.POSITION_Y) / calibration[1])) prunedSpots.add(spot);
      }
    } else {
      prunedSpots = spotsThisFrame;
    }
    return prunedSpots;
  }
示例#2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  protected List<Spot> execSingleFrameSegmentation(
      final Image<? extends RealType<?>> img, Settings settings, int frameIndex) {

    final float[] calibration = settings.getCalibration();
    SpotSegmenter segmenter = settings.segmenter.createNewSegmenter();
    segmenter.setTarget(img, calibration, settings.segmenterSettings);

    if (segmenter.checkInput() && segmenter.process()) {
      List<Spot> spotsThisFrame = segmenter.getResult();
      return translateAndPruneSpots(spotsThisFrame, settings);

    } else {
      model.getLogger().error(segmenter.getErrorMessage() + '\n');
      return null;
    }
  }