Commit 11dbff3d authored by lafabregue's avatar lafabregue
Browse files

add some simplemodifications

parent 21098208
This diff is collapsed.
......@@ -66,7 +66,7 @@ public class ImageSession {
public SSHParameters sshparameters = null;
/** enable the image to display the image or not, for a memory usage matter */
private boolean displayEnable = true;
private boolean displayEnable = false;
/**
* @param aImage
......
......@@ -65,10 +65,10 @@ import mustic.io.*;
import mustic.models.gui.ClassificationModel;
import mustic.models.gui.panels.*;
import mustic.models.thread.ClassificationThread;
import mustic.utils.ImageHelper;
import mustic.utils.UnZipSub;
import mustic.utils.filters.ImageFileFilter;
import mustic.utils.filters.ZipFileFilter;
import mustic.utils.image.ImageHelper;
import mustic.utils.io.CSVUtils;
import mustic.utils.io.dataExchange.DataCsvExchange;
import net.infonode.tabbedpanel.*;
......@@ -2974,7 +2974,7 @@ public class MainFrame extends JFrame {
currentImageSession.getBirdViewPanel().setR(0);
currentImageSession.getBirdViewPanel().setG(1);
currentImageSession.getBirdViewPanel().setB(2);
currentImageSession.getBirdViewPanel().syncImage(currentImageSession);
currentImageSession.getBirdViewPanel().syncImage();
PictureTool.setR(MainFrame.this.currentImageSession.getRawImage().getBirdview(), 0);
PictureTool.setG(MainFrame.this.currentImageSession.getRawImage().getBirdview(), 1);
PictureTool.setB(MainFrame.this.currentImageSession.getRawImage().getBirdview(), 2);
......@@ -3719,7 +3719,7 @@ public class MainFrame extends JFrame {
private void customClassify() {
HybridClassification classification = new HybridClassification();
String datasetName = "InsectWingbeatSound";
String datasetName = "StarLightCurves";
String dataPath = "/home/baptiste/A2CNES/";
String resultPath = "/home/baptiste/A2CNES/results/";
String testResultPath = "/home/baptiste/A2CNES/Train_results/";
......@@ -3730,8 +3730,8 @@ public class MainFrame extends JFrame {
DataDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop().getAllDataDesktopFrames();
DataSession testSession = desktopFrames[desktopFrames.length-1].getDataSession();
int nInf = 10;
int nSup = 13;
int nInf = 3;
int nSup = 5;
// parametre pour la precision des conflits
double minC = 0.9;
......@@ -3742,7 +3742,7 @@ public class MainFrame extends JFrame {
// parametre qualite/similitude
double ps = 0.2;
double pq = 1.0 - ps;
double constraintsWgt = 0;
double constraintsWgt = 85;
double valueKExtern = 60;
double kExtern = valueKExtern * ((100-constraintsWgt)/100);
double kIntern = (100 - valueKExtern) * ((100-constraintsWgt)/100);
......@@ -3782,121 +3782,120 @@ public class MainFrame extends JFrame {
// classif.setName(testResultPath+datasetName+"/clusteing"+i);
// classif.setData(dataTrain);
//// >>>> END FOR PARAM config1
for (int i = 0 ; i < 10 ; i++) {
HybridClassification classif = (HybridClassification) classification.clone();
classif.addAgent(new ParametersKmeans(11, 15, weights), dataTrain);
classif.addAgent(new ParametersKmeans(13, 15, weights), dataTrain);
classif.addAgent(new ParametersKmeans(16, 15, weights), dataTrain);
classif.addAgent(new ParametersKmeans(19, 15, weights), dataTrain);
classif.setName(resultPath+datasetName+"/clustering"+i);
classif.setData(dataTest);
// for (int i = 0 ; i < 10 ; i++) {
// HybridClassification classif = (HybridClassification) classification.clone();
// classif.addAgent(new ParametersKmeans(4, 15, weights), dataTest);
// classif.addAgent(new ParametersKmeans(6, 15, weights), dataTest);
// classif.addAgent(new ParametersKmeans(8, 15, weights), dataTest);
//
// classif.setName(resultPath+datasetName+"/clustering"+i);
// classif.setData(dataTest);
//// >>>> REPLACE PARAM
Thread t = null;
ClassificationImage classificationImage = new ClassificationImage(dataTest,
Messages.getString("ClassifierPanel.73") + DataSession.nbClustering, //$NON-NLS-1$
true);
t = new ClassificationThread(classif, classificationImage.getProgressBar(),
classificationImage, null);
t.start();
try {
testSession.associatedFrame.setMaximum(true);
} catch (PropertyVetoException e1) {}
testSession.addClassifier(classificationImage);
try {
testSession.associatedFrame.setSelected(true);
testSession.associatedFrame.toFront();
} catch (PropertyVetoException e) {
e.printStackTrace();
}
classificationImage.toFront();
classificationImage.setVisible(true);
threadList.add(t);
classifList.add(classif);
}
// <<<< CONSTRAINTS
// try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(
// Paths.get(dataPath+datasetName+"/test/"), "*constraints")) {
// Iterator<Path> iter = dirStream.iterator();
// while(iter.hasNext()) {
// Vector<Constraint> constraints = new Vector<Constraint>();
// String filename = iter.next().getFileName().toString();
// System.out.println(filename);
// CSVUtils reader = null;
// try {
// reader = new CSVUtils(new File(dataPath+datasetName+"/test/"+filename), '\t');
// List<String> line;
// while((line = reader.readNext()) != null) {
// switch (Integer.parseInt(line.get(line.size()-1))) {
// case Constraint.MUST_LINK_TYPE :
// try {
// int index1 = Integer.parseInt(line.get(0))-1;
// int index2 = Integer.parseInt(line.get(1))-1;
// constraints.add(new MustLinkConstraint(index1, index2));
// } catch(Exception e) {
// e.printStackTrace();
// }
// break;
// case Constraint.CANNOT_LINK_TYPE :
// try {
// int index1 = Integer.parseInt(line.get(0))-1;
// int index2 = Integer.parseInt(line.get(1))-1;
// constraints.add(new CannotLinkConstraint(index1, index2));
// } catch(Exception e) {
// e.printStackTrace();
// }
// break;
// }
// }
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// HybridClassification classif = (HybridClassification) classification.clone();
// Data currentData = (Data) dataTest.clone();
// currentData.updateAndSetConstraintsToSample(constraints);
//
// classif.addAgent(new ParametersKmeans(14, 15, weights), currentData);
// classif.addAgent(new ParametersKmeans(17, 15, weights), currentData);
// classif.addAgent(new ParametersKmeans(20, 15, weights), currentData);
//
// classif.setName(resultPath+datasetName+"/"+
// ImageHelper.stripExtension(filename)+
// ".clustering");
// classif.setData(dataTest);
//
// Thread t = null;
//
// ClassificationImage classificationImage = new ClassificationImage(currentData,
// Messages.getString("ClassifierPanel.73") + DataSession.nbClustering, //$NON-NLS-1$
// true);
//
//
// t = new ClassificationThread(classif, classificationImage.getProgressBar(),
// classificationImage, null);
// t.start();
// try {
// testSession.associatedFrame.setMaximum(true);
// } catch (PropertyVetoException e1) {}
// testSession.addClassifier(classificationImage);
// try {
// testSession.associatedFrame.setSelected(true);
// testSession.associatedFrame.toFront();
// } catch (PropertyVetoException e) {
// e.printStackTrace();
// }
// classificationImage.toFront();
// classificationImage.setVisible(true);
//
// threadList.add(t);
// classifList.add(classif);
// }
// } catch (IOException e2) {
// e2.printStackTrace();
// Thread t = null;
//
// ClassificationImage classificationImage = new ClassificationImage(dataTest,
// Messages.getString("ClassifierPanel.73") + DataSession.nbClustering, //$NON-NLS-1$
// true);
//
//
// t = new ClassificationThread(classif, classificationImage.getProgressBar(),
// classificationImage, null);
// t.start();
// try {
// testSession.associatedFrame.setMaximum(true);
// } catch (PropertyVetoException e1) {}
// testSession.addClassifier(classificationImage);
// try {
// testSession.associatedFrame.setSelected(true);
// testSession.associatedFrame.toFront();
// } catch (PropertyVetoException e) {
// e.printStackTrace();
// }
// classificationImage.toFront();
// classificationImage.setVisible(true);
//
// threadList.add(t);
// classifList.add(classif);
// }
// <<<< CONSTRAINTS
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(
Paths.get(dataPath+datasetName+"/test/"), "*constraints")) {
Iterator<Path> iter = dirStream.iterator();
while(iter.hasNext()) {
Vector<Constraint> constraints = new Vector<Constraint>();
String filename = iter.next().getFileName().toString();
System.out.println(filename);
CSVUtils reader = null;
try {
reader = new CSVUtils(new File(dataPath+datasetName+"/test/"+filename), '\t');
List<String> line;
while((line = reader.readNext()) != null) {
switch (Integer.parseInt(line.get(line.size()-1))) {
case Constraint.MUST_LINK_TYPE :
try {
int index1 = Integer.parseInt(line.get(0))-1;
int index2 = Integer.parseInt(line.get(1))-1;
constraints.add(new MustLinkConstraint(index1, index2));
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = Integer.parseInt(line.get(0))-1;
int index2 = Integer.parseInt(line.get(1))-1;
constraints.add(new CannotLinkConstraint(index1, index2));
} catch(Exception e) {
e.printStackTrace();
}
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
HybridClassification classif = (HybridClassification) classification.clone();
Data currentData = (Data) dataTest.clone();
currentData.updateAndSetConstraintsToSample(constraints);
classif.addAgent(new ParametersKmeans(4, 15, weights), currentData);
classif.addAgent(new ParametersKmeans(6, 15, weights), currentData);
classif.addAgent(new ParametersKmeans(8, 15, weights), currentData);
classif.setName(resultPath+datasetName+"/"+
ImageHelper.stripExtension(filename)+
".clustering");
classif.setData(dataTest);
Thread t = null;
ClassificationImage classificationImage = new ClassificationImage(currentData,
Messages.getString("ClassifierPanel.73") + DataSession.nbClustering, //$NON-NLS-1$
true);
t = new ClassificationThread(classif, classificationImage.getProgressBar(),
classificationImage, null);
t.start();
try {
testSession.associatedFrame.setMaximum(true);
} catch (PropertyVetoException e1) {}
testSession.addClassifier(classificationImage);
try {
testSession.associatedFrame.setSelected(true);
testSession.associatedFrame.toFront();
} catch (PropertyVetoException e) {
e.printStackTrace();
}
classificationImage.toFront();
classificationImage.setVisible(true);
threadList.add(t);
classifList.add(classif);
}
} catch (IOException e2) {
e2.printStackTrace();
}
// >>>> CONSTRAINTS
new Thread() {
......@@ -3916,6 +3915,7 @@ public class MainFrame extends JFrame {
e.printStackTrace();
}
}
System.out.println("wrote final results");
}
}.start();
......
......@@ -128,8 +128,7 @@ public class RgbBandChooserInternalFrame extends JInternalFrame {
currentImageSession.getBirdViewPanel().setR(red);
currentImageSession.getBirdViewPanel().setG(green);
currentImageSession.getBirdViewPanel().setB(blue);
currentImageSession.getBirdViewPanel().syncImage(
currentImageSession);
currentImageSession.getBirdViewPanel().syncImage();
MainFrame.getInstance().getCurrentImageSession().getBirdViewPanel()
.refresh();
......
......@@ -253,9 +253,7 @@ public class SequenceDialog extends JDialog {
.getInstance()
.getCurrentImageSession()
.getBirdViewPanel()
.syncImage(
MainFrame.getInstance()
.getCurrentImageSession());
.syncImage();
PictureTool.setR(MainFrame.getInstance()
.getCurrentImageSession().getRawImage()
.getBirdview(), 0);
......
......@@ -23,8 +23,8 @@ import javax.swing.SpinnerNumberModel;
import javax.swing.text.NumberFormatter;
import mustic.gui.MainFrame;
import mustic.utils.ImageHelper;
import mustic.utils.filters.ImageFileFilter;
import mustic.utils.image.ImageHelper;
import otbAppWrapping.ExecCommand;
public class WaterIndiceExtractionDialog extends JFrame {
......
......@@ -34,8 +34,8 @@ 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.image.ImageHelper;
import mustic.utils.io.CSVUtils;
import mustic.utils.io.dataExchange.DataArffExchange;
import weka.core.Instance;
......
......@@ -13,6 +13,8 @@ import mustic.gui.*;
import mustic.io.RawImage;
import mustic.io.roi.RegionOfInterest;
import mustic.utils.filters.ZipFileFilter;
import mustic.utils.image.BufferedImageViewer;
import mustic.utils.image.ImageViewer;
/**
* Display an image and allows the user to do some operations on it (zoom, contrast..)
......@@ -20,60 +22,60 @@ import mustic.utils.filters.ZipFileFilter;
public class ImagePanel extends JPanel {
/** */
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/** The transparency must be between 0.0 and 1.0 */
public static float transparency = new Float(0.50);
public static float transparency = new Float(0.50);
/** brightness value */
private float brightnessValue = 10;
private float brightnessValue = 10;
protected JMenuItem classifyAll;
protected JMenuItem classifyAll = null;
public Image img;
public Image img = null;
private boolean isDataBaseImage = false;
private boolean isDataBaseImage = false;
/** panel used to pick up information on the birdview selection */
protected BirdViewPanel mBirdPanell;
protected BirdViewPanel mBirdPanell = null;
/** label which contains the image */
public JLabel mImageLabel;
public JLabel mImageLabel = null;
/** panel used to update the informations when mouse moved */
protected ImageInformationPanel mInfoPanel;
protected ImageInformationPanel mInfoPanel = null;
protected MouseListener mouseListener = new MouseClickedListener();
/** screen image */
protected BufferedImage mScreenImage;
/**
* original image
*/
protected BufferedImage mSourceImage;
protected MouseListener mouseListener = new MouseClickedListener();
/** zoom level */
protected float mZoomRate = 1.9f;
protected float mZoomRate = 1.9f;
/** zoom step */
private float mZoomStep = 0.2f;
private float mZoomStep = 0.2f;
/** brightness step */
private float offsetStep = 5.0f;
private float offsetStep = 5.0f;
private ClassList pl_label;
private ClassList pl_label = null;
/** operation of rescaling */
RescaleOp rescale;
RescaleOp rescale = null;
/** contrast value */
private float scaleFactor = 1.0f;
private float scaleFactor = 1.0f;
/** contrast step */
private float scaleFactorStep = 0.1f;
private float scaleFactorStep = 0.1f;
private RawImage rawImage = null;
private RawImage rawImage = null;
private ImageViewer viewer = null;
/** screen image */
protected BufferedImage mScreenImage = null;
/** original image */
protected BufferedImage mSourceImage = null;
/**
* Create a new ImagePanel from a BufferedImage.
......@@ -82,11 +84,11 @@ public class ImagePanel extends JPanel {
public ImagePanel(BufferedImage aImage) {
if (MainFrame.DEBUG_MODE)
System.out.println("ImagePanel 1");
this.mSourceImage = aImage;
this.mScreenImage = aImage;
this.mImageLabel = new JLabel(new ImageIcon(this.mScreenImage));
this.mImageLabel.setHorizontalAlignment(SwingConstants.CENTER);
this.viewer = new BufferedImageViewer(aImage);
setLayout(new BorderLayout());
this.mImageLabel = new JLabel(new ImageIcon(viewer.getmScreenImage(0, 0,
this.getHeight(), this.getWidth(), mZoomRate)));
this.mImageLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(this.mImageLabel, BorderLayout.CENTER);
}
......@@ -794,7 +796,7 @@ public class ImagePanel extends JPanel {
// ip.birdViewPanel
imageSession.getBirdViewPanel().syncImage(jInternalFrames[s].getImageSession());
imageSession.getBirdViewPanel().syncImage();
ip.reloadPoint(imageSession.getBirdViewPanel().xxsave, imageSession.getBirdViewPanel().yysave,
imageSession.getBirdViewPanel().rxsave, imageSession.getBirdViewPanel().rysave);
......@@ -857,7 +859,7 @@ public class ImagePanel extends JPanel {
for (int s = 0; s < jInternalFrames.length; s++) {
//ImagePanel ip = jInternalFrames[s].getImageSession().getImagePanel();
ImageSession imageSes = jInternalFrames[s].getImageSession();
imageSes.getBirdViewPanel().syncImage(jInternalFrames[s].getImageSession());
imageSes.getBirdViewPanel().syncImage();
}
}
}
......
......@@ -30,12 +30,12 @@ import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
//<<<< TRANSPARENCE
import jcl.utils.Images.StreamedImageReaderWrapper;
//import jcl.utils.Images.StreamedImageReaderWrapper;
//>>>> TRANSPARENCE
import jsl.Segmentation;
import jsl.regionalisation.vectorisation.Filters;
//<<<< TRANSPARENCE
import loci.formats.FormatException;
//import loci.formats.FormatException;
//>>>> TRANSPARENCE
import mustic.gui.*;
import mustic.gui.dialog.FilterDialog;
......@@ -46,6 +46,7 @@ import mustic.models.gui.ClassificationModel;
import mustic.models.gui.panels.*;
import mustic.utils.Packager;
import mustic.utils.filters.*;
import mustic.utils.io.tiff.TiffUtils;
import org.apache.batik.svggen.SVGGraphics2DIOException;
......@@ -129,21 +130,21 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
protected BufferedImage zoomed;
//<<<< TRANSPARENCE
// clusters' opacity
// up to 0 - 1
public static float opacity = 1;
public static float opacityCluster = 1;
public float getOpacity()
{
return opacity;
}
public float getOpacityCluster()
{
return opacityCluster;
}
// // clusters' opacity
// // up to 0 - 1
// public static float opacity = 1;
//
// public static float opacityCluster = 1;
//
// public float getOpacity()
// {
// return opacity;
// }
//
// public float getOpacityCluster()
// {
// return opacityCluster;
// }
//>>>> TRANSPARENCE
/**
......@@ -658,7 +659,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
updateImageColors();
if (imgData.getAssociatedImageSessions() != null && imgData.getAssociatedImageSessions().size() > 0) {
imgData.getAssociatedImageSessions().get(0).getBirdViewPanel().syncImage(imgData.getAssociatedImageSessions().get(0));
imgData.getAssociatedImageSessions().get(0).getBirdViewPanel().syncImage();
}
this.resultTabbedPane.addTab("Image Result", this.panelImage);
......@@ -824,8 +825,11 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
/** Sauvegarde de l'image couleur */
// retrieve image
BufferedImage bi = imgPanel.getFullColorImage();
File outputfile = new File("imageColor");
ImageIO.write(bi, "png", outputfile);
String outputPath = "imageColor.tif";
File outputfile = new File(outputPath);
// ImageIO.write(bi, "png", outputfile);
TiffUtils.writeRGBTiffwithMetaData(bi, outputPath,
imgPanel.getImgData().getDataFilesName().get(0));
Packager.zipFile(out, name + "/imageColor.tif", outputfile);
outputfile.delete();
out.closeEntry();
......@@ -1385,7 +1389,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
this.colored = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// <<<< TRANSPARENCE
StreamedImageReaderWrapper wrapper = new StreamedImageReaderWrapper(imgData.getDataFilesName().get(0));
// StreamedImageReaderWrapper wrapper = new StreamedImageReaderWrapper(imgData.getDataFilesName().get(0));
// >>>> TRANSPARENCE
int current = 0;
for (int i = 0; i < width * height; i++) {
......@@ -1399,61 +1403,65 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
if (x >= 0 && x < w && y >= 0 && y < h) {
Cluster c = this.classification.getClusteringResult().getCluster(map[current]);
if (c != null) {
if (c.isVisible()) // cluster's color
{
if (c.isVisible()) {// cluster's color
// <<<< TRANSPARENCE
if (getOpacityCluster() == 1.0) {
// if (getOpacityCluster() == 1.0) {
// >>>> TRANSPARENCE
couleur = c.getColor().getRGB();
} else {
// couleur = Color.black.getRGB();
} else {
// << TO COMMENT IF TRANSPARENCE IS USED
couleur = Color.black.getRGB();
// >> TO COMMENT IF TRANSPARENCE IS USED
// <<<< TRANSPARENCE
try
{
int r = (int)wrapper.getPixel(x, y)[0];
int g = (int)wrapper.getPixel(x, y)[1];
int b = (int)wrapper.getPixel(x, y)[2];
Color couleurFont = new Color(r, g, b);
couleurFont = blend(Color.black, couleurFont, getOpacity());
couleur = blend(couleurFont, c.getColor(), getOpacityCluster()).getRGB();
}
catch (FormatException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
else // font image's color
{
try
{
int r = (int)wrapper.getPixel(x, y)[0];
int g = (int)wrapper.getPixel(x, y)[1];
int b = (int)wrapper.getPixel(x, y)[2];
Color couleurFont = new Color(r, g, b);
couleur = blend(Color.black, couleurFont, getOpacity()).getRGB();
}
catch (FormatException e)
{
e.printStackTrace();
}