Commit a949300f authored by adrmeyer's avatar adrmeyer

Merge branch 'master' of icube-forge.unistra.fr:lafabregue/Mustic

parents 33fe6b92 7da3f6fa
......@@ -53,7 +53,12 @@ public class ClassificationImage extends ClassificationModel {
@Override
synchronized public void addResult(Classification result, String title,
TabbedPanel pane) {
ImageResultPanel rpanel = new ImageResultPanel(result, this, ((ImageData) data));
ResultPanel rpanel = null;
if (data instanceof ImageData) {
rpanel = new ImageResultPanel(result, this, ((ImageData) data));
} else {
rpanel = new ResultPanel(result, this);
}
Tab t1 = ClassificationModel.createTab(title, new ImageIcon(getClass()
.getResource("/icons/actions/document-open-result.png")), //$NON-NLS-1$
rpanel, true);
......@@ -70,12 +75,14 @@ public class ClassificationImage extends ClassificationModel {
.getCurrentThreadCpuTime());
this.results.add(result);
this.addResult(result, Messages.getString("ClassificationImage.1") + ResultPanel.nbResult++); //$NON-NLS-1$
ImageResultPanel irp = (ImageResultPanel) this.tabbedPane.getTabAt(
ResultPanel irp = (ResultPanel) this.tabbedPane.getTabAt(
this.tabbedPane.getTabCount() - 1).getContentComponent();
irp.historique.addInfosln(Messages.getString("ClassificationImage.2")); //$NON-NLS-1$
if (result.getData().getOneDataObject().getAttribute(0) instanceof AttributeMultiDimSequence) {
irp.historique.addInfosln(Messages.getString("ClassificationImage.3")); //$NON-NLS-1$
irp.historique.addInfosln(result.getData().getDataFilesName().get(0));
if (result.getData().getDataFilesName().size() > 0) {
irp.historique.addInfosln(result.getData().getDataFilesName().get(0));
}
} else
irp.historique.addInfosln(Messages.getString("ClassificationImage.4") //$NON-NLS-1$
+ result.getData().getDataName() + "\n"); //$NON-NLS-1$
......
This diff is collapsed.
......@@ -222,7 +222,7 @@ public class ArffToDataDialog extends JInternalFrame implements ToUpdateObject {
JOptionPane.showMessageDialog(this,
Messages.getString("ArffToDataDialog.151") + this.textData.getText() //$NON-NLS-1$
+ Messages.getString("ArffToDataDialog.152"), //$NON-NLS-1$
+ " " + Messages.getString("ArffToDataDialog.152"), //$NON-NLS-1$
Messages.getString("ArffToDataDialog.16"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} else {
......
......@@ -8,6 +8,7 @@ import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import jcl.data.Data;
import jcl.learning.LearningParameters;
import mustic.gui.DataDesktopFrame;
import mustic.gui.DataSession;
......@@ -35,7 +36,7 @@ public class AgentDialog extends JDialog {
public ClassifierPanel classifierPanel = null;
/** */
ImageData imgdata;
Data imgdata;
/** bouton d'annulation */
JButton jButtonCancel = new JButton(Messages.getString("AgentDialog.0")); //$NON-NLS-1$
......@@ -148,7 +149,7 @@ public class AgentDialog extends JDialog {
[this.classifierPanel.getApproachPanel().getDataComboBox().getSelectedIndex()].getDataSession();
// récupère les données de l'image
this.imgdata = (ImageData) img.getData();
this.imgdata = img.getData();
this.imgdata.setDataFilesName(imgdata.getDataFilesName());
}
......@@ -173,8 +174,8 @@ public class AgentDialog extends JDialog {
}
} else {
System.out.println(this.imgdata.getWidth());
System.out.println(this.imgdata.getHeight());
// System.out.println(this.imgdata.getWidth());
// System.out.println(this.imgdata.getHeight());
System.out.println(this.imgdata.getNbObjects());
// cas particulier - utilisation samarah4
......
......@@ -173,21 +173,23 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
this.labelImage.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int x = (int) ((e.getX() - (int) ((labelImage.getWidth() - (labelImage.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
int y = (int) ((e.getY() - (int) ((labelImage.getHeight() - (labelImage.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
if (x>=0 && y>=0 && x<imageSource.getWidth() * mZoomRate && y<imageSource.getHeight() * mZoomRate) {
switch(currentStep) {
case MustLink_step1 : case CannotLink_step1 : case Label_step1 :
addFirstPixel(x, y);
break;
case MustLink_step2 : case CannotLink_step2 :
addSecondPixel(x, y);
break;
default :
// we don't refresh if not a valid step
return;
if (image != null) {
int x = (int) ((e.getX() - (int) ((labelImage.getWidth() - (labelImage.getIcon().getIconWidth())) / 2.0)) / mZoomRate);
int y = (int) ((e.getY() - (int) ((labelImage.getHeight() - (labelImage.getIcon().getIconHeight())) / 2.0)) / mZoomRate);
if (x>=0 && y>=0 && x<imageSource.getWidth() * mZoomRate && y<imageSource.getHeight() * mZoomRate) {
switch(currentStep) {
case MustLink_step1 : case CannotLink_step1 : case Label_step1 :
addFirstPixel(x, y);
break;
case MustLink_step2 : case CannotLink_step2 :
addSecondPixel(x, y);
break;
default :
// we don't refresh if not a valid step
return;
}
displayPixels();
}
displayPixels();
}
}
});
......@@ -263,14 +265,14 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
ExportConstraintsTask exportConstraintsTask = new ExportConstraintsTask(this);
exportConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
exportConstraintsTask.execute();
}
}
protected void importConstraints()
{
ImportConstraintsTask importConstraintsTask = new ImportConstraintsTask(this);
importConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
importConstraintsTask.execute();
}
importConstraintsTask.addPropertyChangeListener(new ProgressPropertyChangeListener());
importConstraintsTask.execute();
}
public int countLines(File aFile) throws IOException {
LineNumberReader reader = null;
......@@ -760,7 +762,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
.getComponent(1)).setText(""+index);
}
void displayPixels() {
private void displayPixels() {
if (image == null) {
return;
}
for (int x=0 ; x<this.imageSource.getWidth() ; x++) {
for (int y=0 ; y<this.imageSource.getHeight() ; y++) {
this.imagePoints.setRGB(x, y, this.imageSource.getRGB(x, y));
......@@ -902,7 +907,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
});
container.add(deleteButton);
currentStep = MustLink_step1;
mustLinkContainer.add(container);
constraintsPanels.add(container);
Random rand = new Random();
......@@ -910,7 +914,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
float g = rand.nextFloat();
float b = rand.nextFloat();
constraintsColors.add(new Color(r, g, b));
disableOtherComponents(container);
if (image != null) {
currentStep = MustLink_step1;
disableOtherComponents(container);
}
updateUI();
}
......@@ -937,7 +944,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
});
container.add(deleteButton);
currentStep = CannotLink_step1;
cannotLinkContainer.add(container);
constraintsPanels.add(container);
Random rand = new Random();
......@@ -945,7 +951,11 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
float g = rand.nextFloat();
float b = rand.nextFloat();
constraintsColors.add(new Color(r, g, b));
disableOtherComponents(container);
if (image != null) {
currentStep = CannotLink_step1;
disableOtherComponents(container);
}
updateUI();
}
......@@ -972,7 +982,6 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
});
container.add(deleteButton);
currentStep = Label_step1;
labelContainer.add(container);
constraintsPanels.add(container);
Random rand = new Random();
......@@ -980,7 +989,10 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
float g = rand.nextFloat();
float b = rand.nextFloat();
constraintsColors.add(new Color(r, g, b));
disableOtherComponents(container);
if (image != null) {
currentStep = Label_step1;
disableOtherComponents(container);
}
updateUI();
}
......@@ -1000,7 +1012,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame {
}
}
void enableAllComponents() {
private void enableAllComponents() {
for(Component c : otherComponentList) {
c.setEnabled(true);
}
......
package mustic.gui.dialog.csv;
import java.awt.BorderLayout;
import java.awt.Dialog;
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 java.util.Vector;
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 org.hibernate.mapping.Array;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.sampling.ImportedImageSampler;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.gui.dialog.SequenceDialog;
import mustic.io.ImageData;
import mustic.io.RawImage;
import mustic.utils.ImageHelper;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.io.CSVUtils;
import mustic.utils.io.dataExchange.DataArffExchange;
import weka.core.Instance;
import weka.core.Instances;
/**
* 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);
}
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())));
}
}
@SuppressWarnings({ "unchecked", "deprecation" })
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);
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) {
}
}
......@@ -70,7 +70,7 @@ ArffToImageDialog.8=ARFF
ArffToImageDialog.9=%% Dimension
ArffToDataDialog.0=Input Arff file \:
ArffToDataDialog.151=The data
ArffToDataDialog.152= have been loaded.
ArffToDataDialog.152=have been loaded.
ArffToDataDialog.16=Success
ArffToDataDialog.3=You must select an ARFF file.
ArffToDataDialog.4=Warning
......@@ -84,6 +84,22 @@ ArffToDataDialog.65=The number of image's channels does not match the sequence f
ArffToDataDialog.7=OK
ArffToDataDialog.8=ARFF
ArffToDataDialog.9=%% Dimension
CSVToDataDialog.0=Input CSV file \:
CSVToDataDialog.151=The data
CSVToDataDialog.152=have been loaded.
CSVToDataDialog.16=Success
CSVToDataDialog.2=Separator to use :
CSVToDataDialog.3=You must select a CSV file.
CSVToDataDialog.4=Warning
CSVToDataDialog.41=File selected isn't supported
CSVToDataDialog.5=Output Data name :
CSVToDataDialog.61=Do you want to associate some images to the Data ?\nYou need to associate
CSVToDataDialog.62= images to match the sequence.
CSVToDataDialog.64=The number of images does not match the sequence length.
CSVToDataDialog.65=The number of image's channels does not match the sequence format.
CSVToDataDialog.7=OK
CSVToDataDialog.8=CSV
CSVToDataDialog.9=%% Dimension
ConcatenateImagesDialog.1=Image concatenation
ConcatenateImagesDialog.2=Input image
ConcatenateImagesDialog.21=You should select at least two files
......
......@@ -70,7 +70,7 @@ ArffToImageDialog.8=ARFF
ArffToImageDialog.9=%% Dimension
ArffToDataDialog.0=Fichier Arff en entre \:
ArffToDataDialog.151=Le Data
ArffToDataDialog.152= a t charg.
ArffToDataDialog.152=a t charg.
ArffToDataDialog.16=Succs
ArffToDataDialog.3=Vous devez choisir un fichier ARFF.
ArffToDataDialog.4=Attention
......@@ -80,10 +80,26 @@ ArffToDataDialog.61=Voulez vous associer des images
ArffToDataDialog.62= images associer la squence.
ArffToDataDialog.63=\n\nLes images suivantes sont l'origine du fichier arff :\n
ArffToDataDialog.64=Le nombre d'images ne correspond la longueur de la squence.
ArffToDataDialog.65=Le nombre de bandes ne correspond entre la s"quences et les images.
ArffToDataDialog.65=Le nombre de bandes ne correspond entre la squences et les images.
ArffToDataDialog.7=OK
ArffToDataDialog.8=ARFF
ArffToDataDialog.9=%% Dimension
CSVToDataDialog.0=Fichier CSV en entre \:
CSVToDataDialog.151=Le Data
CSVToDataDialog.152=a t charg.
CSVToDataDialog.16=Succs
CSVToDataDialog.2=Sparateur utiliser :
CSVToDataDialog.3=Vous devez choisir un fichier CSV.
CSVToDataDialog.4=Attention
CSVToDataDialog.41=Le fichier slectionn n'est pas support.
CSVToDataDialog.5=Nom du Data a crer :
CSVToDataDialog.61=Voulez vous associer des images cette squence ?\nVous devez choisir
CSVToDataDialog.62= images associer la squence.
CSVToDataDialog.64=Le nombre d'images ne correspond la longueur de la squence.
CSVToDataDialog.65=Le nombre de bandes ne correspond entre la squences et les images.
CSVToDataDialog.7=OK
CSVToDataDialog.8=CSV
CSVToDataDialog.9=%% Dimension
ConfigDialog.0=Afficher une barre outils
ConfigDialog.1=Configuration
ConfigDialog.10=moyen
......
......@@ -162,8 +162,12 @@ MainFrame.301=Constraints
MainFrame.302=Arff to Data
MainFrame.303=Data to Arff
MainFrame.304=Distance Matrix
MainFrame.305=CSV to Data
MainFrame.306=Result to CSV
MainFrame.31=TransformationBmpToRoi...
MainFrame.32=Image/Data/ARFF
MainFrame.32=Import/Export
MainFrame.321=ARFF
MainFrame.322=CSV
MainFrame.33=Image to ARFF...
MainFrame.34=Load arff...
MainFrame.35=ARFF to image...
......
......@@ -159,11 +159,15 @@ MainFrame.29=Appliquer le masque...
MainFrame.3=nb sessions
MainFrame.30=Crer un sous-image...
MainFrame.301=Contraintes
MainFrame.302=Arff en Data
MainFrame.303=Data en Arff
MainFrame.302=Arff vers Data
MainFrame.303=Data vers Arff
MainFrame.304=Matrice des distances
MainFrame.305=CSV vers Data
MainFrame.306=Rsultat vers CSV
MainFrame.31=TransformationBmpEnRoi...
MainFrame.32=Image/Data/ARFF
MainFrame.32=Import/Export
MainFrame.321=ARFF
MainFrame.322=CSV
MainFrame.33=Image en ARFF...
MainFrame.34=Charger Arff...
MainFrame.35=ARFF en image...
......
package mustic.gui.panels.classifier;
import jcl.data.Data;
import jcl.learning.LearningParameters;
import mustic.io.ImageData;
public interface AgentListManager {
void addAgent(LearningParameters params, ImageData data);
void addAgent(LearningParameters params, Data data);
void removeAgent(int index);
......
......@@ -17,8 +17,10 @@ import javax.xml.parsers.SAXParserFactory;
import jcl.Classification;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.io.arff.ClassificationParametersIO;
import jcl.io.results.CSVResultWriter;
import jcl.jcld.RmiServer;
import jcl.learning.LearningParameters;
import jcl.learning.methods.ClassifierUtils;
......@@ -34,6 +36,8 @@ import jcl.learning.methods.monostrategy.kmeans.otb.ParametersOTBKmeans;
import jcl.learning.methods.monostrategy.perceptron.ParametersPerceptron;
import jcl.learning.methods.monostrategy.random.ParametersRandom;
import jcl.learning.methods.monostrategy.som.ParametersSOM;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahConfig;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import mustic.gui.*;
......@@ -46,6 +50,7 @@ import mustic.models.gui.dialogs.ServerParametersDialog;
import mustic.models.gui.panels.AttributeSelectionPanel;
import mustic.models.gui.panels.HybridClassificationAdvancedParametersPanel;
import mustic.models.thread.ClassificationThread;
import mustic.utils.io.CSVUtils;
import mustic.utils.io.dataExchange.DataArffExchange;
import com.l2fprod.common.swing.JTaskPane;
......@@ -94,6 +99,7 @@ public class ClassifierPanel extends JPanel {
/** Bouton d'action : lance la classification */
public JButton classifyButton = new JButton(Messages.getString("ClassifierPanel.4")); //$NON-NLS-1$
public JButton customButton = new JButton("Custom Classif");
/** La panel pour l'affichage du bouton de lancement de la classification */
private JPanel classifyButton_ = new JPanel();
......@@ -415,6 +421,14 @@ public class ClassifierPanel extends JPanel {
}
});
/* Lance la classification */
this.customButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//customClassify();
}
});
/* Lance la classification */
this.classifierButton.addActionListener(new ActionListener() {
@Override
......@@ -445,6 +459,7 @@ public class ClassifierPanel extends JPanel {
/* Affichage */
if (!monoApproach) {
classifyButton_.add(this.classifyButton);
classifyButton_.add(this.customButton);
// classifyButton_.add(this.classifierButton);
// classifierButton.setVisible(false);