3

Can I use BufferedImage objects from java.awt.image.BufferedImage with ImageJ class instances? For example can I use BufferedImage object instead of an ImagePlus object?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
buwaneka
  • 191
  • 1
  • 4
  • 11

2 Answers2

4

From the docs for ImagePlus(String,java.awt.Image).

Constructs an ImagePlus from an Image or BufferedImage. ..

Result: Create an ImagePlus using that constructor whenever needed.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • didn't notice that..thanks... i can do it the other way round (Image plus obj -> java.awt.Image)using this right? http://rsb.info.nih.gov/ij/developer/api/ij/ImagePlus.html#getImage() – buwaneka Oct 23 '12 at 04:11
  • ..you might do that or call [`getBufferedImage()`](http://rsb.info.nih.gov/ij/developer/api/ij/ImagePlus.html#getBufferedImage%28%29) apparently (which I generally prefer). Glad you got it sorted. :) – Andrew Thompson Oct 23 '12 at 04:15
  • So my question is how to get 16 bit bufferedImage from ij.ImagePlus...? If am trying to get using ShortProcessor it change my signed image to unsigned so i am not getting original image...Thanks in advance can any one provide solution. – Jay Thakkar Apr 24 '14 at 10:43
  • @JayThakkar You should *ask a question* about that question. – Andrew Thompson Apr 24 '14 at 11:39
  • @JayThakkar Your problem is not my problem. If your question asking ability has been curtailed, get that sorted first. – Andrew Thompson Apr 25 '14 at 05:50
  • @Andrew ok my problem is my problem – Jay Thakkar Apr 25 '14 at 08:53
0
public static void processImage(InputStream inputFile, String outputFilePath, double scaleFactor, int interpolationMethod, double sigmaFactor) {
    try {
        BufferedImage bi = ImageIO.read(inputFile);
        ImageProcessor ip = new ColorProcessor(bi);
        ip.blurGaussian(sigmaFactor / scaleFactor);
        ip.setInterpolationMethod(interpolationMethod);
        ImageProcessor outputProcessor = ip.resize((int) (ip.getWidth() * scaleFactor), (int) (ip.getHeight() * scaleFactor));
        IJ.saveAs(new ImagePlus("", outputProcessor), outputFilePath.substring(outputFilePath.lastIndexOf('.') + 1), outputFilePath);
    } catch (Exception e) {
         System.out.println("Error al comrpimir la imagen: "+e);
    }
}
Iván AG
  • 1
  • 1