Search code examples
imagej

Extract pixel values within a selection or region of interest


I am struggling to extract individual pixel values from a selection or area of interest using imageJ. I have tried to save the image as a text file, but it is very hard working to find and collect the pixels I am interested in. I have also tried to extract the histogram values from the option "list" however, it put several pixels with in a bin range and I want to extract every single individual value.

Do you know any way to do this? Any other software suggestions are also welcome.

Many thanks in advance :)


Solution

  • I got the solution form an imageJ mailing list form Nabble. This is a macro that do the trick:

    //------------------------------------------------ 
    Roi.getBounds(rx, ry, width, height); 
    row = 0; 
    
    for(y=ry; y<ry+height; y++) { 
        for(x=rx; x<rx+width; x++) { 
            if(Roi.contains(x, y)==1) { 
                setResult("X", row, x); 
                setResult("Y", row, y); 
                setResult("Value", row, getPixel(x, y)); 
                row++; 
            } 
        } 
    } 
    //------------------------------------------------ 
    

    Credits CEO: Dr. Jan Brocher

    Here the link to the thread

    http://imagej.1557.x6.nabble.com/Extracts-individual-pixel-values-from-a-selection-or-RIO-td5020121.html