Skip to content
73 changes: 64 additions & 9 deletions src/Couleur.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,76 @@

public class Couleur {
private int[] RVB= {0,0,0};
public Couleur(int R, int V, int B)
int R,G,B;
int N=1;
// N repr�sente de combien de Couleurs est issue celle ci,
//pour pouvoir faire des moyennes sans consommer trop de m�moire
public Couleur(int Red, int Green, int Blue)
{
this.RVB[0]=R;
this.RVB[1]=V;
this.RVB[2]=B;
R=Red;
G=Green;
B=Blue;
}
public Couleur(int[] RVB)
{
// deuxi�me constructeur pour faciliter la vie
R=RVB[0];
G=RVB[1];
B=RVB[2];
}

public void initN(int n)
{
N=n;
}
public int getR()
{
return this.RVB[0];
return R;
}
public int getV()
public int getG()
{
return this.RVB[1];
return G;
}
public int getB()
{
return this.RVB[2];
return B;
}
public int getN()
{
return N;
}
public int[] getRVB()
{
int[] a= {R,G,B};
return a;
}

public int distance(Couleur C)
{
//calcule la distance au carr� entre 2 Couleurs, sur les 3 axes
int A=(R-C.getR())*(R-C.getR());
A+=(G-C.getG())*(G-C.getG());
A+=(B-C.getB())*(B-C.getB());
return A;
}

public void printcoul()
{
System.out.printf(" %d , %d , %d \n",R, G, B);
}

public Couleur moyenne(Couleur C)
{
int[] A=new int[3];
A[0]=(R*N + C.getR()*C.getN())/(N+C.getN());
A[1]=(G*N + C.getG()*C.getN())/(N+C.getN());
A[2]=(B*N + C.getB()*C.getN())/(N+C.getN());
Couleur Retour=new Couleur(A);
Retour.initN(N+C.getN());
return Retour;
}
public boolean egal(Couleur C)
{
return(R==C.getR() && G==C.getG() && B==C.getB());
}

}
5 changes: 4 additions & 1 deletion src/DisplayedImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ public void RefreshImage(BufferedImage newimg){
public void paintComponent(Graphics g){
//g.drawImage(image, 0, 0, this); // draw as much as possible
g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this); // draw full image
}
}
public BufferedImage getImage() {
return image;
}
}
121 changes: 109 additions & 12 deletions src/ImageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;

import java.awt.Image;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand All @@ -24,11 +25,14 @@ public class ImageViewer extends JFrame /*implements ActionListener*/
private JButton buttonHisto = new JButton("Histogramme");
private JButton buttonQuant = new JButton("Quantification");


private JButton buttonInverse = new JButton("Inverse");

private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenuItem itemSave = new JMenuItem("Save");

private JMenuItem itemCharge = new JMenuItem("Charger une image");


private JMenuItem itemClose = new JMenuItem("Close");

Expand All @@ -44,6 +48,12 @@ public ImageViewer () {
JPanel inverse = new JPanel();
inverse.setLayout(new BoxLayout(inverse, BoxLayout.PAGE_AXIS));
inverse.add(buttonInverse);

JPanel charger = new JPanel();
charger.setLayout(new BoxLayout(charger, BoxLayout.PAGE_AXIS));
charger.add(itemCharge);
// Defines action associated to buttons
itemCharge.addActionListener(new ButtonCharger());
// Defines action associated to buttons

buttonAction.addActionListener(new ButtonListener());
Expand All @@ -58,8 +68,10 @@ public ImageViewer () {
quant.setLayout(new BoxLayout(quant, BoxLayout.PAGE_AXIS));
quant.add(buttonQuant);
// Defines action associated to buttons
buttonQuant.addActionListener(new Quant());


// ########## CLASS QUANT ##########
buttonQuant.addActionListener(new Quanti());
// ############## FIN CLASS QUANT #############
buttonInverse.addActionListener(new ButtonListener(){
public void actionPerformed(ActionEvent arg0) {
BufferedImage Invimage;
Expand Down Expand Up @@ -94,7 +106,6 @@ public void actionPerformed(ActionEvent arg0) {
global.setLayout(new BoxLayout(global, BoxLayout.LINE_AXIS));
global.add(input);

global.add(action);
global.add(quant);
global.add(histo);

Expand All @@ -111,11 +122,13 @@ public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
this.fileMenu.add(itemClose);
this.fileMenu.add(itemClose);
this.fileMenu.add(itemCharge);

this.menuBar.add(fileMenu);
this.setJMenuBar(menuBar);

itemSave.addActionListener(new ButtonListener2());
this.fileMenu.add(itemSave);
this.setVisible(true);


Expand All @@ -124,18 +137,102 @@ public void actionPerformed(ActionEvent arg0) {
/**
* Class listening to a given button
*/
class ButtonListener2 implements ActionListener{
public void actionPerformed(ActionEvent arg0)
{
final JFileChooser fc=new JFileChooser();
fc.setMultiSelectionEnabled(true);
int returnVal = fc.showSaveDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
File saved = fc.getSelectedFile();
try {
ImageIO.write(ouputImage.getImage(),"png",saved);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class ButtonCharger implements ActionListener{
public JTextField status = new JTextField("pas de fichier charg�");
public JFileChooser choose = new JFileChooser();
private BufferedImage image = inputImage.getimage();

public void actionPerformed(ActionEvent evt){ //ouvrir une boite de dialogue pour choisir un fichier
choose.setApproveButtonText("Charger un fichier");
choose.showOpenDialog(null);
if (choose.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){
status.setText(choose.getSelectedFile().getAbsolutePath());
System.out.println(status.getText());

try{
image = ImageIO.read(new File(status.getText()));
}
catch (IOException e) {
e.printStackTrace();
}


}
inputImage.RefreshImage(image);
ouputImage.RefreshImage(image);

}


}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent arg0)
{
}

class HistoListener implements ActionListener{
}
class Quanti implements ActionListener{
public void actionPerformed(ActionEvent arg0)
{
System.out.println("Histogramme créé");
BufferedImage ima = null;
try {
ima = ImageIO.read(new File("img.png"));
} catch (IOException e) {

e.printStackTrace();
}
System.out.println("Matrice import�e");
int h;
int w;
w= ima.getWidth();
h= ima.getHeight();
int[][][] image = new int[w][h][3];
System.out.println("L x H :"+w +" "+ h);
//r�cup�ration des couleurs, mises dans le tableau image
int i,j,A;
for( j=0 ; j<h; j+=1)
{
for(i=0; i<w ; i+=1)
{
A = ima.getRGB( i, j );
image[i][j][0]=(byte)(A >>> 16)&0xFF;
image[i][j][1]=(byte)(A >>> 8)&0xFF;
image[i][j][2]=(byte)(A >>> 0)&0xFF;
}
}
Traitement PAL = new Traitement(image, w,h);
int[][][] image_finale= PAL.returnImage();
BufferedImage Invimage;
Invimage = ouputImage.getimage();

int x,y;
for(x=0;x<w;x++){
for(y=0; y<h;y++){
Color newclr= new Color(image_finale[x][y][0],image_finale[x][y][1], image_finale[x][y][2]);
Invimage.setRGB(x, y, newclr.getRGB());
ouputImage.RefreshImage(Invimage);
}
}
}

}

}
}
}

Loading