javapythonimagejimagej-macro

How to output the intensity of every point using imageJ?


I want the intensity of every point of a picture, which function should I call? Let say the pixels of my picture is 125 x 125, I want the intensity of (0,0) to (125,125), is there a function so that I give a coordinate, it will return me an intensity like this

function(0,123) --> intensity?

Solution

  • In ImageJ macro language:

    result = getPixel(0,123);
    print(result);
    

    From other scripting languages, you can use the ImageJ Java API, e.g. the ImageProcessor#getPixel(int x, int y) method (ImageJ1) or the net.imglib2.Positionable#setPosition(int[] position) and net.imglib2.Sampler#get() methods (ImageJ2)

    For example, in Python:

    from ij import IJ
    
    imp = IJ.getImage()
    result = imp.getProcessor().getPixel(0, 123)
    print result
    
    # @Dataset img
    ra = img.randomAccess()
    ra.setPosition([0, 123])
    result = ra.get()
    print result