Note:The code will be seen as a mess. You can find it @
http://gis.stackexchange.com/questions/44924/opening-image-file-saved-with-jai-in-geotools
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();
pbConvert.addSource(iNIR);
pbConvert.add(DataBuffer.TYPE_DOUBLE);
PlanarImage NIR = JAI.create("format", pbConvert);
pbConvert = new ParameterBlock();
pbConvert.addSource(iVIS);
pbConvert.add(DataBuffer.TYPE_DOUBLE);
PlanarImage VIS = JAI.create("format", pbConvert);
// Calculate the denominator (NIR-VIS).
ParameterBlock pbd = new ParameterBlock();
pbd.addSource(NIR);
pbd.addSource(VIS);
PlanarImage denominator = JAI.create("subtract", pbd);
// Calculate the numerator (NIR+VIS).
ParameterBlock pbn = new ParameterBlock();
pbn.addSource(NIR);
pbn.addSource(VIS);
PlanarImage numerator = JAI.create("add", pbd);
// Calculate the NDVI.
ParameterBlock pbNDVI = new ParameterBlock();
pbNDVI.addSource(denominator);
pbNDVI.addSource(numerator);
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);
showNDVI(file);
}
You can find DisplayNBImage here[
http://www.lac.inpe.br/JIPCookbook/Code/display/surrogate/DisplayNBImage.java.txt
].
private void showNDVI(File file) throws IOException {
AbstractGridFormat format = GridFormatFinder.findFormat(file);
AbstractGridCoverage2DReader reader = format.getReader(file);
...
final MapContent map = new MapContent();
map.setTitle("ImageLab");
map.addLayer(rasterLayer);
...
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.
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users