How can you convert an image's pixel array to a new image file?

In Javascript, is there a way to convert an array of pixels to an ImagePlus object that I can save as an image file?

The reason I’d like to do this is because I have 8-bit images that contain a color LUT. I’d like to convert them to images without this LUT. Using the getPixels() routine produces the array of pixel values, without the LUT, but I have no idea how to convert this pixel array back to an ImagePlus object. I assume it’s dead easy since I can’t find any examples about how to do this online.


Here is some Javascript code that creates an image from an array of pixel values.

  pixels = [1,2,3,4,5,6,7,8,9,10,11,12];
  ip = new ByteProcessor(4,3,pixels);
  img = new ImagePlus("Test",ip);;, "Set... ", "zoom=3200 x=2 y=1");, "Enhance Contrast", "saturated=0.35");


While I greatly appreciate your solution, I’m super annoyed because I was SO close to figuring it out myself before giving up. Many thanks! :grinning:

1 Like