javax.media.jai.PlanarImage Java Examples

The following examples show how to use javax.media.jai.PlanarImage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageFileAssistantPage1.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Image doInBackground() throws Exception {
    RenderedImage sourceImage = FileLoadDescriptor.create(imageFilePath, null, true, null);
    int width = sourceImage.getWidth();
    int height = sourceImage.getHeight();

    float scale = (float) (targetDimension.getWidth() / width);
    scale = (float) Math.min(scale, targetDimension.getHeight() / height);
    if (scale > 1) {
        scale = 1.0f;
    }

    Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
    RenderedImage scaledImage = ScaleDescriptor.create(sourceImage,
                                                       scale, scale,
                                                       0.0f, 0.0f,
                                                       interpolation, null);
    PlanarImage planarImage = PlanarImage.wrapRenderedImage(scaledImage);
    BufferedImage bufferedImage = planarImage.getAsBufferedImage();
    planarImage.dispose();
    return bufferedImage;
}
 
Example #2
Source File: IJUtils.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creats a planar image based on an ImagePlus. The originalImage is just used for dimensions and tileSize (could be replaced by its int values).
 *
 * @param ip
 * @param originalImage
 * @param fg
 * @param bg
 * @return
 */
public static PlanarImage toPlanarImage(ImagePlus ip, PlanarImage originalImage, Color fg, Color bg) {
    TiledImageWriter imageWriter = new TiledImageWriter(originalImage.getWidth(), originalImage.getHeight(), originalImage.getTileWidth(), originalImage.getTileHeight());

    // resImg
    Point[] tileArr = imageWriter.getImage().getTileIndices(null);
    int[] p = new int[4];
    int[] bgArr = new int[]{bg.getRed(), bg.getGreen(), bg.getBlue(), 255};
    int[] fgArr = new int[]{fg.getRed(), fg.getGreen(), fg.getBlue(), 255};
    for (Point tileNum : tileArr) {
        WritableRaster writeRaster = imageWriter.getImage().getWritableTile(tileNum.x, tileNum.y);
        for (int x = imageWriter.getImage().tileXToX(tileNum.x); x < Math.min(imageWriter.getImage().tileXToX(tileNum.x) + imageWriter.getImage().getTileWidth(), imageWriter.getImage().getWidth()); x++)
            for (int y = imageWriter.getImage().tileYToY(tileNum.y); y < Math.min(imageWriter.getImage().tileYToY(tileNum.y) + imageWriter.getImage().getTileHeight(), imageWriter.getImage().getHeight()); y++) {
                p = ip.getPixel(x, y);
                if (p[0] != 0) p = fgArr;
                else p = bgArr;
                writeRaster.setPixel(x, y, p);  // since it is not a gray-scale image, we just use the red channel
            } // x,y
        imageWriter.getImage().releaseWritableTile(tileNum.x, tileNum.y);
    } // tileNum

    return imageWriter.getImage();
}
 
Example #3
Source File: IJUtils.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creats a binary ImagePlus based on a planar image. If a pixel is fg it is set to white, otherwise to black.
 *
 * @param image
 * @param fg
 * @return
 */
public static ImagePlus toBinaryImagePlus(PlanarImage image, Color fg) {
    if (image == null || (image.getWidth() * image.getHeight() > 6000 * 6000L))
        throw new IllegalArgumentException("this implementation can only handle images where width*height<=6000*6000. (And image cannot be null)");
    int width = image.getWidth();
    int height = image.getHeight();
    Raster raster = image.getData();
    int[] arr = new int[4];

    // set background to black and foreground to white for imageJ watershed
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int b = 0;
    for (int y = b; y < height - b; y++) {
        for (int x = b; x < width - b; x++) {
            arr = raster.getPixel(x, y, arr);
            if (arr[0] == fg.getRed() && arr[1] == fg.getGreen() && arr[2] == fg.getBlue()) {
                bi.setRGB(x, y, Color.WHITE.getRGB());
            } else {
                bi.setRGB(x, y, Color.BLACK.getRGB());
            }

        }
    }
    ImagePlus ip = new ImagePlus("watershed", bi);
    return ip;
}
 
Example #4
Source File: TestCellFeaturesBasic.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void cellFeaturesBasic() {
    BufferedImage bi = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
    Color c1 = new Color(1, 2, 3);
    Color c2 = new Color(4, 8, 16);
    bi.setRGB(10, 10, c2.getRGB());
    bi.setRGB(8, 8, c1.getRGB());
    bi.setRGB(12, 12, c1.getRGB());

    TiledImagePainter tip = new TiledImagePainter(PlanarImage.wrapRenderedImage(bi), "test");
    RecognitionFrame rf = new RecognitionFrame(tip);
    Shape shape = new RectangleExt(9, 9, 3, 3);

    ObjectFeatureBuilderTiled cellFeatureBuilder = new ObjectFeatureBuilderTiled(null);
    double[] feats = cellFeatureBuilder.buildFeatures(shape, 1, rf, null, 3, 0, 0);
    assertEquals(4d, feats[1], delta);
    assertEquals(8d, feats[5], delta);
    assertEquals(16d, feats[9], delta);
    assertEquals(1d, feats[23], delta); // class

    System.out.println(Arrays.toString(feats));


}
 
Example #5
Source File: OrbitImageTiff.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Analysis and analysisHueMap is ignored here - works only for 8bit BF images
 */
@Override
public Raster getTileData(int tileX, int tileY, boolean analysis) {
    try {
        byte[] buf = buffer.get();
        byte[] data = tp.get().getTile(ifd,buf,tileY,tileX);
        BufferedImage image =getBufferedImage(data,tileWidth,tileHeight);

        // ensure tiles have always full tileWifth and tileHeight (even at borders)
        if (image.getWidth()!=getTileWidth() || image.getHeight()!=getTileHeight())
        {
            BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_INT_RGB);   // must be RGB
            bi.getGraphics().drawImage(image, 0, 0, null);
            image = bi;
        }

        Raster r = image.getData().createTranslatedChild(PlanarImage.tileXToX(tileX, image.getTileGridXOffset(), tileWidth), PlanarImage.tileYToY(tileY, image.getTileGridYOffset(), tileHeight));
        return r;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #6
Source File: TMAPoints.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * returns all UEP with a threshold > min in a pointlist.
 * The UEP process has to be applied before!
 *
 * @param img
 * @param min
 * @return
 */
private List<Point> reportPoints(PlanarImage img, int min) {
    Raster r = img.getData();
    int[] rgb = new int[3];
    double d;
    List<Point> pList = new ArrayList<Point>();
    for (int x = 0; x < img.getWidth(); x++)
        for (int y = 0; y < img.getHeight(); y++) {
            rgb = r.getPixel(x, y, rgb);
            d = (rgb[0]);
            if (d > min) {
                Point p = new Point(x, y);
                pList.add(p);
                if (logger.isTraceEnabled()) {
                    logger.trace(x + "," + y + ": " + d);
                }
            }
        }
    return pList;
}
 
Example #7
Source File: OrbitUtils.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public static Raster getRasterForClassification(final TiledImagePainter bimg, final FeatureDescription featureDescription, final int windowSize, final int tileX, final int tileY) throws OrbitImageServletException {
    PlanarImage image = bimg.getImage();
    Raster readRaster;
    if (OrbitUtils.TILEMODE) {
        readRaster = bimg.getModifiedImage(featureDescription).getTile(tileX, tileY);
    } else
        readRaster = bimg.getData(new Rectangle(image.tileXToX(tileX) - windowSize, image.tileYToY(tileY) - windowSize, image.getTileWidth() + (windowSize * 2 + 1), image.getTileHeight() + (windowSize * 2 + 1)), featureDescription);

    if (readRaster == null) {
        throw new OrbitImageServletException("error getting image raster");
    }

    // apply raster modifications like color deconvolution
    readRaster = OrbitUtils.getModifiedRaster(readRaster, featureDescription, bimg.getImage().getColorModel(), true, tileX, tileY, "modifiedRaster", bimg.getImage().getLevel());
    return readRaster;
}
 
Example #8
Source File: TMAPoints.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public PlanarImage process(final PlanarImage image) {
    if (image == null || (image.getWidth() * image.getHeight() > 6000 * 6000L))
        throw new IllegalArgumentException("this implementation can only handle images where width*height<=6000*6000. (And image cannot be null)");

    TMAPointsResult res = findCircles(image);
    this.radius = res.getRadius();
    List<Point> pList = res.getSpotList();

    HashMap<Point, Point> pMap = clusterLines(pList);
    pMap = discardDuplicatePoints(pMap);

    BufferedImage buffImg = res.getSpotImage();
    Graphics g = buffImg.createGraphics();
    g.setColor(Color.blue);
    g.setFont(new Font("System", Font.PLAIN, 9));
    for (Point p : pMap.keySet()) {
        Point pos = pMap.get(p);
        g.drawString(pos.x + "/" + pos.y, p.x, p.y);
    }

    spotMap = pMap;

    return PlanarImage.wrapRenderedImage(buffImg);
}
 
Example #9
Source File: OrbitImageBioformats.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Raster getTileData(int tileX, int tileY, float[] channelContributions, boolean analysis, float[] analysisHues) {
    try {
        
       BufferedImage img = getPlane(tileX, tileY,(analysis||channelContributions!=null)?channelContributions:this.channelContributions, analysis, analysisHues);
       // ensure tiles have always full tileWidth and tileHeight (even at borders)
       if (img.getWidth()!=getTileWidth() || img.getHeight()!=getTileHeight())
       {
           BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), img.getType());
           bi.getGraphics().drawImage(img, 0, 0, null);
           img = bi;
       }

      // set correct bounds
      Raster r = img.getData().createTranslatedChild(PlanarImage.tileXToX(tileX, img.getTileGridXOffset(), getTileWidth()), PlanarImage.tileYToY(tileY, img.getTileGridYOffset(), getTileHeight()));
      return r;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #10
Source File: WarpOpImage.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * This method provides a lazy initialization of the image associated to the ROI. The method uses
 * the Double-checked locking in order to maintain thread-safety
 *
 * @return
 */
private PlanarImage getImage() {
  PlanarImage img = roiImage;
  // HP Fortify "Double-Checked Locking" false positive
  // This is not a security issue. We are aware of the extremely small
  // potential for this to be called twice, but that is not an
  // inconsistency and is more than worth the performance gains
  if (img == null) {
    synchronized (this) {
      img = roiImage;
      if (img == null) {
        roiImage = img = roi.getAsImage();
      }
    }
  }
  return img;
}
 
Example #11
Source File: TiledImageWriter.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public TiledImageWriter(PlanarImage inputImage, int xOffs, int yOffs) {
    this.width = inputImage.getWidth();
    this.height = inputImage.getHeight();
    this.tileWidth = inputImage.getTileWidth();
    this.tileHeight = inputImage.getTileHeight();
    colorModel = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB),
            new int[]{8, 8, 8, 8}, true, false,
            Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);
    sampleModel = colorModel.createCompatibleSampleModel(tileWidth, tileHeight);
    image = new DiskMemImageOrbit(xOffs, yOffs, width, height, 0, 0, sampleModel, colorModel);
    ((DiskMemImageOrbit) image).setUseCommonCache(true);

    TiledImagePainter painter = new TiledImagePainter(inputImage, "");
    Graphics2D g2d = image.createGraphics();
    try { // 03.05.2010 Manuel (exception with JRE 1.5, with JRE 1.6 fine)
        painter.drawImage(g2d, xOffs, yOffs, width, height, 100d, -1);
    } catch (Throwable e) {
        //System.out.println("TiledImageWriter Error",e);
        //e.printStackTrace();
    }
}
 
Example #12
Source File: DiskMemImageGraphicsOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Attempts to retrieve or create a <code>ColorModel</code> for the target
 * image.
 *
 * @throws UnsupportedOperationException if a compatible
 *                                       <code>ColorModel</code> is not found
 */
private void setColorModel() {
    assert (targetImage != null);

    colorModel = targetImage.getColorModel();

    if (colorModel == null) {
        SampleModel sm = targetImage.getSampleModel();
        colorModel = PlanarImage.createColorModel(sm);

        if (colorModel == null) {
            // try simple default
            if (ColorModel.getRGBdefault().isCompatibleSampleModel(sm)) {
                colorModel = ColorModel.getRGBdefault();

            } else {
                // admit defeat
                throw new UnsupportedOperationException(
                        "Failed to get or construct a ColorModel for the image");
            }
        }
    }
}
 
Example #13
Source File: ObjectSegmentationWorker.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
private RecognitionFrame makeROIImage(RecognitionFrame rf, Shape roi) {
        TiledImagePainter ci = rf.bimg;
        if (roi != null) {
            Rectangle roiBounds = roi.getBounds();
            if (logger.isTraceEnabled() && (roiBounds.getWidth() == 0 || roiBounds.getHeight() == 0)) {
                logger.trace("Warning: ROI bounds with width=0 or height=0. Skipping tile.");
                //return null; // instead an error message will be thrown in getAsBufferedImage
            }
            BufferedImage bi = rf.bimg.getModifiedImage(this.segmentationModel.getFeatureDescription()).getAsBufferedImage(roiBounds, rf.bimg.getImage().getColorModel());    // here it is a 'rendered' image, e.g. only with active fluo channels
//            BufferedImage bi = rf.bimg.getImage().getAsBufferedImage(roiBounds, rf.bimg.getImage().getColorModel());    // here it is a 'rendered' image, e.g. only with active fluo channels

            ci = new TiledImagePainter(PlanarImage.wrapRenderedImage(bi), "roi");
            ci.getImage().setUseCache(false);
        }
        RecognitionFrame rf2 = new RecognitionFrame(ci);
        rf2.setClassShapes(rf.getClassShapes());
        rf2.initializeClassColors();
        ci.getImage().setUseCache(false);
        return rf2;
    }
 
Example #14
Source File: HilightImagePanel.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/** Test program */

  public static void main(String[] arg) {
    PlanarImage image = JAI.create("fileload", arg[0]);
    PlanarImage mask  = JAI.create("fileload", arg[1]);

    JFrame window = new JFrame();

    window.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
	  System.exit(0);
	}
      });
    window.getContentPane().add(new HilightImagePanel(image, mask, Color.blue),
				BorderLayout.CENTER);
    window.pack();
    window.setSize(300, 300);
    window.setLocation(40, 40); 
    window.show();
  }
 
Example #15
Source File: TileCacheMonitor.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void updateTableModel(Collection<CachedTile> tiles) {
    tableModel.reset();
    for (CachedTile sct : tiles) {
        RenderedImage owner = sct.getOwner();
        if (owner == null || !(owner instanceof PlanarImage)) {
            continue;
        }
        PlanarImage image = (PlanarImage) owner;
        Object imageID = image.getImageID();
        CachedTileInfo cachedTileInfo = null;
        for (CachedTileInfo info : tableModel.data) {
            if (info.uid.equals(imageID)) {
                cachedTileInfo = info;
                break;
            }
        }
        if (cachedTileInfo == null) {
            cachedTileInfo = new CachedTileInfo();
            cachedTileInfo.uid = imageID;
            cachedTileInfo.imageName = getImageName(image);
            cachedTileInfo.level = getImageLevel(image);
            cachedTileInfo.comment = getImageComment(image);
            tableModel.data.add(cachedTileInfo);
        }
        cachedTileInfo.numTiles++;
        cachedTileInfo.size += sct.getTileSize();
    }
    tableModel.cleanUp();
    tableModel.fireTableDataChanged();

}
 
Example #16
Source File: Picture.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setImage (RenderedImage renderedImage)
        throws ImageFormatException
{
    image = PlanarImage.wrapRenderedImage(renderedImage);

    checkImage();
}
 
Example #17
Source File: PixelInfoViewModelUpdater.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private boolean isPixelValid(RasterDataNode raster, int pixelX, int pixelY, int level) {
    if (raster.isValidMaskUsed()) {
        PlanarImage image = ImageManager.getInstance().getValidMaskImage(raster, level);
        Raster data = getRasterTile(image, pixelX, pixelY);
        return data.getSample(pixelX, pixelY, 0) != 0;
    } else {
        return true;
    }
}
 
Example #18
Source File: WarpRIF.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of warp operator according to the warp object and interpolation method.
 *
 * @param paramBlock The warp and interpolation objects.
 */
@Override
public RenderedImage create(final ParameterBlock paramBlock, final RenderingHints renderHints) {
  final Interpolation interp = (Interpolation) paramBlock.getObjectParameter(1);
  if ((interp instanceof InterpolationNearest)
      || (interp instanceof javax.media.jai.InterpolationNearest)) {
    // Get ImageLayout from renderHints if any.
    final ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

    RenderedImage source = paramBlock.getRenderedSource(0);
    final Warp warp = (Warp) paramBlock.getObjectParameter(0);
    final double[] backgroundValues = (double[]) paramBlock.getObjectParameter(2);

    ROI roi = null;
    final Object roi_ = paramBlock.getObjectParameter(3);
    if (roi_ instanceof ROI) {
      roi = (ROI) roi_;
      final PlanarImage temp = PlanarImage.wrapRenderedImage(source);
      temp.setProperty("ROI", roi);
      source = temp;
    }
    Range noData = (Range) paramBlock.getObjectParameter(4);
    noData = RangeFactory.convert(noData, source.getSampleModel().getDataType());
    return new WarpNearestOpImage(
        source,
        renderHints,
        layout,
        warp,
        interp,
        roi,
        noData,
        backgroundValues);
  }
  return super.create(paramBlock, renderHints);
}
 
Example #19
Source File: ImageWorkerPredefineStats.java    From geowave with Apache License 2.0 5 votes vote down vote up
public ImageWorkerPredefineStats setStats(final Pair<String, Object>[] nameValuePairs) {
  image = new RenderedImageAdapter(image);
  for (final Pair<String, Object> pair : nameValuePairs) {
    ((PlanarImage) (image)).setProperty(pair.getLeft(), pair.getRight());
  }
  return this;
}
 
Example #20
Source File: RasterLayerComponentImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Converts an image to a RGBA direct color model using a workaround via buffered image directly calling the
 * ColorConvert operation fails for unknown reasons ?!
 *
 * @param img
 *            image to convert
 * @return converted image
 */
public PlanarImage toDirectColorModel(RenderedImage img) {
	BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
	BufferedImage source = new BufferedImage(img.getColorModel(), (WritableRaster) img.getData(), img
			.getColorModel().isAlphaPremultiplied(), null);
	ColorConvertOp op = new ColorConvertOp(null);
	op.filter(source, dest);
	return PlanarImage.wrapRenderedImage(dest);
}
 
Example #21
Source File: RasterDirectLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Converts an image to a RGBA direct color model using a workaround via buffered image directly calling the
 * ColorConvert operation fails for unknown reasons ?!
 *
 * @param img image to convert
 * @return converted image
 */
public PlanarImage toDirectColorModel(RenderedImage img) {
	BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
	BufferedImage source = new BufferedImage(img.getColorModel(), (WritableRaster) img.getData(), img
			.getColorModel().isAlphaPremultiplied(), null);
	ColorConvertOp op = new ColorConvertOp(null);
	op.filter(source, dest);
	return PlanarImage.wrapRenderedImage(dest);
}
 
Example #22
Source File: ImageTiler.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private PlanarImage makeTiledImage(PlanarImage img, int tileWidth, int tileHeight) {
    ImageLayout tileLayout = new ImageLayout(img);
    tileLayout.setTileWidth(tileWidth);
    tileLayout.setTileHeight(tileHeight);
    tileLayout.setSampleModel(img.getColorModel().createCompatibleSampleModel(tileWidth,tileHeight));
    tileLayout.setColorModel(img.getColorModel());
    RenderingHints tileHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tileLayout);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(img);
    PlanarImage pi = JAI.create("format", pb, tileHints);
    pi.getWidth();
    return pi;
}
 
Example #23
Source File: TestImage3.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static PlanarImage grayToGray256 (PlanarImage image)
    {
        System.out.println("Converting gray image to gray-256 ...");

        ColorSpace colorSpace = ColorSpace.getInstance
            (java.awt.color.ColorSpace.CS_GRAY);

//        int[] bits = new int[]{8};
//        int opaque = Transparency.OPAQUE;
//        int dataType = DataBuffer.TYPE_BYTE;
//        ColorModel colorModel = new ComponentColorModel
//            (colorSpace, bits, false, false, opaque, dataType);

        return JAI.create("colorConvert", image, colorSpace, null);
    }
 
Example #24
Source File: AnnotationPanel.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public void run() {
    try {
        ClassShape classShape = annotation.getShape();
        if (classShape != null && classShape.getShapeList() != null) {
            if (classShape.getShapeList() != null && classShape.getShapeList().size() > 0) {
                IScaleableShape p = (IScaleableShape) classShape.getShapeList().get(0); // only the first shape

                ImageFrame iFrame = OrbitImageAnalysis.getInstance().getIFrame();
                if (iFrame != null) {
                    final long maxW = 2000;
                    Rectangle rect = p.getScaledInstance(100d, new Point(0, 0)).getBounds();
                    PlanarImage img = iFrame.recognitionFrame.bimg.getImage();
                    if ((long) rect.getWidth() * rect.getHeight() > (maxW * maxW)) {
                        if (iFrame.recognitionFrame.bimg.getMipMaps() != null && iFrame.recognitionFrame.bimg.getMipMaps().length > 0) {
                            img = iFrame.recognitionFrame.bimg.getMipMaps()[iFrame.recognitionFrame.bimg.getMipMaps().length - 1].getImage();
                            double scale = (double) img.getWidth() / (double) iFrame.recognitionFrame.bimg.getImage().getWidth();
                            rect = p.getScaledInstance(scale * 100d, new Point(0, 0)).getBounds();
                        }
                    }
                    BufferedImage bi = img.getAsBufferedImage(rect, iFrame.recognitionFrame.bimg.getImage().getColorModel());
                    bi = TiffConverter.makeScaledImage(bi, thumbnailWidth, thumbnailHeight);
                    ImageIcon icon = new ImageIcon(bi);
                    if ((cellCache != null) && (icon != null)) {
                        cellCache.put(hash, icon);
                        list.revalidate();
                        list.repaint();
                    }
                }
            }
        }

    } catch (Throwable t) {
        // can happen (e.g, outofmemory), but no problem
    }

}
 
Example #25
Source File: TMASpotEditor.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    BufferedImage img = new BufferedImage(300, 500, BufferedImage.TYPE_INT_RGB);
    img.getGraphics().setColor(Color.white);
    img.getGraphics().fillRect(0, 0, img.getWidth(), img.getHeight());

    TiledImagePainter dummy = new TiledImagePainter(PlanarImage.wrapRenderedImage(img), "Dummy");
    Map<Point, Point> spotMap = new HashMap<Point, Point>();
    spotMap.put(new Point(20, 20), new Point(0, 0));
    spotMap.put(new Point(20, 100), new Point(0, 1));
    spotMap.put(new Point(20, 180), new Point(0, 2));
    spotMap.put(new Point(20, 260), new Point(0, 3));
    spotMap.put(new Point(20, 340), new Point(0, 4));

    spotMap.put(new Point(80, 20), new Point(1, 0));
    spotMap.put(new Point(80, 100), new Point(1, 1));
    spotMap.put(new Point(80, 180), new Point(1, 2));
    spotMap.put(new Point(80, 260), new Point(1, 3));
    spotMap.put(new Point(80, 340), new Point(1, 4));

    spotMap.put(new Point(140, 20), new Point(2, 0));
    spotMap.put(new Point(140, 100), new Point(2, 1));
    spotMap.put(new Point(140, 180), new Point(2, 2));
    spotMap.put(new Point(140, 260), new Point(2, 3));
    spotMap.put(new Point(140, 340), new Point(2, 4));


    TMASpotEditor editor = new TMASpotEditor(spotMap, 18, dummy, true);
    editor.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    RawUtilsCommon.centerComponent(editor);
    editor.setVisible(true);
}
 
Example #26
Source File: DLSegment.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static SegmentationResult getSegmentationResult(OrbitModel segModel, BufferedImage segmented) throws Exception {
    IOrbitImage segimg = new OrbitImagePlanar(PlanarImage.wrapRenderedImage(segmented), "segmented");
    RecognitionFrame rfSeg = new RecognitionFrame(segimg, "segmented");
    List<Point> tl = new ArrayList<>();
    tl.add(new Point(-1, -1));
    SegmentationResult segRes = OrbitHelper.Segmentation(rfSeg, 0, segModel, tl, 1, false);
    return segRes;
}
 
Example #27
Source File: NDPIImageNative.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public NDPIImageNative(String filename, int level) throws Exception {
    super(filename, level, false);
    logger.info("loading NDPI image using native ndpi library: "+filename+" ["+level+"]");
    BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_3BYTE_BGR);
    PlanarImage image = PlanarImage.wrapRenderedImage(bi);
    if (image.getSampleModel() != null && (!image.getSampleModel().equals(sampleModel))) {
        this.sampleModel = image.getSampleModel();
    }
    if (level >= getNumLevels())
        throw new OrbitImageServletException("level " + level + " >= numLevels (" + getNumLevels() + ")");

    logger.info(filename+" loaded ["+width+" x "+height+"]");
}
 
Example #28
Source File: AbstractChannelRendererOrbitImage.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private WritableRaster getWritableRaster(final int tileX, final int tileY, final WritableRaster wr, final ColorModel colorModelIn) {
    WritableRaster wr2 = (WritableRaster) wr.createTranslatedChild(0,0);
    BufferedImage bi1 = new BufferedImage(colorModelIn,wr2,false,null);
    BufferedImage bi = new BufferedImage(wr2.getWidth(),wr2.getHeight(),BufferedImage.TYPE_INT_RGB);
    bi.getGraphics().drawImage(bi1,0,0,null);
    bi.getGraphics().dispose();
    // ensure tiles have always full tileWifth and tileHeight (even at borders)
    if (bi.getWidth()!=getTileWidth() || bi.getHeight()!=getTileHeight())
    {
        BufferedImage bi2 = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_INT_RGB);   // must be RGB
        bi2.getGraphics().drawImage(bi, 0, 0, null);
        bi = bi2;
    }
    return (WritableRaster) bi.getRaster().createTranslatedChild(PlanarImage.tileXToX(tileX, 0, tileWidth), PlanarImage.tileYToY(tileY, 0, tileHeight));
}
 
Example #29
Source File: OrbitHelper.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
private static PlanarImage scalePlanarImage(PlanarImage sourceImage, double factor) {
    ParameterBlockJAI pb = new ParameterBlockJAI("scale", RenderedRegistryMode.MODE_NAME);
    pb.setSource("source0", sourceImage);
    pb.setParameter("xScale", new Float(factor));
    pb.setParameter("yScale", new Float(factor));
    PlanarImage pi = JAI.create("scale", pb);
    return pi;
}
 
Example #30
Source File: ImageTiler.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    BufferedImage img = new BufferedImage(4000,4000,BufferedImage.TYPE_INT_RGB);
    PlanarImage pi = PlanarImage.wrapRenderedImage(img);
    for (BufferedImage tileImg: new ImageTiler(pi,512,512)) {
        System.out.println(tileImg);
    }

}