Commit b6a7bf3f authored by lafabregue's avatar lafabregue
Browse files

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() {
......
......@@ -288,29 +288,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
@Override
public void mouseClicked(MouseEvent e) {
// Test if an image is loaded
if (!session.isDisplayEnable() || this.mImage == null) {
return;
}
// Test if the mouse is over the image
if (e.getPoint().x >= this.mBirdImage.getWidth()
|| e.getPoint().y >= this.mBirdImage.getHeight()) {
return;
}
// Zoom factor of the image
double xfact = (double) this.mImage.getWidth()
/ (double) this.mBirdImage.getWidth();
double yfact = (double) this.mImage.getHeight()
/ (double) this.mBirdImage.getHeight();
double x = e.getX() * xfact;
double y = e.getY() * yfact;
this.mInfoPanel.setPixel((int) (x), (int) (y));
repaint();
}
/**
......@@ -631,7 +609,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
this.repaint();
this.action = BirdViewPanel.ACT_NONE;
if (!MainFrame.getInstance().isLierBirdView()) {
if (!MainFrame.getInstance().isLinkToAllBirdView()) {
ImageDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop()
.getAllImageDesktopFrames();
int nbSessions = desktopFrames.length;
......@@ -653,28 +631,13 @@ public class BirdViewPanel extends JPanel implements MouseListener,
.getBirdViewPanel().rysave);
}
} else {
if (MainFrame.getInstance().getDesktop().getActiveFrame() instanceof ImageDesktopFrame) {
syncImage(((ImageDesktopFrame) MainFrame.getInstance().getDesktop().getActiveFrame())
.getImageSession());
((ImageDesktopFrame) MainFrame
.getInstance()
.getDesktop()
.getActiveFrame())
.getImageSession()
.getImagePanel()
.reloadPoint(
((ImageDesktopFrame) MainFrame.getInstance().getDesktop()
.getActiveFrame()).getImageSession()
.getBirdViewPanel().xxsave,
((ImageDesktopFrame) MainFrame.getInstance().getDesktop()
.getActiveFrame()).getImageSession()
.getBirdViewPanel().yysave,
((ImageDesktopFrame) MainFrame.getInstance().getDesktop()
.getActiveFrame()).getImageSession()
.getBirdViewPanel().rxsave,
((ImageDesktopFrame) MainFrame.getInstance().getDesktop()
.getActiveFrame()).getImageSession()
.getBirdViewPanel().rysave);
if (session != null) {
syncImage(session);
session.getImagePanel().reloadPoint(
session.getBirdViewPanel().xxsave,
session.getBirdViewPanel().yysave,
session.getBirdViewPanel().rxsave,
session.getBirdViewPanel().rysave);
}
}
......
......@@ -406,11 +406,13 @@ public class ImageInformationPanel extends JPanel {
* </p>
*
* @param x
* the x position of the pixel
* the x position of the pixel
* @param y
* the y position of the pixel
* the y position of the pixel
* @param value
* the pixel value
*/
public void setPixel(int x, int y) {
public void setPixel(int x, int y, double value[]) {
this.mPixel.setText("Pixel: " + (x + 1) + " - " + (y + 1));
try {
double posGeo[] = this.mImage.getLatLon(x, y);
......@@ -425,19 +427,12 @@ public class ImageInformationPanel extends JPanel {
this.mPixelGeo.setText("Lat: " + myFormatter.format(xgeo)
+ " Lon: " + myFormatter.format(ygeo));
} catch (Exception ex) {
if(MainFrame.DEBUG_MODE)
ex.printStackTrace();
// if(MainFrame.DEBUG_MODE)
// ex.printStackTrace();
this.mPixelGeo.setText("no georeferencing");
}
double data[][][] = this.mImage.load(x, y, 1, 1);
double realdata[] = new double[data.length];
for (int i = 0; i < data.length; i++)
realdata[i] = data[i][0][0];
setPixelVal(this.mImage.getWavelength(), realdata);
setPixelVal(this.mImage.getWavelength(), value);
}
/**
......
This diff is collapsed.
......@@ -19,11 +19,8 @@ import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.mask.Mask;
import jcl.evaluation.clustering.ResultsComparison;
import jcl.learning.*;
import jcl.learning.methods.monostrategy.SingleClassification;
......@@ -643,7 +640,7 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
}