Filtre noir et blanc

najah01_3 Messages postés 35 Date d'inscription dimanche 24 septembre 2006 Statut Membre Dernière intervention 17 juillet 2007 - 3 juin 2007 à 05:18
najah01_3 Messages postés 35 Date d'inscription dimanche 24 septembre 2006 Statut Membre Dernière intervention 17 juillet 2007 - 7 juin 2007 à 00:59
salam ,


je ai realisé le programme de detections de contour d une image blan/noir . lors de l execution un message d ereur dans la partie "public inter filterRGB (int x, int y, int rgb) " s affiche . voici mon programme .




 
public class NegatifImage extends Applet
{
  private Image image,
                negatifImage;
 
  public void init ()
  {     
    // Création d'une image et de son négatif
    image        = getImage (getCodeBase (), "image1.jpg");
    negatifImage = createImage (new FilteredImageSource
                                       (image.getSource (),
                                        new FiltreNegatif ()));
  }
 
  public void paint (Graphics gc)
  {
    if (image != null)
    {
      // Affichage des images
      gc.drawImage (image, 0, 0, this);
      gc.drawImage (negatifImage,
                     image.getWidth (this) + 10, 0, this);
    }
  }
}
 
class FiltreNegatif extends RGBImageFilter
{
  private int [] data ;
 private int width ;
 private int hight ;
 public FiltreNegatif (Image Image) {
          this.width = Image.getWidth ();
          this.height = Image.getHeight ();
          this.data = new int [this.width * this.height];


          try {
             PixelGrabber pg = new PixelGrabber (Image,
                               0,
                               0,
                               this.width,
                               this.height,
                               this.data,
                               0,
                               this.width);
             pg.grabPixels ();
          }
          catch (InterruptedException err) {
                throw new RuntimeException ("Chargement interrompu ...");
          }
          if ((pg.getStatus () & ImageObserver.ABORT) != 0) {
             throw new RuntimeException ("Chargement interrompu ...");
          }
       


  public int filterRGB (int x, int y, int rgb)  {
    if (y==0) {
                   return rgb ;
                   }
                  
     int yprevious = y-1 ; 
     if (yprevious < 0 )
     {
         yprevious = this.width - 1;
         }
 
  int previousRGB =this.data[this.width*x + yprevious] ;
 
  int r1 = (rgb >>16 ) & 0xFF;
  int g1= (rgb >>8 ) & 0xFF;
  int b1= rgb  & 0xFF; 
 
  int r2 = ( previousRGB>>16 ) & 0xFF;
  int g2= ( previousRGB>>8 ) & 0xFF ;
  int b2=  previousRGB & 0xFF;
 
  int r3=r1-r2 ;
  int g3=g1-g2 ;
  int b3=b1-b2 ;
                     
    return   r3 | g3 | b3;
  }
}
}

7 réponses

sheorogath Messages postés 2448 Date d'inscription samedi 21 février 2004 Statut Modérateur Dernière intervention 29 janvier 2010 17
3 juin 2007 à 17:29
je peux pas trp t'aider la dedans mais bon tu trouveras ton bonheur peut etre ici : http://perso.orange.fr/emmanuel.remy/Java/Tutoriels/TechniquesSup/TraitementImages.html#filtrage

"n'est pas mort ce qui semble a jamais dormir et en d'etrange temps meme la mort peut mourrir"
0
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
4 juin 2007 à 19:48
Salut:

J'ai fait toutes les corrections possibles avec des modifications. J'espère que ça va marcher (ICA).

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageObserver;
import java.awt.image.RGBImageFilter;
import javax.swing.ImageIcon;
import java.awt.image.PixelGrabber;

public class NegatifImage extends Applet {
    private Image image,
            negatifImage;
   
    public void init() {
        // Création d'une image et de son négatif
        image        = getImage(getCodeBase(), "image1.jpg");
        negatifImage = createImage(new FilteredImageSource
                (image.getSource(),
                new FiltreNegatif (image)));
    }
   
    public void paint(Graphics gc) {
        if (image != null) {
            // Affichage des images
            gc.drawImage(image, 0, 0, this);
            gc.drawImage(negatifImage,
                    image.getWidth(this) + 10, 0, this);
        }
    }
}

class FiltreNegatif extends RGBImageFilter {
    private int [] data ;
    private int width ;
    private int height ;
    public FiltreNegatif(Image image) {
        // POUR S'ASSURER QUE TOUTE L'IMAGE A ETAIT CHARGEE
        // PAR LA SUITE DETERMINER SES DIMENSIONS
        ImageIcon icon = new ImageIcon (image);
       
        width  = icon.getIconWidth();
        height = icon.getIconHeight();
        data   = new int [width * height];
       
        try {
            PixelGrabber pg = new PixelGrabber(image,
                    0,
                    0,
                    width,
                    height,
                    data,
                    0,
                    this.width);
            pg.grabPixels();
        } catch (InterruptedException err) {
            throw new RuntimeException("Chargement interrompu ...");
        }
    }
   
    public int filterRGB(int x, int y, int rgb)  {
        if (y == 0) {
            return rgb ;
        }
       
        int yprevious = y - 1 ;
        if (yprevious < 0 ) {
            yprevious = width - 1;
        }
       
        int previousRGB = data[width*x + yprevious] ;
       
        int r1 = (rgb >> 16) & 0xFF;
        int g1=  (rgb >> 8)  & 0xFF;
        int b1=  rgb  & 0xFF;
       
        int r2 = (previousRGB >> 16) & 0xFF;
        int g2 = (previousRGB >> 8) & 0xFF ;
        int b2 =  previousRGB & 0xFF;
       
        int r3 = r1 - r2 ;
        int g3 = g1 - g2 ;
        int b3 = b1 - b2 ;
       
        return   (int)(r3 | g3 | b3);
    }
}
0
najah01_3 Messages postés 35 Date d'inscription dimanche 24 septembre 2006 Statut Membre Dernière intervention 17 juillet 2007
5 juin 2007 à 02:07
salam ,
il y a un message d erreur " illegal srat of expression"
0
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
5 juin 2007 à 12:11
Salut:

Il faut utiliser le code que j'ai envoyé, je l'ai testé il n'y a pas d'erreur de compilation.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
najah01_3 Messages postés 35 Date d'inscription dimanche 24 septembre 2006 Statut Membre Dernière intervention 17 juillet 2007
5 juin 2007 à 21:32
salam ,


 


je l ai corrigé ca marche ; il se compile mais l excecution donne frame vide
0
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
5 juin 2007 à 23:00
Salut:

Chez moi, il y a affichage de l'image mais visiblement sans modification.

Si tu utilises Internet Explorer pour visualiser l'applet, je te conseille de passer par l'utilitaire appletviewer

C:\> appletviewer applet.html

Ou bien fireFox car Internet Explorer bloque la page.

Autre alternative débloques la page
0
najah01_3 Messages postés 35 Date d'inscription dimanche 24 septembre 2006 Statut Membre Dernière intervention 17 juillet 2007
7 juin 2007 à 00:59
salam
je travail toujours avec appletviewer .
0
Rejoignez-nous