Commit 092a20c2 authored by lafabregue's avatar lafabregue

Initial commit

parents
temporary/*
*.class
*.hprof
*.log
# eclipse specific git ignore
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# libgdalconstjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgdalconstjni.so.20'
# Names of this library.
library_names='libgdalconstjni.so.20.3.1 libgdalconstjni.so.20 libgdalconstjni.so'
# The name of the static archive.
old_library='libgdalconstjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgdalconstjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gdalconst_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgdalconstjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libgdaljni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgdaljni.so.20'
# Names of this library.
library_names='libgdaljni.so.20.3.1 libgdaljni.so.20 libgdaljni.so'
# The name of the static archive.
old_library='libgdaljni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgdaljni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gdal_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgdaljni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libgnmjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libgnmjni.so.20'
# Names of this library.
library_names='libgnmjni.so.20.3.1 libgnmjni.so.20 libgnmjni.so'
# The name of the static archive.
old_library='libgnmjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libgnmjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 gnm_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libgnmjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libogrjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libogrjni.so.20'
# Names of this library.
library_names='libogrjni.so.20.3.1 libogrjni.so.20 libogrjni.so'
# The name of the static archive.
old_library='libogrjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libogrjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 ogr_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libogrjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
# libosrjni.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libosrjni.so.20'
# Names of this library.
library_names='libosrjni.so.20.3.1 libosrjni.so.20 libosrjni.so'
# The name of the static archive.
old_library='libosrjni.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -ljson-c -lfreexl -lqhull -lgeos_c -lwebp /usr/lib/x86_64-linux-gnu/libsqlite3.la -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator /usr/lib/x86_64-linux-gnu/libexpat.la -lxerces-c -lopenjp2 -lnetcdf -lhdf5_hl -lsz -lhdf5 /usr/lib/libmfhdfalt.la /usr/lib/libdfalt.la -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -lpq -lz -lpthread -lrt -ldl -lpcre /usr/lib/x86_64-linux-gnu/libcurl.la -lxml2'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libosrjni.
current=23
age=3
revision=1
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/baptiste/Downloads/gdal-2.2.2/swig/java; /bin/bash /home/baptiste/Downloads/gdal-2.2.2/libtool --mode=relink g++ -std=gnu++11 osr_wrap.lo /home/baptiste/Downloads/gdal-2.2.2/libgdal.la -o libosrjni.la -rpath /usr/local/lib -no-undefined -version-info 23:1:3 @inst_prefix_dir@)"
package multiCube.tools.image;
import java.io.File;
public class ImageHelper {
/**
* Remove extension from a file name
* @param str
* the file name
* @return the file name without extension
*/
public static String stripExtension (String str) {
// Handle null case specially.
if (str == null) return null;
// Get position of last '.'.
int pos = str.lastIndexOf(".");
// If there wasn't any '.' just return the string as is.
if (pos == -1) return str;
// Otherwise return the string, up to the dot.
return str.substring(0, pos);
}
/**
* Return the extension from a file name
* @param str
* the file name
* @return the file extension
*/
public static String getExtension (String str) {
// Handle null case specially.
if (str == null) return null;
// Get position of last '.'.
int pos = str.lastIndexOf(".");
// If there wasn't any '.' just return the string as is.
if (pos == -1) return "";
// Otherwise return the string, up to the dot.
return str.substring(pos, str.length());
}
/**
* Extract the file name from a path
* @param path
* the file full path
* @return the file name without extension
*/
public static String extractFileName (String path) {
// Handle null case specially.
if (path == null) return null;
// Get position of last '.'.
int pos = path.lastIndexOf(File.pathSeparator);
// If there wasn't any '.' just return the string as is.
if (pos == -1) return path;
// Otherwise return the string, up to the dot.
return path.substring(pos, path.length());
}
}
This diff is collapsed.
package multiCube.tools.image.reader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;
import loci.formats.FormatException;
import loci.formats.FormatTools;
import loci.formats.ImageReader;
/**
* <p>
* Wrapper au dessus des fonctions de lecture d'image de la libraire
* bio-formats qui permet de lire les images par tuile.
* <p>
*
* @author Baptiste LAFABREGUE
*
*/
public class ImageReaderWrapper {
ImageReader reader = null;
int currentImageIndex = 0;
public ImageReaderWrapper() {
reader = new ImageReader();
}
/**
* <p>
* Definit l'image a utiliser
* <p>
*
* @param path
* le chemin d'acces de l'image
*
* @throws FormatException
* @throws IOException
*/
public void setImage(String path) throws FormatException, IOException {
reader.setId(path);
}
/**
* <p>
* Renvoi un tableau de byte qui contient pour chaque coordonnee contient sa
* valeur sous la forme d'un tableau de byte pour une vue donnee de l'image.
* Format : byte[x][y][pixels]
*
* A noter que si les pixels font n bytes, les n premiers bytes seront pour la bande 1,
* les n suivant pour la bande 2, ect ..
* <p>
*
* @param x
* l'absisse du coin haut-gauche de la vue
* @param y
* l'ordonnee du coin haut-gauche de la vue
* @param w
* la largeur de la vue
* @param h
* la hauteur de la vue
* @return le tableau de byte contenant les valeus de la vue
*
* @throws IOException
* si il y a eu un probleme en lisant le fichier
* @throws FormatException
* si il y a eu un probleme en parsant les metadata du fichier
*/
public byte[][][] getPixels(int x, int y, int w, int h) throws FormatException, IOException {
byte[] rawData = reader.openBytes(currentImageIndex, x, y, w, h);
int channelCount = reader.getRGBChannelCount();
int pixelSize = reader.getBitsPerPixel()/8;
// test si on a bien le nombre attendu de pixels
if(rawData.length != w * h * channelCount * pixelSize) {
throw new IndexOutOfBoundsException("La taille du tableau de byte renvoye n'est pas celle attendue.");
}
int channelGap = rawData.length / channelCount;
byte[][][] result = new byte[w][h][channelCount*pixelSize];
int index = 0;
for(int j = 0 ; j < h ; j++) {
for(int i = 0 ; i < w ; i++) {
for(int c = 0 ; c < channelCount ; c++) {
for(int p = 0 ; p < pixelSize ; p++) {
result[i][j][c*pixelSize+p] = rawData[index+channelGap*c+p];
}
}
index++;
}
}
return result;
}
/**
* <p>
* Renvoi un tableau de byte qui contient pour chaque coordonnee sa
* valeur sous la forme d'un byte pour une vue donnee de l'image.
* L'image ne doit avoir qu'une seul bande avec un byte par pixel.
* Format : byte[x][y]
*
* <p>
*
* @param x
* l'absisse du coin haut-gauche de la vue
* @param y
* l'ordonnee du coin haut-gauche de la vue
* @param w
* la largeur de la vue
* @param h
* la hauteur de la vue
* @return le tableau de byte contenant les valeus de la vue
*
* @throws IOException
* si il y a eu un probleme en lisant le fichier
* @throws FormatException
* si il y a eu un probleme en parsant les metadata du fichier ou si
* l'image ne verifie pas les conditions d'une bande a 1 byte pixels
*/
public byte[][] get1BytePixels(int x, int y, int w, int h) throws FormatException, IOException {
int pixelSize = reader.getBitsPerPixel()/8;
int channelCount = reader.getRGBChannelCount();
if (pixelSize != 1 || channelCount != 1) {
throw new FormatException("The function get1BitPixels can only be called on images with "+
"only one chanel of one byte pixels.");
}
// test si on a bien qu'un seul byte par pixel et une seule bande sinon l'algorithme
byte[] rawData = reader.openBytes(currentImageIndex, x, y, w, h);
// test si on a bien le nombre attendu de pixels
if(rawData.length != w * h * channelCount * pixelSize) {
throw new IndexOutOfBoundsException("La taille du tableau de byte renvoye n'est pas celle attendue.");
}
byte[][] result = new byte[w][h];
int index = 0;
for(int j = 0 ; j < h ; j++) {
for(int i = 0 ; i < w ; i++) {
result[i][j] = rawData[index];
index++;
}
}
return result;
}
/**
* <p>
* Renvoi le nombre de bytes composant la valeur
* <p>
*
* @return le nombre de butes par pixel
*/
public int getBytesPerPixel() {
return reader.getBitsPerPixel()/8;
}
/**
* <p>
* Renvoi l'index d'image actuellement utilise
* <p>
*
* @return l'index d'image utilise
*/
public int getCurrentImageIndex() {
return currentImageIndex;
}
/**
* <p>
* Modifie l'image qui sera utilise pour les prochaines operations
* <p>
*
* @param currentImageIndex
* l'index de l'image a utiliser
*/
public void setCurrentImageIndex(int currentImageIndex) {
if (reader.getImageCount() < currentImageIndex) {
throw new IndexOutOfBoundsException("There are just " + reader.getImageCount() +
" images in the file " + reader.getCurrentFile());
}
this.currentImageIndex = currentImageIndex;
}
/**
* <p>
* Renvoi le nombre de pixel en largeur de l'image
* <p>
*
* @return la largeur de l'image
*/
public int getImageWidth() {
return reader.getSizeX();
}
/**
* <p>
* Renvoi le nombre de pixel en hauteur de l'image
* <p>
*
* @return la hauteur de l'image
*/
public int getImageHeight() {
return reader.getSizeY();
}
/**
* <p>
* Renvoi le nombre de bande de l'image
* <p>
*
* @return le nombre de bande
*/
public int getChannelCount() {
return reader.getRGBChannelCount();
}
/**
* <p>
* Renvoi le type de pixel de l'image
* INT8 = 0;
* UINT8 = 1;
* INT16 = 2;
* UINT16 = 3;
* INT32 = 4;
* UINT32 = 5;
* FLOAT = 6;
* DOUBLE = 7;
* BIT = 8;
* <p>
*
* @return le type de pixel
*/
public int getPixelType() {
return reader.getPixelType();
}
/**
* <p>
* Renvoi la valeur entiere d'un pixel. Cette fonction utilise les n premiers
* byte du tableau pour lire l'entier, avec n le nombre de de byte par pixel de l'image
* <p>
*
* @param pixel
* le pixel sous forme de tableau de byte
* @return la valeur en int du pixel
* @throws IOException
* @throws FormatException
* si le format de pixel ne peut etre caste vers int (double, float)
*/
public int getPixelValue(byte[] pixel) throws IOException, FormatException {
int pixelType = reader.getPixelType();
switch(pixelType) {
case(FormatTools.BIT) :
return pixel[0];
case(FormatTools.INT8) :
return pixel[0];
case(FormatTools.UINT8) :
return pixel[0] & 0xFF;
case(FormatTools.INT16) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 1))).readInt();
case(FormatTools.UINT16) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 1))).readUnsignedByte();
case(FormatTools.INT32) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 3))).readInt();
case(FormatTools.UINT32) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 3))).readUnsignedByte();
default :
throw new FormatException("The pixel format cannot be cast to int without ");
}
}
/**
* <p>
* Renvoi la valeur entiere d'un pixel. Cette fonction utilise les n premiers
* byte du tableau pour lire l'entier, avec n le nombre de de byte par pixel de l'image
* <p>
*
* @param pixel
* le pixel sous forme de tableau de byte
* @param pixelType
* le type de format du pixel
* @return la valeur en int du pixel
* @throws IOException
* @throws FormatException
* si le format de pixel ne peut etre caste vers int (double, float)
*/
static public int getPixelValue(byte[] pixel, int pixelType) throws IOException, FormatException {
switch(pixelType) {
case(FormatTools.BIT) :
return pixel[0];
case(FormatTools.INT8) :
return pixel[0];
case(FormatTools.UINT8) :
return pixel[0] & 0xFF;
case(FormatTools.INT16) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 1))).readInt();
case(FormatTools.UINT16) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 1))).readUnsignedByte();
case(FormatTools.INT32) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 3))).readInt();
case(FormatTools.UINT32) :
return new DataInputStream(new ByteArrayInputStream(
Arrays.copyOfRange(pixel, 0, 3))).readUnsignedByte();
default :
throw new FormatException("The pixel format cannot be cast to int without ");
}
}
}
This diff is collapsed.
package multiCube.tools.image.reader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Iterator;
import loci.formats.FormatException;
import loci.formats.FormatTools;
import loci.formats.ImageReader;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
/**
* <p>
* Wrapper above the image reading library bio-formats
* that allows to read images in a stream fashion
* <p>
*
* @author Baptiste Lafabregue
*
*/
public class StreamedImageReaderWrapper extends ReaderWrapper {
/** */
private static final long serialVersionUID = 1L;
ImageReader reader = null;
/** Buffer that contains the current view */
private byte[] tile = null;
/**
* <p>
* Constructor
* By default the tiling is the one recommended by the bio-format library
* <p>
*
* @param path
* The image file path
*/
public StreamedImageReaderWrapper(String path) {
this.reader = new ImageReader();
try {
setImage(path);
} catch (FormatException | IOException e) {
e.printStackTrace();
}
}
/**
* <p>
* Constructor by copy
* By default the tiling is the one recommended by the bio-format library
* so not the one of the copied wrapper.
* <p>
*
* @param path
* The image file path
*/
public StreamedImageReaderWrapper(StreamedImageReaderWrapper wrapper) {
this.reader = new ImageReader();
try {
setImage(wrapper.reader.getCurrentFile());
this.extrema = wrapper.extrema;
setMaxRAM(wrapper.maxRAM);
} catch (FormatException | IOException e) {
e.printStackTrace();
}
}
/**
* <p>
* Constructor
* <p>
*