Commit 357848ef authored by lafabregue's avatar lafabregue

switch to GDAL for image reading

parent 0fc1b77e
......@@ -17,3 +17,4 @@ local.properties
.settings/
.loadpath
*.hprof
/target/
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JCL</groupId>
<artifactId>JCL</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Java CLustering Library</description>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<name>JCL</name>
<organization>
<name>SDC - iCube</name>
<url>http://icube-sdc.unistra.fr/fr/index.php/Accueil</url>
</organization>
<dependencies>
<dependency>
<groupId>ome</groupId>
<artifactId>formats-gpl</artifactId>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.19</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>unidata</id>
<name>Unidata Repository</name>
<url>http://artifacts.unidata.ucar.edu/content/repositories/unidata-releases</url>
</repository>
<repository>
<id>ome</id>
<name>OME Artifactory</name>
<url>http://artifacts.openmicroscopy.org/artifactory/maven/</url>
</repository>
</repositories>
</project>
\ No newline at end of file
package jcl.clustering.ImageBased;
import java.io.IOException;
import java.util.Vector;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.clustering.LightCluster;
import jcl.data.DataObject;
import jcl.utils.Images.ImageReaderWrapper;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
import loci.formats.FormatException;
/**
* <p>
* Classe qui lit/écrit le resultat d'une classification d'une image via un fichier
* <p>
*
* @author baptistelafabregue
*
*/
public class ImagebasedClusteringResult extends ClusteringResult {
/** Chemin d'acces du fichier contenant le resultat de la classification */
private String filePath = "";
/** tableau qui contient pour chaque element d'un Data de type image son cluster de rattachement */
private byte[][] clusterMap = null;
/** non utilisé pour l'instant, mais doit pemerttre d'accéder au contenu de maniere streamee */
private int maxMemoryUsage = 0;
/** le format des pixel de l'image, correspond au formats de la classe FormatTool */
private int pixelType = 0;
/**
* <p>
* Constructeur
* <p>
*
* @param path
* le chemin d'acces du fichier contenant le resultat de la classification
* @param weights
* les ponderations utilisees
*/
public ImagebasedClusteringResult(String path, ClassificationWeights weights) {
this.filePath = path;
loadFromFile();
this.weights = weights;
this.randomColor();
}
/**
* <p>
* Constructeur
* <p>
*
* @param path
* le chemin d'acces du fichier contenant le resultat de la classification
* @param centroidsPath
* le chemin d'acces du fichier contenant la liste des centroids
* @param weights
* les ponderations utilisees
*/
public ImagebasedClusteringResult(String classifPath, String centroidsPath,
ClassificationWeights weights) {
this.filePath = classifPath;
loadFromFile();
Vector<DataObject> seeds = CentroidFileManager.readCentroidFile(centroidsPath);
this.clusters = new Cluster[seeds.size()];
for (int i = 0 ; i < seeds.size() ; i++) {
clusters[i] = new LightCluster(this, i, seeds.get(i));
}
this.weights = weights;
this.randomColor();
}
/**
* <p>
* Constructeur
* <p>
*
* @param path
* le chemin d'acces du fichier contenant le resultat de la classification
* @param seeds
* l'ensemble des centroides
* @param weights
* les ponderations utilisees
*/
public ImagebasedClusteringResult(String classifPath, Vector<DataObject> seeds,
ClassificationWeights weights) {
this.filePath = classifPath;
loadFromFile();
this.clusters = new Cluster[seeds.size()];
for (int i = 0 ; i < seeds.size() ; i++) {
clusters[i] = new LightCluster(this, i, seeds.get(i));
}
this.weights = weights;
this.randomColor();
}
/**
* <p>
* Constructeur de copie
* <p>
*
* @param result
* le FilebasedClusteringResult a copier
*/
public ImagebasedClusteringResult(ImagebasedClusteringResult result) {
this.filePath = result.getFilePath();
loadFromFile();
this.clusters = result.getClusters();
this.weights = (ClassificationWeights) result.weights.clone();
this.randomColor();
}
/** */
private static final long serialVersionUID = 1L;
@Override
public Object clone() {
return new ImagebasedClusteringResult(this);
}
@Override
public void deleteEmptyClusters() {
}
@Override
public int getClass(int o, boolean onWholeData) {
return clusterMap[o/clusterMap.length][o % clusterMap.length] & 0xFF;
}
@Override
public int[] getClusterMap() {
int[] result = new int[clusterMap.length*clusterMap[0].length];
int index = 0;
for (int j = 0 ; j <clusterMap[0].length ; j++) {
for (int i = 0 ; i < clusterMap.length ; i++) {
result[index] = clusterMap[i][j] & 0xFF;
index++;
}
}
return result;
}
@Override
public void setClusterMap(int[] clusterMap) {
if (clusterMap.length != this.clusterMap.length*this.clusterMap[0].length) {
new FormatException("Les nouvelles valeurs de cluster ne respectent pas les "
+ "dimensions de l'image en paramètre").printStackTrace();
}
int index = 0;
for (int j = 0 ; j < this.clusterMap[0].length ; j++) {
for (int i = 0 ; i < this.clusterMap.length ; i++) {
this.clusterMap[i][j] = (byte) clusterMap[index];
index++;
}
}
}
@Override
public int getNbObjects() {
if (clusterMap == null) {
return 0;
}
return clusterMap.length*clusterMap[0].length;
}
@Override
public void flushMemory() throws MethodNotImplementedException {
this.clusterMap = null;
}
/**
* <p>
* Renvoi le fichier qui contient le resultat de la classification
* <p>
*
* @return le chemin d'acces du fichier
*/
public String getFilePath() {
return filePath;
}
/**
* <p>
* Indique le fichier contenatn le resulat de la classification
* <p>
*
* @param filePath
* Le chemin d'acces du fichier
*/
public void setFilePath(String filePath) {
if (this.filePath != filePath) {
this.filePath = filePath;
loadFromFile();
}
}
private void loadFromFile() {
if (clusterMap == null) {
if (filePath != "") {
ImageReaderWrapper reader = new ImageReaderWrapper();
try {
reader.setImage(filePath);
pixelType = reader.getPixelType();
clusterMap = reader.get1BytePixels(0, 0, reader.getImageWidth(), reader.getImageHeight());
} catch (FormatException | IOException e) {
e.printStackTrace();
}
}
}
}
}
This diff is collapsed.
This diff is collapsed.
package jcl.data.sampling;
import java.util.List;
import java.util.Vector;
import jcl.data.DataObject;
import jcl.data.mask.Mask;
import jcl.utils.exceptions.MethodNotImplementedException;
import loci.formats.FormatException;
/**
*
* Implementation of the Sample class for extract some sample from an image
* The implementation is the same as ImageSampler but the dataObjects sample
* produce is set at the constructor and just retrieved. Note that the construction
* with a Mask is not yet supported.
*
* @author Baptiste LAFABREGUE
*
*/
public class ImportedImageSampler extends ImageSampler{
/** */
private static final long serialVersionUID = 1L;
private final List<DataObject> importedSample;
/**
* Constructor from a sequence of images
*
* @param imagesPaths
* paths of image's files in the sequence
* @param importedSample
* the set of DataObject that compose the sample
* @param selectedIndexes
* the set of indexes selected in importedSample
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public ImportedImageSampler(final Vector<String> imagesPaths, List<DataObject> importedSample,
List<Integer> selectedIndexes) throws FormatException {
super(imagesPaths);
this.importedSample = importedSample;
this.selectedIndexes = selectedIndexes;
this.setSizeByCount(importedSample.size());
}
/**
* Constructor from a sequence of images with the vectors to know how to match
* pixels between images, we also need to know where to start and end pixels.
* The user should know what are the non overlapping pixels and ignore them.
* It reads only pixel in the rectangle defined by those two points, this is
* different that reading between two indexes.
*
* @param imagesPaths
* paths of image's files in the sequence
* @param geoTranslateVectors
* vector to match images pixels
* @param startX
* X coordinate where to start read images
* @param startY
* Y coordinate where to start read images
* @param endX
* X coordinate where to end read images
* @param endY
* Y coordinate where to end read images
* @param importedSample
* the set of DataObject that compose the sample
* @param selectedIndexes
* the set of indexes selected in importedSample
*
* @throws FormatException
* if the end coordinates are out of the image
*/
public ImportedImageSampler(final Vector<String> imagesPaths, Vector<double[]> geoTranslateVectors,
int startX, int startY, int endX, int endY, List<DataObject> importedSample,
List<Integer> selectedIndexes) throws FormatException {
super(imagesPaths, geoTranslateVectors, startX, startY, endX, endY);
this.importedSample = importedSample;
this.selectedIndexes = selectedIndexes;
this.setSizeByCount(importedSample.size());
}
/**
* Constructor from an image
*
* @param imagesPaths
* the image file path
* @param importedSample
* the set of DataObject that compose the sample
* @param selectedIndexes
* the set of indexes selected in importedSample
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public ImportedImageSampler(final String imagesPaths, List<DataObject> importedSample,
List<Integer> selectedIndexes) {
super(imagesPaths);
this.importedSample = importedSample;
this.selectedIndexes = selectedIndexes;
this.setSizeByCount(importedSample.size());
}
/**
* Copy constructor
*
* @param sampler
* the sampler to copy
* @param importedSample
* the set of DataObject that compose the sample
* @param selectedIndexes
* the set of indexes selected in importedSample
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public ImportedImageSampler(ImageSampler sampler, List<DataObject> importedSample,
List<Integer> selectedIndexes) {
super(sampler);
this.importedSample = importedSample;
this.selectedIndexes = selectedIndexes;
this.setSizeByCount(importedSample.size());
}
@Override
public List<DataObject> getDataObjects() {
return importedSample;
}
@Override
public List<DataObject> getDataObjects(final Mask mask) {
new MethodNotImplementedException("This method is not yet implemented for Mask support").printStackTrace();
return null;
}
}
......@@ -4,6 +4,7 @@ import java.io.Serializable;
import jcl.clustering.ClusteringResult;
import jcl.data.Data;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
/**
......@@ -116,4 +117,21 @@ public abstract class LearningResult extends Object implements Serializable {
public void setBestFitness(final double[] bestFitness) {
this.bestFitness = bestFitness;
}
/**
* Export the learned result to a file
* @param path
* the file path
* @return the String containing the model of the LearningResult
*/
public abstract String ExportResult() throws MethodNotImplementedException;
/**
* Import the learned result to a file
* @param model
* the String containing the model of the LearningResult
* @return the LearningResult generated
*/
public abstract LearningResult ImportResult(String model) throws MethodNotImplementedException;
}
......@@ -9,6 +9,7 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.learning.LearningParameters;
import jcl.learning.LearningResult;
import jcl.utils.exceptions.MethodNotImplementedException;
/**
* résultats de classification obtenus par l'algorithme AHC
......@@ -135,4 +136,16 @@ public class LearningResultAHC extends LearningResult {
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -7,6 +7,7 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.LearningResult;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
/**
......@@ -228,4 +229,16 @@ public class LearningResultCobweb extends LearningResult {
public Concept getRoot() {
return this.racine;
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -7,6 +7,7 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.LearningResult;
import jcl.utils.exceptions.MethodNotImplementedException;
/**
* <p>
......@@ -241,4 +242,16 @@ public class LearningResultCure extends LearningResult {
// this.qualityIndices[4] = ClusteringEvaluation.HUBERT;
this.qualityIndices[1] = ClusteringEvaluation.WG;
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -8,6 +8,7 @@ import jcl.data.DataObject;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.LearningResult;
import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.utils.exceptions.MethodNotImplementedException;
/**
*
......@@ -188,4 +189,16 @@ public class LearningResultEM extends LearningResult {
public Object clone() {
return new LearningResultEM(this);
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -11,6 +11,7 @@ import jcl.learning.LearningParameters;
import jcl.learning.LearningResult;
import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.utils.exceptions.MethodNotImplementedException;
/**
* @author MARTAJ Mounir
......@@ -326,4 +327,16 @@ public class LearningResultEvidence extends LearningResult {
return this.FinalHierarchy;
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import jcl.data.DataObject;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.LearningParameters;
import jcl.learning.LearningResult;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
/**
......@@ -181,4 +182,16 @@ public class LearningResultGNG extends LearningResult {
this.qualityIndices[1] = ClusteringEvaluation.WG;
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -17,6 +17,7 @@ import jcl.data.mask.Mask;
import jcl.data.mask.MultiIDIntArrayMask;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.LearningResult;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import jcl.weights.LocalWeights;
......@@ -962,4 +963,16 @@ public class LearningResultKmeans extends LearningResult {
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
return null;
}
@Override
public String ExportResult() throws MethodNotImplementedException {
String model = "";
return model;
}
}
......@@ -9,6 +9,7 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.learning.LearningResult;
import jcl.learning.methods.monostrategy.kmeans.HardSeed;
import jcl.utils.exceptions.MethodNotImplementedException;
public class ResultConstraintKmeans extends LearningResult {
......@@ -204,4 +205,16 @@ public class ResultConstraintKmeans extends LearningResult {
protected void setQualityIndices() {
// TODO Auto-generated method stub
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -10,6 +10,7 @@ import jcl.data.DataObject;
import jcl.learning.LearningResult;
import jcl.learning.methods.monostrategy.kmeans.HardSeed;
import jcl.learning.methods.monostrategy.kmeans.KmeansSeed;
import jcl.utils.exceptions.MethodNotImplementedException;
public class ResultLocalKmeans extends LearningResult {
......@@ -160,4 +161,16 @@ public class ResultLocalKmeans extends LearningResult {
protected void setQualityIndices() {
// TODO Auto-generated method stub
}
@Override
public LearningResult ImportResult(String path) throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
@Override
public String ExportResult() throws MethodNotImplementedException {
throw new MethodNotImplementedException("Import/Export not yet implemented for " +
this.getClass().getEnclosingClass().getName());
}
}
......@@ -9,6 +9,7 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.learning.LearningResult;
import jcl.learning.methods.monostrategy.kmeans.HardSeed;