Search code examples
scalaimagej

how to get a matrix of pixel values in ImageJ?


I am sorry if I have overlooked the answer to my question in the Fiji tutorials. I guess I am wondering; is there any way of getting information about all the image pixel values (for instance in a matrix? or a list of matrices) from either the imagePlus, ImageStack or process.ImageProcessor?

I have so far tried to get pixel values (my image has 262144 pixels) as seen in the two lowest lines. Pixels should now be an array of pixel values, but its an object that I can't access as an array. I get that the pixel is 0 (which seems to be an out of bounds return value), and that the pixelValue is -1024.

Any help would be very appreciated..

import ij._
import java.nio.file.{Paths,Files}

object Main{
    def main(args: Array[String]){ 
        println(ImagesProcessing.read())
    }
}

object ImagesProcessing { 

    def read():Unit = {
        val image: ImagePlus = IJ.openImage("./image.dcm")
        val stack:ImageStack = image.getImageStack()
        val processor: process.ImageProcessor = image.getProcessor().convertToRGB()
        val pixels = processor.getPixels()
        println(pixels)
   }

}

I have looked into the tutorial suggested, and it seems that I am using the correct functions. I have decided to convert to RGB as that is mentioned in the first suggested tutorial. The only thing I see that I am not doing is a type casting. I believe I am getting a Java object which I do not know how to iterate over (I wrote a separate question about that).


Solution

  • Maybe one of these options will be helpful:

    In the plugin tutorial by Werner Bailer, see pages 16-18 for examples of accessing individual pixel values in a Java plugin.

    Albert Cardona's tutorial shows how to do it in Jython.