Elewis787
Elewis787

Reputation: 27

ImageJ Overlay ROI zoom

Using ImageJ I would like to create a Zoom function for a ROI at a given location. so far I have something like this:

imp = IJ.getImage();
ip = imp.getProcessor();
//fill pixel array with ROI pixels
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
pixels[i][j] = (float)ip.getPixel(xPos + i, yPos + j);
}
}

I have a array of pixels, now I want to create a ROI containing these pixels enlarged in the corner of my image. I have been looking into the ROI api of ImageJ but cannot seem to get in the right direction. Any guidance would be great. I am looking to a function that would Fill a ROI with the pixels values I have. Thanks in advance.

Upvotes: 0

Views: 1262

Answers (1)

Josef Borkovec
Josef Borkovec

Reputation: 1079

You are probably looking for the class ImageRoi. This code will show the selected roi in the overlay in upper left corner (2x bigger).

ImageProcessor cropped = IJ.getImage().getProcessor().crop(); //image from currently selected roi
ImageProcessor scaled = cropped.resize(cropped.getWidth()*2,cropped.getHeight()*2);  //magnified image
Overlay overlay = new Overlay(new ImageRoi(0,0, scaled));    
IJ.getImage().setOverlay(overlay);

Upvotes: 1

Related Questions