Array ( int [] ) to ImageProcessor

Hello,

How can I simply put a Array (Integer Values of a Picture) to an imageprocessor? And after that I want to show this ImageProcessor as a Picture.

I hope somebody can quickly help me? :slight_smile:

Hi Stefan,

In which langage do you want to do it? In Jython it could look like this, you can run it from the script editor.

from ij.process import FloatProcessor
from ij import ImagePlus

w=3
h=2
myArray = [0, 1, 0, 0, 0, 1]
ipFloat = FloatProcessor( w, h, myArray )

imp = ImagePlus( "image of my array" , ipFloat )

imp.show()

In Java, you might need to convert first your array to an appropriate type if it is not Byte, Short or Float as ByteProcessor, FloatProcessor, ShortProcessor are the available type of image processor.

I hope that helps, good luck!

Edit: FloatProcessor has a constructor with int so no conversion might be needed

1 Like

Hi Benoit,

I want to do it in Java and I have to (for school) code it. And I should not use other plugins or a macro, …just java code

Try this

/**
     *
     * @param array the intarray
     * @return a double array
     */
    public static double[] todouble(int[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

Then just call

  ImageProcessor ip = new FloatProcessor(todouble(intarray));
1 Like

Thank you for your help, I solved in a other way but I will use your method to solve the problem next time I need it :slight_smile: