Histogramme d'une image en java

Fermé
neo black - 23 janv. 2010 à 10:05
 asma24 - 27 avril 2012 à 13:52
Bonjour,
voila j'ai un traivail a faire je doit afficher un histogramme d'une image en java
j'ai une recherche sur presque tout ls document existant sur l'internet et jusqu'a maintement je n'ai reussie a le programmer alors si quelqu'un sais comment le faire (afficher le histogramme d'une images en java) ils me contacte et toute aides sera le bien venue
A voir également:

3 réponses

bjr, normalement cette classe calcul l'histo d'une image couleur essayé avec ..moi j'ai un probleme je veu calculer l'histogramme mais eske il existe une fonction prédifini en java fait ça ou nn, et bon courage
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Menu;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;


public class Histo extends Frame implements ActionListener {

BufferedImage bufferdImage, buffeurActuel,buffeur;

Menu menu;
FileDialog dialog;
int []imageSeuil;
int [] pixelsCourant,pixelsAncien,pixelsNouveau;
Panel panneau;
int largeur,hauteur;
int [] tab = new int[256];
int [] tab1 = new int[256];
int [] tab2 = new int[256];
int [] tab3 = new int[256];
int [] pixels;
Button butom1,butom2,butom3;
Panel p;
Panel p1;
Panel panel1=new Panel();
Panel panel2=new Panel();
DrawHist ZoneDessin;
DrawImage ZoneImage;
Histogramme ZoneDessin2;
private void FormeFenetre(){
dialog = new FileDialog(this,"File Dialog");
setSize(500,500);

}

public Histo (int larg,int haut,int []pixel,BufferedImage buffeur){
pixelsCourant=pixel;
this.pixels=pixel;
largeur=larg;
hauteur=haut;
this.buffeur=buffeur;
FormeFenetre();
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();}
});

setLayout (new BorderLayout ());
Histogramme ZoneDessin2 =new Histogramme(largeur,hauteur,pixelsCourant);
tab1= ZoneDessin2.getHisR();
tab2= ZoneDessin2.getHisV();
tab3= ZoneDessin2.getHisB();
affiche();


}
private void affiche(){
ZoneImage = new DrawImage (buffeur);
ZoneDessin= new DrawHist (tab1);
add("Center",ZoneImage);
p=new Panel();
p.setBackground(new Color(200,200,200));
p.setLayout(new BorderLayout());
Label s=new Label(" *** Histogramme de l'image *** ");
p.add("North",s);
p.add("Center",ZoneDessin);
p1=new Panel();
p1.setLayout(new GridLayout());
butom1= new Button("Rouge");
butom1.addActionListener(this);
butom2= new Button("Vert");
butom2.addActionListener(this);
butom3= new Button("Bleu");
butom3.addActionListener(this);
p1.add("East",butom1);
p1.add("Center",butom2);
p1.add("West",butom3);
p.add("South",p1);
//p.remove(ZoneDessin);
Label titre=new Label(" ----- Caractéristiques Générales de l'Image ------");
add("North", titre);
add("East",p);
setTitle("Generalite");
setResizable(false);
this.setLocation(largeur+100,1);
show();
}

public void actionPerformed(ActionEvent event) {

if (event.getSource()==butom1) {
ZoneDessin.affect(1,tab1);
String valeur=new String();
}

if (event.getSource()==butom2 ) {
ZoneDessin.affect(2,tab2);
String valeur=new String();
}

if ( event.getSource()==butom3) {
ZoneDessin.affect(3,tab3);
String valeur=new String();

}
}

}
1
pour calculer ls histogramme je peu t'aider j'ai coder un algo le voiçi



import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class Histogramme {
private int [] HR=new int[256];
private int [] HG=new int[256];
private int [] HB=new int [256];
private int [] CR=new int [256];
private File file;
private BufferedImage img;
public int[] getHR() {
return HR;
}

public void setHR(int[] hr) {
HR = hr;
}

public int[] getHG() {
return HG;
}

public void setHG(int[] hg) {
HG = hg;
}

public int[] getHB() {
return HB;
}

public void setHB(int[] hb) {
HB = hb;
}

private int [] CG=new int [256];
private int [] CB=new int [256];
private double [] NR=new double[256];
private double [] NG=new double[256];
private double [] NB=new double[256];
private int width,height,red,green,bleu,Rred,Rgreen,Rbleu;
private int[]MatriceImage;
private void getRGB (int x, int y) {

int pixel = MatriceImage[y*width+x];
setRed((pixel >> 16) & 0xFF);
setGreen((pixel >> 8) & 0xFF);
setBleu((pixel ) & 0xFF);
}

public void CalculerHistogramme(int [] pixel)
{

for(int i=0;i<255;i++)
{
HR[i]=0;
HG[i]=0;
HB[i]=0;
}

for (int i=0; i<width; i++)
for (int j=0; j<height; j++)
{
getRGB(i,j);
HR[getRed()]=HR[getRed()]+1;
HG[getGreen()]=HG[getGreen()]+1;
HB[getBleu()]=HB[getBleu()]+1;

}
setHR(HR);
setHG(HG);
setHB(HB);


}
public BufferedImage GetBuffered(File f)
{

try {
img = ImageIO.read(f);
} catch (IOException e)
{
e.printStackTrace();
}
return img;

}
public int[] DataPixel(BufferedImage image)
{

width = image.getWidth();
height = image.getHeight();
MatriceImage = new int[width*height];
for (int i=0; i<width; i++)
for (int j=0; j<height; j++)
{
MatriceImage[j*width+i] = img.getRGB(i,j);
}
return MatriceImage;
}

public void CaclulerCumule()
{

CalculerHistogramme(DataPixel(GetBuffered(file)));
CR[0]=getHR()[0];
CG[0]=getHG()[0];
CB[0]=getHB()[0];
for(int i=1;i<256;i++)
{
CR[i]=CR[i-1]+HR[i];
CG[i]=CG[i-1]+HG[i];
CB[i]=CB[i-1]+HB[i];
}

setCR(CR);
setCG(CG);
setCB(CB);
}
public int[] getCR() {
return CR;
}

public void setCR(int[] cr) {
CR = cr;
}

public int[] getCG() {
return CG;
}

public void setCG(int[] cg) {
CG = cg;
}

public int[] getCB() {
return CB;
}

public void setCB(int[] cb) {
CB = cb;
}

public void ClaculerNormalise()
{

CalculerHistogramme(DataPixel(GetBuffered(file)));
double val=100/(width*height);
for(int i=0;i<256;i++)
{
NR[i]=(getHR()[i])*val;
NG[i]=(getHG()[i])*val;
NB[i]=(getHB()[i])*val;

}
setNR(NR);
setNG(NG);
setNB(NB);

}
public double[] getNR() {
return NR;
}

public void setNR(double[] nr) {
NR = nr;
}

public double[] getNG() {
return NG;
}

public void setNG(double[] ng) {
NG = ng;
}

public double[] getNB() {
return NB;
}

public void setNB(double[] nb) {
NB = nb;
}

public int getRed() {
return red;
}

public void setRed(int red) {
this.red = red;
}

public int getGreen() {
return green;
}

public void setGreen(int green) {
this.green = green;
}

public int getBleu() {
return bleu;
}

public void setBleu(int bleu) {
this.bleu = bleu;
}

}

essay pour + de question n'hisiter pas
0
monsieur neo merci pour votre programme mais je veux voir l'affichage
ton code ne contien pas le main pour executer
si tu peux la mettre j serai contente
0