Search code examples
javaimagej

imageJ how to get pixel rgb value?


i have a simple plugin which saves the polygon coordinates:

Roi roi = imp.getRoi();
Polygon p = roi.getPolygon();
for (int i = 1; i <= p.npoints; i++) {
// létrehozzuk az onvif féle vector-t
org.onvif.ver10.schema.Vector myVector = new Vector();
myVector.setX((float) p.xpoints[i - 1]);
myVector.setY((float) p.ypoints[i - 1]);
op.getPoint().add(myVector);
// IJ.log("Vector X Elements " + i + " :" + MyVector.getX());

        }

but i want to get the coordinates rgb values like this: enter image description here

can you help me with this? Thank you!


Solution

  • Supposing the image is 32-bit RGB:

    ImagePlus im = IJ.getImage();
    ImageProcessor imp = im.getProcessor();
    
    int[] rgb = new int[3];
    imp.getPixel(X,Y,rgb);
    
    IJ.log(Arrays.toString(rgb));