Commit b6a7bf3f authored by lafabregue's avatar lafabregue

finished pyramid iamge implementation

parent 0f66b211
......@@ -123,7 +123,7 @@ public class MainFrame extends JFrame {
private JPanel infosPanel;
/** boolean pour lier le birdview avec l'image active */
private boolean lierBirdView = false;
private boolean linkToAllImages = false;
/** the project root for datas */
private DefaultMutableTreeNode mDataProjectNode;
......@@ -1310,8 +1310,8 @@ public class MainFrame extends JFrame {
menuBrightM.setEnabled(this.actionBrightM);
menuContrastP.setEnabled(this.actionContratsP);
menuContrastM.setEnabled(this.actionContrastM);
menuConnectActiv.setEnabled(!this.isLierBirdView());
menuConnectAll.setEnabled(this.isLierBirdView());
menuConnectActiv.setEnabled(!this.isLinkToAllBirdView());
menuConnectAll.setEnabled(this.isLinkToAllBirdView());
menuResetAll.setEnabled(this.actionResetAll);
menuChooseRgb.setEnabled(this.actionChooseRgb);
menuRefresh.setEnabled(this.actionRefresh);
......@@ -1480,7 +1480,7 @@ public class MainFrame extends JFrame {
// =============== Creation of the Desktop ================
JPanel panel_desktop = new JPanel(new BorderLayout());
panel_desktop.setOpaque(false);
panel_desktop.setBorder(Borders.DIALOG);
panel_desktop.setBorder(Borders.DIALOG_BORDER);
panel_desktop.add(this.desktop);
sif_desktop = new SimpleInternalFrame(Messages.getString("MainFrame.72")); //$NON-NLS-1$
......@@ -1494,7 +1494,7 @@ public class MainFrame extends JFrame {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(Borders.DIALOG);
panel.setBorder(Borders.DIALOG_BORDER);
panel.add(pane);
// =============== Creation of the Progress Panel => South
......@@ -1530,36 +1530,6 @@ public class MainFrame extends JFrame {
this.birdPanel.requestFocus();
}
//TODO to remove
// method for resizing an image while keeping aspect ratio
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int frameWidth, int frameHeight) {
double height = originalImage.getHeight();
double width = originalImage.getWidth();
int newWidth, newHeight;
// if image size smaller than window size, do not resize
if (height < frameHeight && width < frameWidth) {
newWidth = (int) width;
newHeight = (int) height;
}
// else resize
else {
double scaleX = (frameWidth / width);
double scaleY = (frameHeight / height);
double scale = Math.min(scaleX, scaleY);
newWidth = (int) (width * scale);
newHeight = (int) (height * scale);
}
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
return resizedImage;
}
// 20120309_MBH-Test-Fin
/**
......@@ -1647,7 +1617,7 @@ public class MainFrame extends JFrame {
// =============== Creation of the Desktop ================
JPanel panel_desktop = new JPanel(new BorderLayout());
panel_desktop.setOpaque(false);
panel_desktop.setBorder(Borders.DIALOG);
panel_desktop.setBorder(Borders.DIALOG_BORDER);
panel_desktop.add(this.desktop);
sif_desktop = new SimpleInternalFrame(Messages.getString("MainFrame.72")); //$NON-NLS-1$
......@@ -1661,7 +1631,7 @@ public class MainFrame extends JFrame {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(Borders.DIALOG);
panel.setBorder(Borders.DIALOG_BORDER);
panel.add(pane);
// =============== Creation of the Progress Panel => South
......@@ -2494,8 +2464,8 @@ public class MainFrame extends JFrame {
return mDataTreeModel;
}
public boolean isLierBirdView() {
return lierBirdView;
public boolean isLinkToAllBirdView() {
return linkToAllImages;
}
/**
......@@ -3461,7 +3431,7 @@ public class MainFrame extends JFrame {
}
public void setLierBirdView(boolean lierBirdView) {
this.lierBirdView = lierBirdView;
this.linkToAllImages = lierBirdView;
setEnabledMenu();
}
//
......
......@@ -29,7 +29,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.io.LineNumberReader;
import java.util.List;
......@@ -38,11 +37,9 @@ import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
......@@ -67,11 +64,11 @@ import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.gui.ProgressPropertyChangeListener;
import mustic.gui.tools.ZoomBoxPanel;
import mustic.gui.tools.Zoomable;
import mustic.io.RawImage;
import mustic.utils.filters.CSVFileFilter;
import mustic.utils.io.CSVUtils;
import mustic.utils.image.ImageViewer;
import mustic.utils.image.PyramidImageViewer;
import mustic.utils.image.ZoomBoxPanel;
import mustic.utils.image.Zoomable;
/**
* Dialog window that allows the user to generate a set of constraints
......@@ -101,6 +98,9 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
/** Image displayed */
private BufferedImage mNew = null;
/** Image viewer that handle image read operations */
private ImageViewer viewer = null;
/** Panel that contains the displayed image */
private JPanel displayPanel = null;
......@@ -357,7 +357,7 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
initializeConstraintsColors();
otherComponentList.add(constraintsColorChooser);
JCheckBox zoomBoxChkBox = new JCheckBox(Messages.getString("ConstraintsSelectionDialog.58"));
final JCheckBox zoomBoxChkBox = new JCheckBox(Messages.getString("ConstraintsSelectionDialog.58"));
// key listener for the keyJCheckBox
this.displayPanel.addKeyListener(new KeyListener() {
......@@ -503,97 +503,8 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
return this.data;
}
void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(line.size()-1))) {
case Constraint.MUST_LINK_TYPE :
try {
createMustLinkConstraint();
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
constraints.add(new MustLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.CANNOT_LINK_TYPE :
try {
int index1 = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
int index2 = getIndex(Integer.parseInt(line.get(1)), isImageRelated);
createCannotLinkConstraint();
constraints.add(new CannotLinkConstraint(index1, index2));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index1);
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(3)).setText(""+index2);
} catch(Exception e) {
e.printStackTrace();
}
break;
case Constraint.LABEL_TYPE :
try {
int index = getIndex(Integer.parseInt(line.get(0)), isImageRelated);
createLabelConstraint();
constraints.add(new LabelConstraint(index,
Integer.parseInt(line.get(2))));
currentStep = -1;
// we update text fields
((JTextField) constraintsPanels.get(constraintsPanels.size()-1)
.getComponent(1)).setText(""+index);
} catch(Exception e) {
e.printStackTrace();
}
break;
private boolean openFile(File file) {
System.out.println(
"__________________________________________________________________________________________\n"); //$NON-NLS-1$
System.out.println("Opening file : " + file.getPath()); //$NON-NLS-1$
System.out
.println("__________________________________________________________________________________________"); //$NON-NLS-1$
boolean isImageRelated = true;
if (data != null) {
// choose between image or data indexes
String[] possibilities = { Messages.getString("ConstraintsSelectionDialog.521"),
Messages.getString("ConstraintsSelectionDialog.522") };
String s = (String) JOptionPane.showInputDialog(this, Messages.getString("ConstraintsSelectionDialog.524"),
Messages.getString("ConstraintsSelectionDialog.523"), JOptionPane.PLAIN_MESSAGE, null,
possibilities, Messages.getString("ConstraintsSelectionDialog.522"));
// if data is selected
if (s.equals(Messages.getString("ConstraintsSelectionDialog.522"))) {
isImageRelated = false;
}
}
CSVUtils reader = null;
try {
reader = new CSVUtils(file);
clear();
List<String> line;
while ((line = reader.readNext()) != null) {
addConstraint(line, isImageRelated);
}
enableAllComponents();
displayPixels();
updateUI();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
return true;
}
private void addConstraint(List<String> line, boolean isImageRelated) {
protected void addConstraint(List<String> line, boolean isImageRelated) {
switch (Integer.parseInt(line.get(line.size() - 1))) {
case Constraint.MUST_LINK_TYPE:
try {
......@@ -899,85 +810,84 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
if (img == null) {
return;
}
if (this.image != null && !this.image.getPath().equals(img.getPath()))
this.clear();
this.width = img.getWidth();
this.imageSource = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
this.imagePoints = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
double data[][][] = img.load(0, 0, img.getWidth(), img.getHeight());
double[] max = new double[data.length];
double[] min = new double[data.length];
// for each band
for (int i = 0; i < data.length; i++) {
max[i] = min[i] = data[i][0][0];
// for each column
for (int x = 0; x < data[i].length; x++) {
// for each line
for (int y = 0; y < data[i][x].length; y++) {
// searching the max and min value of the band
max[i] = Math.max(max[i], data[i][x][y]);
min[i] = Math.min(min[i], data[i][x][y]);
}
}
}
short[][][] dataView = new short[data.length][data[0]
.length][data[0][0].length]; // the values to display
double values[][] = data[0];
/*
* max contains the max value for r g b, we can create a valid
* representation of data. the data values must be between 0 and 255 to
* be valid, so let's convert them if needed
*/
int[] bands = new int[3];
bands[0] = img.r;
bands[1] = img.g;
bands[2] = img.b;
// we use at most 3 bands
int nbUsedBand = img.getNbBands();
if (nbUsedBand > 3) {
nbUsedBand = 3;
}
for (int b = 0; b < nbUsedBand; b++) {
int i = bands[b];
for (int x = 0; x < data[0].length; x++) {
for (int y = 0; y < data[0][0].length; y++) {
if (data[i][x][y] > 0) {
// convert only if needed to avoid color deformation on
// 8 bits images
if (max[i] <= 255 && min[b] >= 0) {
dataView[i][x][y] = (short) data[b][x][y];
} else {
dataView[i][x][y] = (short) (255 *
(data[i][x][y] - min[b]) / (max[b] - min[b]));
}
} else {
dataView[i][x][y] = 0;
}
}
}
}
// pixels of the image to display
for (int x = 0; x < values.length; x++) {
for (int y = 0; y < values[0].length; y++) {
int pixel = (int) values[x][y] << 24 | dataView[bands[0]][x][y] << 16
| dataView[bands[1]][x][y] << 8 | dataView[bands[2]][x][y];
imageSource.setRGB(x, y, pixel);
imagePoints.setRGB(x, y, pixel);
}
}
this.viewer = new PyramidImageViewer(img.getFilename(), true);
// if (this.image != null && !this.image.getPath().equals(img.getPath()))
// this.clear();
// this.width = img.getWidth();
// this.imageSource = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
// this.imagePoints = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
//
// double data[][][] = img.load(0, 0, img.getWidth(), img.getHeight());
// double[] max = new double[data.length];
// double[] min = new double[data.length];
//
// // for each band
// for (int i = 0; i < data.length; i++) {
// max[i] = min[i] = data[i][0][0];
// // for each column
// for (int x = 0; x < data[i].length; x++) {
// // for each line
// for (int y = 0; y < data[i][x].length; y++) {
// // searching the max and min value of the band
// max[i] = Math.max(max[i], data[i][x][y]);
// min[i] = Math.min(min[i], data[i][x][y]);
// }
// }
// }
// short[][][] dataView = new short[data.length][data[0]
// .length][data[0][0].length]; // the values to display
// double values[][] = data[0];
// /*
// * max contains the max value for r g b, we can create a valid
// * representation of data. the data values must be between 0 and 255 to
// * be valid, so let's convert them if needed
// */
//
// int[] bands = new int[3];
// bands[0] = img.r;
// bands[1] = img.g;
// bands[2] = img.b;
//
// // we use at most 3 bands
// int nbUsedBand = img.getNbBands();
// if (nbUsedBand > 3) {
// nbUsedBand = 3;
// }
// for (int b = 0; b < nbUsedBand; b++) {
// int i = bands[b];
// for (int x = 0; x < data[0].length; x++) {
// for (int y = 0; y < data[0][0].length; y++) {
// if (data[i][x][y] > 0) {
// // convert only if needed to avoid color deformation on
// // 8 bits images
// if (max[i] <= 255 && min[b] >= 0) {
// dataView[i][x][y] = (short) data[b][x][y];
// } else {
// dataView[i][x][y] = (short) (255 *
// (data[i][x][y] - min[b]) / (max[b] - min[b]));
// }
// } else {
// dataView[i][x][y] = 0;
// }
// }
// }
// }
// // pixels of the image to display
// for (int x = 0; x < values.length; x++) {
// for (int y = 0; y < values[0].length; y++) {
//
// int pixel = (int) values[x][y] << 24 | dataView[bands[0]][x][y] << 16
// | dataView[bands[1]][x][y] << 8 | dataView[bands[2]][x][y];
//
// imageSource.setRGB(x, y, pixel);
// imagePoints.setRGB(x, y, pixel);
// }
// }
this.image = img;
// TODO : Solve conflict
// <<
displayPixels();
// doZoomedOp();
//>>
doZoomedOp();
}
protected void addSecondPixel(int x, int y) {
......@@ -1383,25 +1293,13 @@ public class ConstraintsSelectionDialog extends JInternalFrame implements Zoomab
// coordinates in original image
int xo = (int) (x/mZoomRate);
int yo = (int) (y/mZoomRate);
int widthOrigin = (int) (width/mZoomRate);
int heightOrigin= (int) (height/mZoomRate);
// int widthOrigin = (int) (width/mZoomRate);
// int heightOrigin= (int) (height/mZoomRate);
float zoomOrigin = zoom*mZoomRate ;
int widthSubImage=widthOrigin;
int heightSubImage=heightOrigin;
// manage integer precision rounding problem
if(widthSubImage + xo > this.getOriginalImage().getWidth()) {
widthSubImage=this.getOriginalImage().getWidth() - xo;
}
if(heightSubImage + yo > this.getOriginalImage().getHeight()) {
heightSubImage=this.getOriginalImage().getHeight() - yo;
}
BufferedImage subImage = this.getOriginalImage().getSubimage(xo, yo, widthSubImage, heightSubImage);
return subImage.getScaledInstance((int) (widthSubImage * zoomOrigin), (int) (heightSubImage * zoomOrigin ), Image.SCALE_SMOOTH);
BufferedImage subImage = viewer.getScreenImage(xo, yo, width, height, zoomOrigin, false);
return subImage;
}
public BufferedImage getOriginalImage() {
......
package mustic.gui.dialog.classifier;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.io.LineNumberReader;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.clustering.constraints.CannotLinkConstraint;
import jcl.clustering.constraints.ClusterDiameterConstraint;
import jcl.clustering.constraints.Constraint;
import jcl.clustering.constraints.LabelConstraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.utils.Images.StreamedImageReaderWrapper;
import mustic.gui.panels.ImagePanel;
import mustic.io.RawImage;
import mustic.utils.image.ImageViewer;
import mustic.utils.image.PyramidImageViewer;
import mustic.utils.image.ZoomBoxPanel;
import mustic.utils.image.Zoomable;
/**
* Dialog window that allows the user to generate a set of constraints on an imagePanel
*
* @author Baptiste LAFABREGUE
*
*/
public class ConstraintsSelectionInternalFrame extends JDialog {
private static final long serialVersionUID = 1L;
ImportConstraintsTask importConstraintsTask = null;
/** data related fields */
private int width = -1;
private double minDistance = 0;
private double maxDistance = 100;
private Data data = null;
/** Panel that contains the displayed image */
private ImagePanel imagePanel = null;
public JPanel mainPanel;
protected int labelClassesCount = 1;
/** inner panel of task groups per constraint types */
private JPanel mustLinkContainer = new JPanel();
private JPanel cannotLinkContainer = new JPanel();
private JPanel labelContainer = new JPanel();
private JPanel panelImage = new JPanel(new BorderLayout());
/** set of created constraints */
private Vector<Constraint> constraints = new Vector<Constraint>();
/** panels linked to each constraints */
private Vector<JPanel> constraintsPanels = new Vector<JPanel>();
/** other components that must be disable or enabled */
private Vector<Component> otherComponentList = new Vector<Component>();
/** Cluster related components */
private JCheckBox nbClusterCheckBox;
private JTextField nbClusterMaxTextField;
private JTextField nbClusterMinTextField;
private JCheckBox clusterDiameterCheckBox;
private JTextField diameterTextField;
/** Record steps of constraint construction */
private int currentStep = 0;
/* steps types */
static final private int MustLink_step1 = 1;
static final private int MustLink_step2 = 2;
static final private int CannotLink_step1 = 3;
static final private int CannotLink_step2 = 4;
static final private int Label_step1 = 5;
private int previousIndex = -1;
/**
* Colors and buttons linked to Must Link, Cannot Link and Label constraints
**/
/** Hide/Display constraints related components */
private JCheckBox check;
/** Dialog for choosing colors for the constraints*/
private JDialog jd_colorsChooser;
/** constraints colors */
private Color mustLinkColor = new Color(124, 252, 0);
private Color cannotLinkColor = new Color(255, 0, 255);
private Vector<Color> labelConstraintColor = new Vector<Color>();
/** Images and constraints zoom */
/** Constraint images related components */
private File inputImage = new File(getClass().getResource("/icons/icon-pince.png").getFile());
private BufferedImage imagePixel = null;
private BufferedImage imagePixelML = null;
private BufferedImage imagePixelCL = null;
private Vector<BufferedImage> imageLabelPixel = new Vector<BufferedImage>();
private int classID;
private JPanel container;
/**
* Constructor to a dialog window to visualize and build a set of
* constraints
*
* @param img
* the image on which the constraints have to be build
* @param data
* (optional) the data related to the constraints
*/
public ConstraintsSelectionInternalFrame(ImagePanel imagePanel, Data data) {
super();
mainPanel = new JPanel(new BorderLayout());
if (data != null) {
// case of Data provided
minDistance = data.getEstimatedMinDistance();
maxDistance = data.getEstimatedMaxDistance();
this.data = data;
} else {
// otherwise we base our estimation on the image
StreamedImageReaderWrapper reader = new StreamedImageReaderWrapper(imagePanel.getRawImage().getPath());
minDistance = 0;
maxDistance = 0;
for (int i = 0 ; i < reader.getMaxValues().length ; i++) {
double d = (reader.getMaxValues()[i] - reader.getMinValues()[i]);
maxDistance += d*d;
}
maxDistance = Math.sqrt(maxDistance);
}
addListeners();
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("ConstraintsSelectionDialog.50")); //$NON-NLS-1$
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ConstraintsSelectionInternalFrame.this.data != null) {
ConstraintsSelectionInternalFrame.this.data.updateAndSetConstraintsToSample(getConstraints());
}
ConstraintsSelectionInternalFrame.this.dispose();
}
});
panelButton.add(buttonOk);
otherComponentList.add(buttonOk);
JButton buttonCancel = new JButton(Messages.getString("ConstraintsSelectionDialog.55")); //$NON-NLS-1$
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ConstraintsSelectionInternalFrame.this.dispose();
}
});
panelButton.add(buttonCancel);
otherComponentList.add(buttonCancel);
JButton importButton = new JButton(Messages.getString("ConstraintsSelectionDialog.51")); //$NON-NLS-1$
importButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
importConstraints();
}
});