示例#1
0
  public final void run(
      final ImagePlus imp,
      final int width,
      final int height,
      final double minLambda,
      final double minPhi,
      final double hfov,
      final double vfov) {
    ip = imp.getProcessor().createProcessor(width, height);
    final ImagePlus impViewer = new ImagePlus("Panorama View", ip);

    /* initialize projection */
    p.setMinLambda(minLambda);
    p.setMinPhi(minPhi);
    p.setLambdaPiScale(Math.PI / hfov * imp.getWidth());
    p.setPhiPiScale(Math.PI / vfov * (imp.getHeight() - 1));
    p.setTargetWidth(ip.getWidth());
    p.setTargetHeight(ip.getHeight());
    p.setF(0.5);

    System.out.println(p.getLambdaPiScale() + " " + p.getPhiPiScale());

    /* TODO calculate proper size */

    // final int cubeSize = 500;
    final int cubeSize =
        (int) Math.round(Math.max(p.getPhiPiScale(), p.getLambdaPiScale()) * 2.0 / Math.PI);

    frontSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);
    backSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);
    leftSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);
    rightSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);
    topSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);
    bottomSource = ip.createProcessor(cubeSize + 1, cubeSize + 1);

    renderCubeFaces(hfov, vfov);

    /* instantiate and run mapper and painter */
    final Mapper mapper =
        new CubeFaceMapper(
            frontSource, backSource, leftSource, rightSource, topSource, bottomSource, p);
    painter = new MappingThread(imp, impViewer, mapper, ip, p);

    impViewer.show();

    gui = new GUI(impViewer);

    gui.backupGui();
    gui.takeOverGui();

    painter.start();
    update(false);
  }
 public ImageProcessor expandImage(ImageProcessor ipOld, int wNew, int hNew, int xOff, int yOff) {
   ImageProcessor ipNew = ipOld.createProcessor(wNew, hNew);
   if (zeroFill) ipNew.setValue(0.0);
   else ipNew.setColor(Toolbar.getBackgroundColor());
   ipNew.fill();
   ipNew.insert(ipOld, xOff, yOff);
   return ipNew;
 }
示例#3
0
  private final void renderCubeFaces(final double hfov, final double vfov) {
    /* fragile, but that's not public API and we know what we're doing... */
    final double cubeSize = frontSource.getWidth() - 1;

    /* prepare extended image */
    ipSource =
        ip.createProcessor(
            hfov == 2.0 * Math.PI ? imp.getWidth() + 1 : imp.getWidth(),
            vfov == Math.PI ? imp.getHeight() + 1 : imp.getHeight());
    prepareExtendedImage(imp.getProcessor(), ipSource);

    /* render cube faces */
    final EquirectangularProjection q = p.clone();
    q.resetOrientation();
    q.setTargetWidth(cubeSize);
    q.setTargetHeight(cubeSize);
    q.setF(0.5f);

    final InverseTransformMapping<EquirectangularProjection> qMapping =
        new InverseTransformMapping<EquirectangularProjection>(q);

    IJ.showStatus("Rendering cube faces...");
    IJ.showProgress(0, 6);
    qMapping.mapInterpolated(ipSource, frontSource);
    IJ.showProgress(1, 6);
    q.pan(Math.PI);
    qMapping.mapInterpolated(ipSource, backSource);
    IJ.showProgress(2, 6);
    q.resetOrientation();
    q.pan(Math.PI / 2);
    qMapping.mapInterpolated(ipSource, leftSource);
    IJ.showProgress(3, 6);
    q.resetOrientation();
    q.pan(-Math.PI / 2);
    qMapping.mapInterpolated(ipSource, rightSource);
    IJ.showProgress(4, 6);
    q.resetOrientation();
    q.tilt(-Math.PI / 2);
    qMapping.mapInterpolated(ipSource, topSource);
    IJ.showProgress(5, 6);
    q.resetOrientation();
    q.tilt(Math.PI / 2);
    qMapping.mapInterpolated(ipSource, bottomSource);
    IJ.showProgress(6, 6);

    if (showCubefaces) {
      new ImagePlus("front", frontSource).show();
      new ImagePlus("back", backSource).show();
      new ImagePlus("left", leftSource).show();
      new ImagePlus("right", rightSource).show();
      new ImagePlus("top", topSource).show();
      new ImagePlus("bottom", bottomSource).show();
    }
  }
示例#4
0
 ImageProcessor expand(ImageProcessor ip, boolean hasEdgePixels) {
   if (hasEdgePixels) {
     ImageProcessor ip2 = ip.createProcessor(ip.getWidth() + 2, ip.getHeight() + 2);
     if (foreground == 0) {
       ip2.setColor(255);
       ip2.fill();
     }
     ip2.insert(ip, 1, 1);
     // new ImagePlus("ip2", ip2).show();
     return ip2;
   } else return ip;
 }
示例#5
0
    public MappingThread(
        final ImagePlus impSource,
        final ImagePlus impTarget,
        final Mapper mapper,
        final ImageProcessor target,
        final PanoramaCamera<?> camera) {
      this.impSource = impSource;
      this.impTarget = impTarget;

      this.mapper = mapper;

      this.target = target;
      this.temp = target.createProcessor(target.getWidth(), target.getHeight());
      temp.snapshot();
      this.camera = camera;
      this.setName("MappingThread");
    }
  public ImageStack expandStack(ImageStack stackOld, int wNew, int hNew, int xOff, int yOff) {
    int nFrames = stackOld.getSize();
    ImageProcessor ipOld = stackOld.getProcessor(1);
    java.awt.Color colorBack = Toolbar.getBackgroundColor();

    ImageStack stackNew = new ImageStack(wNew, hNew, stackOld.getColorModel());
    ImageProcessor ipNew;

    for (int i = 1; i <= nFrames; i++) {
      IJ.showProgress((double) i / nFrames);
      ipNew = ipOld.createProcessor(wNew, hNew);
      if (zeroFill) ipNew.setValue(0.0);
      else ipNew.setColor(colorBack);
      ipNew.fill();
      ipNew.insert(stackOld.getProcessor(i), xOff, yOff);
      stackNew.addSlice(stackOld.getSliceLabel(i), ipNew);
    }
    return stackNew;
  }
  public void runLipschitz(ImageProcessor ip) {
    if (IJ.escapePressed()) return;
    breaked = false;
    Date d1, d2;
    d1 = new Date();

    IJ.showStatus("Initializing...");
    m_stack_out = m_imp.createEmptyStack();
    ImagePlus imp2 = null;

    for (int i = 0; ((i < m_scount) && (!breaked)); i++) {
      if (m_scount > 1) {
        ip = m_stack.getProcessor(i + 1);
      }
      iptmp = ip.createProcessor(ImageWidth, ImageHeight);
      iptmp.copyBits(ip, 0, 0, Blitter.COPY);

      IJ.showStatus("Filtering " + (i + 1) + "/" + m_scount + " slice.");

      Lipschitz2D(iptmp);

      m_stack_out.addSlice(m_imp.getShortTitle() + " " + (i + 1) + "/" + m_scount, iptmp);

      if (breaked = IJ.escapePressed()) IJ.beep();
    }

    imp2 =
        new ImagePlus(
            m_imp.getShortTitle()
                + " Filtered (Lipschitz) Slope:"
                + m_Slope
                + " "
                + ((m_Down) ? " -Down" : " ")
                + " "
                + ((m_TopHat) ? " -TopHat" : " ")
                + ((breaked) ? " -INTERUPTED" : ""),
            m_stack_out);
    imp2.show();
    imp2.updateAndDraw();
    IJ.showProgress(1.0);
  } // end of 'runLipschitz' method