Lire des fichiers TIFF multi-band
Bonjour tout le monde,
je viens voir si vous pourriez me donner un petit coup de main pour la gestion de mes images TIFF.
Je dois réaliser un programme qui va bosser sur des images provenant de satellites et contenant plusieurs bandes (R, G, B, proche infra rouge, moyen infra rouge et d'autres: 10 bandes en tout)
Je veux pouvoir ouvrir mes images, et accéder aux valeurs des pixels dans chaque bande. (pour pouvoir faire des calculs et des comparaisons dessus)
Je redebute en java, et ai trouve pour travailler sur des images les librairies JAI et JAI-imageIO, ainsi que des exemples de code pour travailler sur des fichiers TIFF.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package erwann;
import java.awt.Transparency;
import java.awt.image.*;
import java.io.File;
import javax.media.jai.*;
public class ImageInfo
{
public static void main(String[] args)
{
System.out.print("affiche1\n");
// Open the image (using the name passed as a command line parameter)
PlanarImage pi = JAI.create("fileload", args[0]);
System.out.print("affiche2");
// Get the image file size (non-JAI related).
File image = new File(args[0]);
System.out.println("Image file size: "+image.length()+" bytes.");
// Show the image dimensions and coordinates.
System.out.print("Dimensions: ");
//System.out.print(pi.getWidth()+"x"+pi.getHeight()+" pixels");
// Remember getMaxX and getMaxY return the coordinate of the next point!
System.out.println(" (from "+pi.getMinX()+","+pi.getMinY()+" to " +
(pi.getMaxX()-1)+","+(pi.getMaxY()-1)+")");
if ((pi.getNumXTiles() != 1)||(pi.getNumYTiles() != 1)) // Is it tiled?
{
// Tiles number, dimensions and coordinates.
System.out.print("Tiles: ");
System.out.print(pi.getTileWidth()+"x"+pi.getTileHeight()+" pixels"+
" ("+pi.getNumXTiles()+"x"+pi.getNumYTiles()+" tiles)");
System.out.print(" (from "+pi.getMinTileX()+","+pi.getMinTileY()+
" to "+pi.getMaxTileX()+","+pi.getMaxTileY()+")");
System.out.println(" offset: "+pi.getTileGridXOffset()+","+
pi.getTileGridXOffset());
}
// Display info about the SampleModel of the image.
SampleModel sm = pi.getSampleModel();
System.out.println("Number of bands: "+sm.getNumBands());
System.out.print("Data type: ");
switch(sm.getDataType())
{
case DataBuffer.TYPE_BYTE: System.out.println("byte"); break;
case DataBuffer.TYPE_SHORT: System.out.println("short"); break;
case DataBuffer.TYPE_USHORT: System.out.println("ushort"); break;
case DataBuffer.TYPE_INT: System.out.println("int"); break;
case DataBuffer.TYPE_FLOAT: System.out.println("float"); break;
case DataBuffer.TYPE_DOUBLE: System.out.println("double"); break;
case DataBuffer.TYPE_UNDEFINED:System.out.println("undefined"); break;
}
// Display info about the ColorModel of the image.
ColorModel cm = pi.getColorModel();
if (cm != null)
{
System.out.println("Number of color components: "+
cm.getNumComponents());
System.out.println("Bits per pixel: "+cm.getPixelSize());
System.out.print("Transparency: ");
switch(cm.getTransparency())
{
case Transparency.OPAQUE: System.out.println("opaque"); break;
case Transparency.BITMASK: System.out.println("bitmask"); break;
case Transparency.TRANSLUCENT:
System.out.println("translucent"); break;
}
}
else System.out.println("No color model.");
}
} |
Le probleme est que ce code ne fonctionne pas pour mes images TIFF a 10 bandes. L'image est correcte, je n'ai pas de problemes pour l'ouvrir avec ENVI, et j'ai fait attention d'en prendre une qui ne soit pas trop lourde a charger. Voici l'erreur que je prends:
Citation:
affiche1
affiche2Image file size: 584739 bytes.
Dimensions: Error: Cannot decode the image for the type :
Occurs in: com.sun.media.jai.opimage.CodecRIFUtil
java.io.IOException: Planar (band-sequential) format TIFF is not supported.
at com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.FileLoadRIF.create(FileLoadRIF.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getMinX(RenderedOp.java:2161)
at erwann.ImageInfo.main(ImageInfo.java:23)
Caused by: java.lang.RuntimeException: Planar (band-sequential) format TIFF is not supported.
at com.sun.media.jai.codecimpl.TIFFImage.<init>(TIFFImage.java:334)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:107)
... 32 more
Error: IOException occurs when decode the image.
Occurs in: com.sun.media.jai.opimage.StreamRIF
java.io.IOException: Planar (band-sequential) format TIFF is not supported.
at com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.codec.ImageDecoderImpl.decodeAsRenderedImage(ImageDecoderImpl.java:140)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.FileLoadRIF.create(FileLoadRIF.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getMinX(RenderedOp.java:2161)
at erwann.ImageInfo.main(ImageInfo.java:23)
Caused by: java.lang.RuntimeException: Planar (band-sequential) format TIFF is not supported.
at com.sun.media.jai.codecimpl.TIFFImage.<init>(TIFFImage.java:334)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:107)
... 23 more
Exception in thread "main" java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:827)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getMinX(RenderedOp.java:2161)
at erwann.ImageInfo.main(ImageInfo.java:23)
J'ai teste ce code avec d'autres images: avec une JPEG cela passe tres bien, et avec une image TIFF non "professionnelle"(comprendre une bete image en couleur), cela passe aussi. (dans ces 2 cas, cela me dit que mon image a 3 bandes R G et B)
Si certains d'entre vous ont des idees sur comment je peux faire pour reussir a ouvrir et utiliser mes images TIFF a 10 bandes, je suis preneur de tout conseil. J'espere que j'ai ete assez precis.
Merci par avance,
Erwannlh
gestion de tiff multi-layer
Bon,
je vois que ma question n'excite pas les foules :cry:
Il n'y a vraiment personne qui a une petite idee a ce sujet?
Erwannlh