Reputation: 611
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
fs1.saveAsJpeg("Resized.jpg");
/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);
imgP2.crop();
fs2.saveAsJpeg("Cropped.jpg");
Unfortunately, the newly created files are identical to 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?
Upvotes: 2
Views: 8040
Reputation: 4090
Your cross-posted question to the ImageJ forum was answered there by Stefan Helfrich:
If you take a look at the Javadocs for ImageProcessor you'll see that
resize()
as well ascrop()
return newImageProcessor
instances and do not operate onthis
. That's why you'll have to use theImagePlus.setProcessor(ImageProcessor)
method to add the returned ImageProcessors toip1
andip2
.
When cross-posting like this, please always include links to the other posts, so people finding this question later will have a chance to follow the discussion.
Upvotes: 8
Reputation: 75
circle crop: https://youtu.be/OyiOFh1pD3k
resize: https://youtu.be/N_jddMMhzqc
combine both code.
Upvotes: -1