1
votes

I'm writing a scala program that needs to be able to read a 16 bit grayscale tiff image and do some complicated calculations on the individual pixels.

Specfically, I want a library to be able to get me an Array[Int] of all the pixel intensity values from the tiff file, and to be able to write an image from such a data structure.

The question that I have is what libraries are capable of doing this?

Thanks for any help you can provide.

1
hi, i'd take a look at the Java standard imageio library. docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html you'll have to do a bit of work to get from ImageIO to BufferedImage to Array[Int], but i don't think it will be very hard. - Steve Waldman
javax.imageio is an excellent package, but it doesn't support TIFFs. For that you'll need Sanselan or Scrimage. - sksamuel

1 Answers

0
votes

I ended up using the imageJ API to solve this problem. There is an excellent article here on the API: http://albert.rierol.net/imagej_programming_tutorials.html#ImageJ programming basics

This chunk gets you a ShortProcessor (http://rsb.info.nih.gov/ij/developer/api/ij/process/ShortProcessor.html) which you can use to query individual pixels or get an Array[Short] dump of all pixels.

val opener = new Opener()
val imp = opener openImage path
val sp = (imp.getProcessor()).convertToShort(false)

Also, here's the sbt line you want

libraryDependencies += "gov.nih.imagej" % "imagej" % "1.46"