Note:The code will be seen as a mess. You can find it @

I need to find NDVI and other vegetation indices and then find changes in time with tif images.

I've been using Geotools for this. Took 2 tiff images, then using QGis I changed them to PNG because original ones are huge. Then taking those 2 PNG I created NDVI image using JAI. The problem is that I couldn't show this file with Geotools. You can look at the code here:

private void constructNDVI(File band3File, File band4File)
throws IOException {
PlanarImage iNIR = JAI.create("fileload", band3File.getAbsolutePath());
PlanarImage iVIS = JAI.create("fileload", band4File.getAbsolutePath());
// The pixels on those images must be processed as floating-point
// values!
ParameterBlock pbConvert = new ParameterBlock();
PlanarImage NIR = JAI.create("format", pbConvert);
pbConvert = new ParameterBlock();
PlanarImage VIS = JAI.create("format", pbConvert);
// Calculate the denominator (NIR-VIS).
ParameterBlock pbd = new ParameterBlock();
PlanarImage denominator = JAI.create("subtract", pbd);
// Calculate the numerator (NIR+VIS).
ParameterBlock pbn = new ParameterBlock();
PlanarImage numerator = JAI.create("add", pbd);
// Calculate the NDVI.
ParameterBlock pbNDVI = new ParameterBlock();
PlanarImage ndvi = JAI.create("divide", pbNDVI);
DisplayNBImage disp = new DisplayNBImage(ndvi);
String filename = new Date().getTime() + ".png";
JAI.create("filestore", disp.getSurrogateImage(), filename, "PNG");
File file = new File(filename);

You can find DisplayNBImage here[].

private void showNDVI(File file) throws IOException {
AbstractGridFormat format = GridFormatFinder.findFormat(file);
AbstractGridCoverage2DReader reader = format.getReader(file);
final MapContent map = new MapContent();
JMapFrame frame = new JMapFrame(map);

I can open the file I've created in constructNDVI method in Windows Photo Viewer or QGis. But 2nd line in showNDVI gives
Exception in thread "main" java.lang.UnsupportedOperationException: Trying to get a reader from an unknown format.

I've tried bmp, tiff but no luck. How can I overcome this?

In fact, proposing non-Jai way of the same thing would be awesome.