gpt4 book ai didi

java - 使用 ImageJ 调整和裁剪图像

转载 作者:行者123 更新时间:2023-11-30 06:06:44 27 4
gpt4 key购买 nike

我正在尝试使用 ImageJ 调整图像大小和裁剪图像。这是代码:

ImagePlus ip1 = IJ.openImage("_Pic.jpg");
ImagePlus ip2 = IJ.openImage("_Pic.jpg");

ImageProcessor imgP1 = ip1.getProcessor();
ImageProcessor imgP2 = ip2.getProcessor();

FileSaver fs1 = new FileSaver(ip1);
FileSaver fs2 = new FileSaver(ip2);

/* Trying to resize */
imgP1.resize(100); // also tried with width and height
fs1.saveAsJpeg("Resized.jpg");

/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);
imgP2.crop();
fs2.saveAsJpeg("Cropped.jpg");

不幸的是,新创建的文件与原始文件相同。

到目前为止,我已经找到了如何模糊、平滑、反转、平移、旋转……,但这两个让我很难过。有人有想法吗?

最佳答案

你的 cross-posted question to the ImageJ forum Stefan Helfrich 在那里回答:

If you take a look at the Javadocs for ImageProcessor you'll see that resize() as well as crop() return new ImageProcessor instances and do not operate on this. That's why you'll have to use the ImagePlus.setProcessor(ImageProcessor) method to add the returned ImageProcessors to ip1 and ip2.


当像这样交叉发帖时,请始终包含指向其他帖子的链接,这样以后发现此问题的人将有机会关注讨论。

关于java - 使用 ImageJ 调整和裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43499204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com