使用 ImageJ 调整和裁剪图像

Resize and crop an image using ImageJ

我正在尝试使用 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");

很遗憾,新创建的文件与原始文件相同。

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

圆形裁剪:https://youtu.be/OyiOFh1pD3k

调整大小:https://youtu.be/N_jddMMhzqc

合并两个代码。

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

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.


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