SVP (correction dun petit code : filtrage noirt/blanc)
najah01_3
Messages postés35Date d'inscriptiondimanche 24 septembre 2006StatutMembreDernière intervention17 juillet 2007
-
14 juin 2007 à 00:17
najah01_3
Messages postés35Date d'inscriptiondimanche 24 septembre 2006StatutMembreDernière intervention17 juillet 2007
-
17 juil. 2007 à 11:23
salam ,
dans le code suivant , j ai fait detection de contour horizentalement . j ai compilé , mais mon applet affiche une image blanche .
merci
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);
}
A voir également:
SVP (correction dun petit code : filtrage noirt/blanc)
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023111 14 juin 2007 à 10:28
Salut,
pour moi ce qui ne colle pas c'est le calcul de la résultante de r3 ou g3 ou b3.
Car il faudrait masquer r3, g3 et b3 avec leurs masque respectif avant et surtout les redécaler pour les replacer à leurs postition dans le mot de 32 bits final.
De plus attention si ton image contient de la transparence ici tu ne la replace pas :
najah01_3
Messages postés35Date d'inscriptiondimanche 24 septembre 2006StatutMembreDernière intervention17 juillet 2007 23 juin 2007 à 07:00
salam ,
voila mon code qui fait un detecteur horizoatal et vertical . mais le probleme est qu il ne donne pas le resultat siuhaitable . parfois il affiche l image tel quelle .
public int filterRGB(int x, int y, int rgb) {
if (y == 0) {
return rgb ;
}
if (x == 0) {
return rgb ;
}
int yprevious = y - 1 ;
if (yprevious < 0 ) {
yprevious = width - 1;
}
int xprevious = x - 1 ;
if (xprevious < 0 ) {
xprevious = height - 1;
}
int ypreviousRGB = data[width*x + yprevious] ;
int xpreviousRGB = data[x + xprevious*height] ;
int a1 = (rgb >> 24) & 0xFF;
int r1 = (rgb >> 16) & 0xFF;
int g1= (rgb >> 8) & 0xFF;
int b1= rgb & 0xFF;
int r2 = (ypreviousRGB >> 16) & 0xFF;
int g2 = (ypreviousRGB >> 8) & 0xFF ;
int b2 = ypreviousRGB & 0xFF;
int r3 = (xpreviousRGB >> 16) & 0xFF;
int g3 = (xpreviousRGB >> 8) & 0xFF ;
int b3 = xpreviousRGB & 0xFF;
int r4 = r2 - r1 ;
int g4 = g2 - g1 ;
int b4 = b2 - b1 ;
int r5 = r3 - r1 ;
int g5 = g3 - g1 ;
int b5 = b3 - b1 ;
int r6 =(int) (Math.sqrt((r4*r4)+(r5*r5)));
int g6 = (int)(Math.sqrt((g4*g4)+(g5*g5)));
int b6 = (int) (Math.sqrt((b4*b4)+(b5*b5)));
najah01_3
Messages postés35Date d'inscriptiondimanche 24 septembre 2006StatutMembreDernière intervention17 juillet 2007 17 juil. 2007 à 11:23
salut twunis ,
j ai realisé une applet avec convolveOP . il donne le message derror" identifier ;;"
est ce la formule d applet est juste d abord ???
public class filtreImage extends Applet {
private Image img ;
private BufferedImage bi ;
//float[] filter = new float { 0f,-1f,0f,-1f,4f,-1f,0f,-1f,0f } ;
public void init() {
// Création d'une image et de son négatif
img = getImage(getCodeBase(), "img3.gif");
BufferedImage bi = new BufferedImage(img.getWidth(null) ,img.getHeight(null),BufferedImage.TYPE_INT_RGB);
}
public static BufferedImage contour(BufferedImage bi){
float[] filter = { 0f, -1f, 0f, -1f, 4f, -1f, 0f, -1f, 0f };
Kernel kernel = new Kernel(3, 3, filter);
ConvolveOp op = new ConvolveOp(kernel);
return op.filter(bi, null);
}
public void paint(Graphics gc) {
//if (image != null) {
// Affichage des images
Graphics2D g = bi.createGraphics();
// g.drawImage(contour(createBufferedImag(bi)),0,0,this);
g.drawImage(contour((bi)),0,0,this);