|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2005
Città: Ragusa
Messaggi: 1954
|
[Java] Aiuto filtro convolutivo
Sto realizzando un programma in java (sono ancora agli inizi) che dove applicare una maschera convolutiva o kernel a un'immagine, in questo caso sto applicando Sobelx (kernel 3x3):
Compilando il codice non riscontro nessun errore, ma al momento di eseguirlo mi da il seguente errore Exception in thread "main" java.awt.image.ImagingOpException: Unable to convolve src image at java.awt.image.ConvolveOp.filter(ConvolveOp.java:180) at Sobelx.converti(Sobelx.java:39) at Sobelx.main(Sobelx.java:59) La sintassi è la seguene: ...$ java Sobelx nome_sorgente_immagine.jpg nome_destinazione_immagine.jpg e questo è il codice: Codice:
import javax.imageio.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
public class Sobelx {
public static BufferedImage apri(String path)throws Exception {
BufferedImage imm1=ImageIO.read(new File(path));
return imm1;
}
public static BufferedImage crea(BufferedImage imm)throws Exception {
BufferedImage imm2=new BufferedImage(imm.getWidth(null),imm.getHeight(null),imm.getType());
return imm2;
}
public static void salva(BufferedImage imm2,String path)throws Exception
{
ImageIO.write(imm2,"jpg",new File(path));
}
public static BufferedImage converti(BufferedImage imm1, BufferedImage imm2)throws Exception
{
float [] data={-1.0f, -2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 2.0f, 1.0f};
Kernel kernel= new Kernel(3,3,data);
BufferedImageOp op= new ConvolveOp(kernel);
return imm2= op.filter(imm1,null);
}
public static void main(String args[])throws Exception
{
if (args.length !=2){
System.out.println("Errore");
return;
}
BufferedImage imm1=apri(args[0]);
BufferedImage imm2=crea(imm1);
converti (imm1,imm2);
salva(imm2,args[1]);
}
}
Ultima modifica di Belzer : 13-01-2007 alle 19:22. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2005
Città: Ragusa
Messaggi: 1954
|
Problema risolto
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: May 2005
Città: Roma
Messaggi: 7938
|
dicci come.....
__________________
My gaming placement |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:33.



















