Cropped and resized images are not saved

I’m trying to resize and crop an image using ImageJ. Here’s the code:

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

/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);

Unfortunately, the newly created files are identical as the original one.

So far I’ve found out how to blur, smooth, invert, translate, rotate… but these two are giving me hard time. Anybody has an idea?


Hi @vtomic85,

welcome to the forum! :slight_smile:

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.



Thanks a lot, @stelfrich, this helped :slight_smile:

@vtomic85 when cross-posting here and on, please include links so that others will be able to find the answers :slight_smile:

1 Like

I’m need to resize images, but I don’t quite understand how ImagePlus and ImageProcessor gets used. Can you please post a code example for your answer?