Get ImageRoi's pixel value

imagej
plugin
roi

#1

Hi, ImageJ Developper’s,

How can I get an imageRoi’s pixel value located at base image (x,y)??
This imageRoi is rotated and panning.

Tatsuaki


#2

Dear @11110,

you can use ImageRoi.getProcessor() to get an object that extends ImageProcessor. Since ImageProcessor defines get(int x, int y) you can use that to get intensities.

How exactly did you create a rotated ImageRoi? Assuming that you have created the overlay programmatically, you can always use the x- and y-shifts and your rotation angle to compute the coordinate you have to access in the underlying ImageProcessor. I am not aware of any built-in functionality to handle that situation in ImageJ1.

Best,
Stefan


#3

Dear, Stefan,

Thank you for your reply,

How exactly did you create a rotated ImageRoi? Assuming that you have created the overlay programmatically,

This is yes,
In my code, for example,

//rotate
ImageRoi roi = new ImageRoi(ip);
roi.rotate(angle);
//pan
roi.setLocation(x,y);

you can always use the x- and y-shifts and your rotation angle to compute the coordinate you have to access in the underlying ImageProcessor.

I think so too.
But, for example,

ImagePlus imp = new ImagePlus(ToMyImagePath);
ImageProcessor ip = imp.getProcessor();//yet rotated and panning
ImageRoi roi = new ImageRoi(ip);
roi.rotate(25.0);
roi.setLocation(100,100);
ImageProcessor ip2 = roi.getProcessor();//rotated and panning

System.out.println(ip.get(100, 100));
System.out.println(ip.get(200, 100));
System.out.println(ip.get(300, 100));
System.out.println(ip2.get(100, 100));
System.out.println(ip2.get(200, 100));
System.out.println(ip2.get(300, 100));

These value are same.
So, my idea is…

  • get X and Y shift on ImageCanvas,
  • get Rotated angle,
  • get Roi’ ImageProcessor,
  • calculate shift and rotate to this ImageProcessor?

Do you have any another suggestions?

Best regards,
Tatsuaki


#4

For now, I can do it using above method, thanks a lot.

Best regards,
Tatsuaki


#5

That’s exactly how I would approach this issue and I don’t know of a better way.

Best,
Stefan