How can I use ImageJ as a library for a separate Java application?

后端 未结 3 1109
慢半拍i
慢半拍i 2021-02-07 12:11

In a regular Java application, I have a BufferedImage that I would like to manipulate with ImageJ. I have a macro that is exactly what I need to execute. I suspect that the firs

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 12:29

    Here is a sample code that opens an image, inverts it and saves it back:

    import ij.ImagePlus;
    import ij.io.FileSaver;
    import ij.process.ImageProcessor;
    
    ImagePlus imgPlus = new ImagePlus("path-to-sample.jpg");
    ImageProcessor imgProcessor = imgPlus.getProcessor();
    imgProcessor.invert();
    FileSaver fs = new FileSaver(imgPlus);
    fs.saveAsJpeg("path-to-inverted.jpg");
    

    And here's a sample code that shows how to manipulate an image to make it grayscale:

    BufferedImage bufferedImage = imgProcessor.getBufferedImage();
    for(int y=0;y

    I hope it helps you get started :)

提交回复
热议问题