...
 
Commits (6)
No preview for this file type
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,11 +18,11 @@ import javax.swing.JTextField;
import jcl.data.mask.IntArrayMask;
import jcl.data.mask.Mask;
import jcl.data.mask.MultiIDIntArrayMask;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
import mustic.gui.dialog.Messages;
import mustic.gui.panels.data.DataConstructPanel;
import mustic.io.RawImage;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import mustic.utils.io.CSVUtils;
......
......@@ -29,11 +29,9 @@ import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import loci.formats.FormatException;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
import mustic.io.PictureTool;
import mustic.io.RawImage;
import mustic.utils.documentFilter.ToUpdateObject;
......@@ -297,11 +295,8 @@ public class SequenceDialog extends JDialog {
* Return the list of image path constituting the selected sequence
*
* @return the list of ordered file path
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public Vector<RawImage> getSequenceData() throws FormatException {
public Vector<RawImage> getSequenceData() {
int nb = this.dlmSeq.getSize();
Donnee donnee;
Vector<RawImage> paths = new Vector<RawImage>();
......@@ -325,11 +320,8 @@ public class SequenceDialog extends JDialog {
* Return the list of image sessions constituting the selected sequence
*
* @return the list of ordered session
*
* @throws FormatException
* if the images don't have the same dimensions
*/
public Vector<ImageSession> getSequenceSessions() throws FormatException {
public Vector<ImageSession> getSequenceSessions() {
int nb = this.dlmSeq.getSize();
Donnee donnee;
Vector<ImageSession> paths = new Vector<ImageSession>();
......
......@@ -22,9 +22,9 @@ import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.text.NumberFormatter;
import multiCube.tools.image.ImageHelper;
import mustic.gui.MainFrame;
import mustic.utils.filters.ImageFileFilter;
import mustic.utils.image.ImageHelper;
import otbAppWrapping.ExecCommand;
public class WaterIndiceExtractionDialog extends JFrame {
......
......@@ -23,6 +23,9 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.gui.dialog.SequenceDialog;
......@@ -212,16 +215,23 @@ public class ArffToDataDialog extends JInternalFrame implements ToUpdateObject {
// test if we have one or multiples images
if (sequenceFiles.size() > 1) {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath,
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles);
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles, null, null);
} else {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath.get(0),
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0));
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0),
null, null);
}
} else {
// if no images is associated we create a SimpleData
data = new SimpleData((List<DataObject>) result[1]);
data = new SimpleData((List<DataObject>) result[1], null, null);
}
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(DataArffExchange.getRelationName(this.textFile.getText()));
......
......@@ -56,7 +56,7 @@ import jcl.clustering.constraints.LabelConstraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.utils.image.ImageAddOn;
......@@ -1019,7 +1019,9 @@ public class ConstraintsSelectionFrame extends JFrame implements ImageAddOn {
}
public void refresh() {
container.updateUI();
if (container != null) {
container.updateUI();
}
imageDisplayer.refresh(false);
}
......
......@@ -22,15 +22,15 @@ import javax.swing.JTextField;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.image.ImageHelper;
import mustic.utils.io.CSVUtils;
......
package mustic.gui.dialog.csv;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
<<<<<<< HEAD
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
=======
import multiCube.tools.image.ImageHelper;
>>>>>>> master
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.io.CSVUtils;
/**
* Dialog that allow the user to generate a Data from an arff file
*
* @author Baptiste LAFABREGUE
*
*/
public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
private static final long serialVersionUID = 1L;
private JTextField textFile = new JTextField();
private JTextField textData = new JTextField();
private JTextField textSeparator = new JTextField();
public CSVToDataDialog() {
super();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(3, 2));
JPanel pInpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.0")), BorderLayout.WEST); //$NON-NLS-1$
pInpout.add(this.textFile, BorderLayout.CENTER);
this.textFile.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
updateOutputName();
}
@Override
public void focusGained(FocusEvent e) {
}
});
JButton buttonBrowse = new JButton("..."); //$NON-NLS-1$
buttonBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser
.showOpenDialog(CSVToDataDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
CSVToDataDialog.this.textFile.setText(fileChooser
.getSelectedFile().getPath());
updateOutputName();
if (!fileChooser.getSelectedFile().getPath()
.endsWith(".csv")) { //$NON-NLS-1$
JOptionPane.showMessageDialog(CSVToDataDialog.this,
Messages.getString("CSVToDataDialog.3"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
}
}
});
pInpout.add(buttonBrowse, BorderLayout.EAST);
panel.add(pInpout);
JPanel pSeparator = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.2")), BorderLayout.WEST); //$NON-NLS-1$
pSeparator.add(this.textSeparator, BorderLayout.CENTER);
panel.add(pSeparator);
this.textSeparator.setText(";");
JPanel pOutpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.5")), BorderLayout.WEST); //$NON-NLS-1$
pOutpout.add(this.textData, BorderLayout.CENTER);
panel.add(pOutpout);
this.textFile.setPreferredSize(new Dimension(200, 30));
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("CSVToDataDialog.7")); //$NON-NLS-1$
panelButton.add(buttonOk);
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonOk_actionPerformed();
}
});
mainPanel.add(panel, BorderLayout.NORTH);
mainPanel.add(panelButton, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("CSVToDataDialog.8")); //$NON-NLS-1$
this.setSize(300, 180);
this.setResizable(true);
this.setMaximizable(true);
this.setIconifiable(true);
this.setClosable(true);
this.setVisible(true);
this.requestFocus();
}
private void updateOutputName() {
if (this.textData.getText() != null && this.textData.getText() != "") { //$NON-NLS-1$
// we don't update if there is already a value
return;
}
if (this.textFile.getText() != null && this.textFile.getText() != "") { //$NON-NLS-1$
this.textData.setText(ImageHelper.extractFileName(
ImageHelper.stripExtension(this.textData.getText())));
}
}
protected void buttonOk_actionPerformed() {
try {
List<DataObject> result = new ArrayList<DataObject>();
Data data = null;
CSVUtils reader = null;
try {
File file = new File(this.textFile.getText());
reader = new CSVUtils(file, this.textSeparator.getText().charAt(0));
List<String> line;
while((line = reader.readNext()) != null) {
extractObjectFromLine(result, line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
result = null;
}
if(result != null) {
data = new SimpleData(result, null, null);
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
data.setDistanceModel(model, parameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(ImageHelper.extractFileName(
ImageHelper.stripExtension(this.textData.getText())));
}
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.151") + this.textData.getText() //$NON-NLS-1$
+ " " + Messages.getString("CSVToDataDialog.152"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.16"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
this.dispose();
} catch (Exception e) {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
}
}
/**
* Construct a DataObject from a set of Strings and add it to a List
* @param list
* the list to add the DataObject to
* @param line
* the line to interpret
*/
private void extractObjectFromLine(List<DataObject> list, List<String> line) {
DataObject obj = new DataObject(1);
double[][] seq = new double[line.size()][];
for (int i = 0 ; i < line.size() ; i++) {
seq[i] = new double[1];
seq[i][0] = Double.parseDouble(line.get(i));
}
obj.setAttribute(0, new AttributeMultiDimSequence(seq));
list.add(obj);
}
@Override
public void update(String s) {
}
}
......@@ -20,10 +20,10 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
import jcl.data.Data;
import multiCube.tools.image.ImageHelper;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.image.ImageHelper;
import mustic.utils.io.dataExchange.DataOGRExchange;
/**
......
......@@ -21,6 +21,9 @@ import javax.swing.text.PlainDocument;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.BasicIntDocumentFilter;
......@@ -158,7 +161,13 @@ public class OGRToDataDialog extends JInternalFrame implements ToUpdateObject {
if(result != null) {
data = new SimpleData(result);
data = new SimpleData(result, null, null);
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
......
......@@ -28,10 +28,11 @@ import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.utils.io.JCLModelExchange;
import jsl.Segmentation;
import jsl.regionalisation.vectorisation.Filters;
import multiCube.tools.image.tiff.TiffUtils;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.*;
import mustic.gui.dialog.FilterDialog;
import mustic.gui.dialog.classifier.ConstraintsSelectionFrame;
......@@ -52,7 +53,6 @@ import mustic.utils.image.viewer.ClusteringImageViewer;
import mustic.utils.image.viewer.GDALPyramidImageViewer;
import mustic.utils.image.viewer.ImageViewer;
import mustic.utils.image.viewer.MultiResolutionClusterMap;
import mustic.utils.io.tiff.TiffUtils;
import org.apache.batik.svggen.SVGGraphics2DIOException;
......@@ -72,90 +72,90 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
private MultiResolutionClusterMap clusterMap = null;
protected File currentDirectory = null;
protected File currentDirectory = null;
/** Coordinates of the current position of the top left corner
* of the screen image in the original image */
private Point currentTopLeft = new Point(0,0);
private Point currentTopLeft = new Point(0,0);
/** l'image contenant les donnees d'origine */
private BufferedImage data;
private BufferedImage data;
/** l'image contenant les donnees d'origine */
protected BufferedImage data_zoomed;
protected BufferedImage data_zoomed;
/** panel that displays the image */
protected ZoomBoxPanel displayPanel = null;
protected ZoomBoxPanel displayPanel = null;
/** the list of add on that the displayer has subscribed to */
private Vector<ImageAddOn> imageAddOns = new Vector<ImageAddOn>();
private Vector<ImageAddOn> imageAddOns = new Vector<ImageAddOn>();
/** the parent session */
private ImageManager imageManager = null;
private ImageManager imageManager = null;
private ImageData imgData;
private ImageData imgData;
protected JInternalFrame jif_saveResult = new JInternalFrame();
protected JInternalFrame jif_saveResult = new JInternalFrame();
protected JLayeredPane lpane = new JLayeredPane();
protected JLayeredPane lpane = new JLayeredPane();
/** width of the screen image */
private int lastWidth = 0;
private int lastWidth = 0;
/** height of the screen image */
private int lastHeight = 0;
private int lastHeight = 0;
protected int[] map = null;
protected int[] map = null;
/** classification */
// protected Classification classification;
/** image initiale */
/** record the position of the mouse when it has been pressed */
private Point mousePressedCoordinates = null;
private Point mousePressedCoordinates = null;
// protected RawImage mRawImage;
// protected RawImage mRawImage;
/** zoom level */
protected double mZoomRate = 1.0f;
protected double mZoomRate = 1.0f;
/** zoom step */
private double mZoomStep = 0.7f;
private double mZoomStep = 0.7f;
// clusters' opacity
// up to 0 - 1
private float opacity = 1;
private float opacity = 1;
private float opacityCluster = 1;
private float opacityCluster = 1;
/** */
protected JPanel panelResSave = new JPanel();
protected JPanel panelResSave = new JPanel();
/** offset between the panel and the actual displayed image */
private Point screenOffset = new Point(0,0);
private Point screenOffset = new Point(0,0);
protected ClusteringResult result;
protected ClusteringResult result;
protected boolean[] resultSave = null;
protected boolean[] resultSave = null;
private ROIImage roi = null;
private ROIImage roi = null;
protected int rx = 0;
protected int rx = 0;
protected int ry = 0;
protected int ry = 0;
private float scaleFactor = 1.0f;
private float scaleFactor = 1.0f;
/** */
protected JToolBar tools = new JToolBar();
protected JToolBar tools = new JToolBar();
protected JButton vectorise = new JButton("Segmentation");
protected JButton vectorise = new JButton("Segmentation");
/** the viewer that allows to reader the image */
private ImageViewer viewer = null;
private ClusteringImageViewer viewer = null;
/** */
protected BufferedImage zoomed;
protected BufferedImage zoomed = null;
/**
*
......@@ -1679,8 +1679,14 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
@Override
public BufferedImage getBirdViewImage(double zoomFactor) {
// we want the original image in the birdview so we hide every clusters
viewer.disableClustersDisplay();
BufferedImage result = viewer.getScreenImage(0, 0, (int) (viewer.getRealImageWidth()*zoomFactor),
(int) (viewer.getRealImageHeight()*zoomFactor), zoomFactor, false);
viewer.enableClustersDisplay();
return result;
}
......
......@@ -5,7 +5,10 @@ import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.learning.LearningParameters;
import jcl.weights.GlobalWeights;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.MainFrame;
import mustic.io.ImageData;
......@@ -79,7 +82,13 @@ class RemoteSensingClassifierDialog extends ClassifierDialog {
if (this.bidouille == null) {
img = MainFrame.getInstance().getDesktop().getAllImageDesktopFrames()[this.dataBox
.getSelectedIndex()].getImageSession().getRawImage();
this.bidouille = new ImageData(img);
this.bidouille = new ImageData(img, null, null);
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
this.bidouille.getOneDataObject(), new GlobalWeights(this.bidouille.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, this.bidouille);
this.bidouille.setDistanceModel(distanceModel, distanceParameters);
}
LearningParameters params = this.classifiersPanel
......
......@@ -17,10 +17,10 @@ import javax.xml.parsers.SAXParserFactory;
import jcl.Classification;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.EmptyDistanceParameter;
import jcl.data.distance.average.AverageParameter;
......@@ -1022,7 +1022,8 @@ public class ClassifierPanel extends JPanel {
if (filePath.endsWith(".arff")) { //$NON-NLS-1$
int[][] clustering = DataArffExchange.arffToClusteredIndexes(filePath);
List<DataObject> result = ClassifierKmeans.getCentroidsFromClustering(data, clustering, model, null );//TODO
params = new ParametersKmeans(result.size(), 0, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(result.size(), 0, model, distanceParameters, averageParameters);
params.setSamples(new Vector<DataObject>(result));
} else {
JOptionPane.showMessageDialog(this,
......@@ -1074,7 +1075,8 @@ public class ClassifierPanel extends JPanel {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.COBWEB: {
......@@ -1115,7 +1117,9 @@ public class ClassifierPanel extends JPanel {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double beta = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.GWFCM: {
......@@ -1123,14 +1127,18 @@ public class ClassifierPanel extends JPanel {
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
double beta = Double.valueOf(((JTextField) comp[7]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.GLOBAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.LWKMEANS: {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double beta = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.LWFCM: {
......@@ -1138,7 +1146,9 @@ public class ClassifierPanel extends JPanel {
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
double m = Double.valueOf(((JTextField) comp[5]).getText()).doubleValue();
double beta = Double.valueOf(((JTextField) comp[7]).getText()).doubleValue();
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING, model, distanceParameters);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(model, data);
params = new ParametersKmeans(nbClusters, nbIters, m, beta, ParametersKmeans.LOCAL_FEATURE_WEIGHTING,
model, distanceParameters, averageParameters);
break;
}
case ClassifierUtils.GNG: {
......@@ -1963,6 +1973,10 @@ public class ClassifierPanel extends JPanel {
*/
public void updateParams(final int m, final boolean isImport) {
String[] method = ClassifierUtils.METHODS.get(new Integer(m));
if (isImport) {
method = ClassifierUtils.METHODS.get(new Integer(m+1000));
}
System.out.println("method : "+m);
this.paramsPanel.removeAll();
this.paramsPanel.setLayout(this.paramsGridLayout);
this.paramsGridLayout.setRows(method.length / 2);
......
......@@ -10,10 +10,10 @@ import javax.swing.*;
import javax.swing.border.TitledBorder;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.attribute.Attribute;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.sequential.DistanceEuclidean;
import jcl.learning.LearningParameters;
......
......@@ -18,7 +18,6 @@ import jcl.learning.methods.multistrategy.modular.ClassifierModular;
import jcl.learning.methods.multistrategy.modular.maclaw.ClassifierMaclaw;
import jcl.learning.methods.multistrategy.modular.maclaw.ParametersMaclaw;
import jcl.weights.*;
import loci.formats.FormatException;
import mustic.gui.*;
import mustic.gui.dialog.classifier.ClassifierDialog;
import mustic.gui.panels.classifier.SelectionModel;
......@@ -119,11 +118,7 @@ public class MaclawClassificationParametersPanel extends JPanel implements Param
if (this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox().getSelectedIndex() == nbSessions) {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getFirstIndex()].getImageSession()
.getImageData();
try {
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
} catch (FormatException e) {
e.printStackTrace();
}
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
}
else {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox()
......@@ -173,11 +168,7 @@ public class MaclawClassificationParametersPanel extends JPanel implements Param
if (this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox().getSelectedIndex() == nbSession) {
this.data = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getFirstIndex()].getImageSession()
.getImageData();
try {
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
} catch (FormatException e) {
e.printStackTrace();
}
this.data.setSequence(this.initMethodClassifierDialog.classifiersPanel.sequenceDialog.getSequenceData());
}
else {
imgSession = desktopFrames[this.initMethodClassifierDialog.classifiersPanel.getApproachPanel().getDataComboBox()
......
......@@ -15,7 +15,7 @@ import javax.swing.JScrollPane;
import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
......
......@@ -64,10 +64,10 @@ public class SegmentationPanel extends JPanel implements ActionListener, MouseLi
/*** truc ImageSession */
/** zoom level */
protected float mZoomRate = 1.0f; // 1.9f;
protected double mZoomRate = 1.0; // 1.9f;
/** zoom step */
protected float mZoomStep = 0.1f; // 0.2f;
protected double mZoomStep = 0.1; // 0.2f;
/** brightness value */
float offset = 10;
......
......@@ -264,7 +264,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* Apply the zoom factor. And display the image. When another operation is finished, this method
* <b>must be called<b>.
*/
public void doZoomOp(float mZoomRate) {
public void doZoomOp(double mZoomRate) {
AffineTransform trans = AffineTransform.getScaleInstance(mZoomRate, mZoomRate);
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
this.zoomed = op.filter(this.imageContours, null); // this.colored
......@@ -459,7 +459,7 @@ public class SegmentationPanelResultatImage extends JPanel {
}
public void clickSurImage(int x, int y, float mZoomRate) {
public void clickSurImage(int x, int y, double mZoomRate) {
if (x >= 0 && x < this.zoomed.getWidth() && y >= 0 && y < this.zoomed.getHeight()) {
this.setClicked(this.getPointWithReelCoordinates(x, y, mZoomRate));
this.updateInformationPanel(x, y, mZoomRate);
......@@ -472,7 +472,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* @param y the y co-ordinate of the point which is clicked.
* @return the point with the reel co-ordinates.
*/
public Point getPointWithReelCoordinates(int x, int y, float mZoomRate) {
public Point getPointWithReelCoordinates(int x, int y, double mZoomRate) {
int xreel, yreel;
xreel = (int) (((double) x / mZoomRate) + this.rx);
yreel = (int) (((double) y / mZoomRate) + this.ry);
......@@ -520,7 +520,7 @@ public class SegmentationPanelResultatImage extends JPanel {
* @param x x coord.
* @param y y coord.
*/
private void updateInformationPanel(int ex, int ey, float mZoomRate) {
private void updateInformationPanel(int ex, int ey, double mZoomRate) {
double w1 = contoursLabel.getWidth();
double w2 = contoursLabel.getIcon().getIconWidth();
......@@ -566,7 +566,7 @@ public class SegmentationPanelResultatImage extends JPanel {
}
}
public void setRegionToolTip(int x, int y, float mZoomRate) {
public void setRegionToolTip(int x, int y, double mZoomRate) {
if (x >= 0 && x < this.zoomed.getWidth() && y >= 0 && y < this.zoomed.getHeight()) {
Point clicked = this.getPointWithReelCoordinates(x, y, mZoomRate);
this.updateRegionInfos(clicked);
......
......@@ -5,13 +5,13 @@ import java.util.ArrayList;
import java.util.Vector;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
import mustic.models.thread.ProgressThreadJCL;
......
......@@ -8,8 +8,8 @@ import java.io.IOException;
import java.util.Iterator;
import jcl.data.mask.Mask;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
//import mustic.io.bsq.BSQImage;
......
......@@ -18,16 +18,16 @@ import mustic.gui.Messages;
import mustic.gui.dialog.MaskImportDialog;
import mustic.io.roi.ROIImage;
import mustic.io.roi.RegionOfInterest;
import mustic.utils.image.reader.GDALImageReaderWrapper;
import mustic.utils.image.reader.ReaderWrapper;
import otbAppWrapping.*;
import com.l2fprod.common.propertysheet.DefaultProperty;
import com.l2fprod.common.propertysheet.Property;
import jcl.data.mask.Mask;
import jcl.utils.MemoryFlush;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.image.reader.GDALImageReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
import multiCube.tools.util.MemoryFlush;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
/**
* <p>
......@@ -617,8 +617,20 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
{
try
{
setDataMatrice(replacer.loadImage(info.getTempPath(), info.getSizeX(), info.getSizeY(),
info.getNumberOfBands()));
// setDataMatrice(replacer.loadImage(info.getTempPath(), info.getSizeX(), info.getSizeY(),
// info.getNumberOfBands()));
GDALImageReaderWrapper reader = new GDALImageReaderWrapper(info.getPath());
double data[][][] = new double[reader.getChannelCount()][reader.getImageWidth()][reader.getImageHeight()];
for(int x = 0 ; x < reader.getImageWidth() ; x++) {
for (int y = 0 ; y < reader.getImageHeight() ; y++) {
double[] pixel = reader.getPixel(x, y);
for (int c = 0 ; c < pixel.length ; c++) {
data[c][x][y] = pixel[c];
}
}
}
setDataMatrice(data);
MainFrame.getProgressBar().setValue(MainFrame.getProgressBar().getValue() + 50);
}
catch (Exception e)
......@@ -897,11 +909,11 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
}
/**
* Retourne une image au format fr.unistra.pelican. TODO ne marche pas
* Retourne une image au format fr.unistra.pelican. TODO old methods, that is too memory consuming and support only 4 channels images
*/
public image.Image getPiafImage()
{
image.Image image = new image.ByteImage(this.getWidth(), this.getHeight(), 1, 1, this.getNbBands());
image.Image image = new image.DoubleImage(this.getWidth(), this.getHeight(), 1, 1, this.getNbBands());
double[][][] buffer = load(0, 0, getWidth(), getHeight());
......@@ -910,24 +922,24 @@ public class RawImage extends Observable implements Serializable, MemoryFlush
for (int b = 0; b < this.getNbBands(); b++)
{
int pixelValue = (int) buffer[b][x][y];
double pixelValue = (double) buffer[b][x][y];
if (b == this.r)
{
image.setPixelXYBByte(x, y, 0, pixelValue);
image.setPixelXYBDouble(x, y, 0, pixelValue);
// System.out.println(b+" "+this.r);
}
else if (b == this.g)
{
image.setPixelXYBByte(x, y, 1, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 1, buffer[b][x][y]);
}
else if (b == this.b)
{
image.setPixelXYBByte(x, y, 2, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 2, buffer[b][x][y]);
}
else
{
image.setPixelXYBByte(x, y, 3, (int) buffer[b][x][y]);
image.setPixelXYBDouble(x, y, 3, buffer[b][x][y]);
}
}
if (MainFrame.DEBUG_MODE)
......
......@@ -24,6 +24,7 @@ import jcl.Classification;
import jcl.data.Data;
import jcl.jcld.database.SSHParameters;
import jcl.learning.methods.monostrategy.SingleClassification;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.gui.DataSession;
import mustic.gui.MainFrame;
import mustic.gui.panels.ImageResultPanel;
......@@ -33,7 +34,6 @@ import mustic.models.gui.panels.HybridClassificationMonitor;
import mustic.models.gui.panels.MaclawClassificationMonitor;
import mustic.models.gui.panels.ResultPanel;
import mustic.models.gui.widgets.ClassificationManager;
import mustic.utils.tools.ProgressStatus;
import net.infonode.tabbedpanel.Tab;
import net.infonode.tabbedpanel.TabDragEvent;
import net.infonode.tabbedpanel.TabEvent;
......
......@@ -15,7 +15,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.models.gui.panels.ResultPanel;
import mustic.models.gui.panels.utils.ClassTreeRenderer;
......
......@@ -14,7 +14,7 @@ import javax.swing.JSpinner;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.models.gui.panels.ResultPanel;
public class SplitDialog extends JDialog {
......
......@@ -13,13 +13,13 @@ import javax.swing.tree.*;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.learning.IterativeClassification;
import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.utils.Matrix;
import jcl.utils.exceptions.MethodNotImplementedException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
import mustic.gui.ClassificationImage;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
......
package mustic.models.gui.panels;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.management.ManagementFactory;
import java.util.*;
......@@ -485,7 +487,11 @@ public class HybridClassificationMonitor extends JPanel implements Observer {
/** le panel pour l'affichage de la tendance */
private JPanel trendPanel = new JPanel();
private MyTableCellRenderer historyTableCellRenderer;
/** Button to ask the classification to stop */
private JButton stopButton = new JButton("Stop Classification");
/**
* <p>
......@@ -547,13 +553,24 @@ public class HybridClassificationMonitor extends JPanel implements Observer {
trendPanel.add(Box.createHorizontalGlue());
trendPanel.add(conflictsLabel);
trendPanel.add(Box.createHorizontalGlue());
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
HybridClassificationMonitor.this.classification.stopLearning();
}
});
JPanel southPane = new JPanel(new BorderLayout());
southPane.add(trendPanel, BorderLayout.CENTER);
southPane.add(stopButton, BorderLayout.SOUTH);
// creation du panel contenant les operateurs
JPanel operationsPanel = new JPanel(new GridLayout(2, 1, 10, 10));
operationsPanel.setBorder(BorderFactory.createTitledBorder("Evaluation"));
updateTrendPanel(0, -1);
JPanel jp = new JPanel(new BorderLayout());
jp.add(trendPanel, BorderLayout.SOUTH);
jp.add(southPane, BorderLayout.SOUTH);
jp.add(Box.createVerticalGlue(), BorderLayout.CENTER);
jp.add(historyTablePanel, BorderLayout.NORTH);
// jp.add(operationsPanel, BorderLayout.SOUTH);
......
......@@ -259,7 +259,8 @@ class MaclawViewer extends ViewerQualityEvolution {
ClusteringResult clusteringResult = null;
clusteringResult = this.learningResult.classify(this.data, false);
quality = clusteringResult.evaluate();
quality = clusteringResult.evaluate(this.data.getDistanceModel(),
this.data.getDistanceParameters()[0]);
quality.setTime(elapsed);
this.monitor.partitionEvolution.add(quality.getQualityIndex(0)
......
......@@ -9,8 +9,8 @@ import jcl.clustering.constraints.Constraint;
import jcl.jcld.RmiServer;
import jcl.learning.IterativeClassification;
import jcl.learning.methods.multistrategy.samarah4.comm.ClassificationSAM4;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.models.gui.ClassificationModel;
import mustic.utils.tools.ProgressStatus;
/**
* <p>
......
......@@ -5,8 +5,8 @@ import java.util.Date;
import javax.swing.JProgressBar;
import jcl.utils.Progressable;
import multiCube.tools.util.gui.ProgressStatus;
import mustic.gui.MainFrame;
import mustic.utils.tools.ProgressStatus;
/**
* <p>
......
......@@ -10,7 +10,7 @@ import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
import mustic.utils.image.reader.ReaderWrapper;
import multiCube.tools.image.reader.ReaderWrapper;
/**
* Class that allows buffer manipulation and creation from images.
......
package mustic.utils.image;
import java.io.File;
import image.Image;
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());
}
}
package mustic.utils.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 ");
}
}
}