Help! Graphis class
super.paintComponent(g);
m=ImageIO.read(new File(s));
Rectangle2D anc =new Rectangle2D.Double(0,0,m.getWidth(),m.getHeight());
Paint pTexture =new TexturePaint(m,anc);
g.setPaint(pTexture)// i have some problems in this method
Message was edited by:
willjunior
# 1
> [code]
> super.paintComponent(g);
>
> m=ImageIO.read(new File(s));
I seriously doubt that you really want to read this image file *every* time paint() is called.
>
> Rectangle2D anc = new
> new
> Rectangle2D.Double(0,0,m.getWidth(),m.getHeight());
> Paint pTexture =new TexturePaint(m,anc);
I seriously doubt that you really want to create this TexturePaint *every* time paint() is called.
>
> g.setPaint(pTexture)// i have some problems in this
> method
What problems? Errors? Unexpected behavior? Why not submit an SSCCE?
http://homepage1.nifty.com/algafield/sscce.html
Jim S.
# 2
>I seriously doubt that you really want to read this image file *every* time paint() is called.u r right!i move in to the Constructor!idem m=ImageIO.read(new File(s));but still i get some errors!:(
# 3
setPaint() not found on class Graphics
# 4
You should look at Graphics2D class. It can be obtained from Graphics just by casting.
# 5
Ops!!!U R Right!!!!!Tanx u very much! i used a simple casting... Graphics2D G2 = (Graphics2D)(g);ok in the future i post my image elaboration code...tnx u again! :)
# 6
kernel:
public static Kernel otherFilter() {
int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del filtro?"));
k=2*k+1;//Lato del filtro
float[] filtro = new float[k*k];
for(int i=0;i<=k-1;i++)/////////////lato in alto
filtro=1F/(4*k-4);
for(int i=0;i<=k*k-k;i+=k)////////////////lato sinistro
filtro=1F/(4*k-4);
for(int i=k-1;i<=k*k-1;i+=k)////////////////lato destro
filtro=1F/(4*k-4);
for(int i=k*k-k;i<k*k-1;i++)/////////////////////lato basso
filtro=1F/(4*k-4);
return new Kernel(k,k,filtro);
}>
# 7
lut:
for(int i=0; i<100; i++)
{
tabella[RED]=(byte)i;
tabella[GREEN]=(byte)255;
tabella[BLUE]=(byte)(255-i);
}
for(int i=100; i<256; i++)
{
tabella[RED]=(byte)0;
tabella[GREEN]=(byte)0;
tabella[BLUE]=(byte)(255-i);
}
# 8
raster:
int b=0;
int a=0;
/////////////// kiedo di inserire a e b finke sono fuori dai margini dell'immagine
do{
a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));
}while(a<0&&a>=src.getWidth());
do{
b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));
}while(b<0&&b>=src.getHeight());
for(int i=0;i< src.getWidth();i++)
{
for(int j=0;j<src.getHeight();j++)
{
/////////// scorro l'immagine pixel per pixel
float[] val=in.getPixel(i,j,(float[])null);
///////////////// calcolo la distanza del pixel da quello dato
int r=(int)(Math.sqrt((i-a)*(i-a)+(j-b)*(j-b)));
///////////// imposto i colori
val[RED]=(val[RED]-r)%256;
val[GREEN]=(val[GREEN]-r)%256;
val[BLUE]=(val[BLUE]+r)%256;
//////////// scrivo il pixel
out.setPixel(i,j,val);
}
}>
# 9
filtro "quadri gialli"
si consenta all'utente la selezione di una immagine RGB e l'inserimento tramite dialogo delle coordinate di un pixel (A,B) della immagine, si trasformino i suoi pixel come segue:
Per ciascun pixel (X,Y) si calcoli la funzione R(x,y)=Max(|X-A|,|Y-B|)
Per ciascun pixel con valore (Red,Green,Blue) si assegnino i nuovi colori:
( (Red+R)%256 , (Green+R)%256 , (Blue-R)%256 )
visualizzare l'immagine risultante
filtro lut
si crei un filtro puntuale che applichi sui canali R, G, B la seguente lut applicata canale per canale:
i valori tra 0 e 128 vengono invertiti, i valori tra 129 e 255 sono decrementati di 129
filtro convolutivio "media delle diagonali"
si crei un filtro convolutivo descritto da un kernel di convoluzione (2k+1)x(2k+1) che sostituisca il valore del pixel centrale con la media dei pixel che si trovano sulle diagonali del kernel. Anche qui k viene fornito dall'utente
# 10
LUT
for(int i=0; i<=128; i++) {
tabella[RED][i]=(byte)(255-i);
tabella[GREEN][i]=(byte)(255-i);
tabella[BLUE][i]=(byte)(255-i);
}
for(int i=129; i<256; i++) {
tabella[RED][i]=(byte)(i-129);
tabella[GREEN][i]=(byte)(i-129);
tabella[BLUE][i]=(byte)(i-129);
}
?giusta?
# 11
COME CRISTO SI FA IL MODULO?
# 12
private static final int ALPHA=2;
private static final int BLUE=3;
private static final int GREEN=0;
private static final int RED=1;
public BufferedImage otherLUT(BufferedImage I) {
byte [][] tabella = new byte [4][256];
for(int i=0; i<128; i++)
tabella[ALPHA][i]=(byte)(255);
for(int i=0; i<128; i++)
{
tabella[RED][i]=(byte)(255-i);
tabella[BLUE][i]=(byte)(255-i);
tabella[GREEN][i]=(byte)(255-i);
}
for(int i=129; i<256; i++)
{
tabella[RED][i]=(byte)(i-129);
tabella[BLUE][i]=(byte)(i-129);
tabella[GREEN][i]=(byte)(i-129);
}
// dalla tabello ottengo la LUT corrispondente
ByteLookupTable inversione=new ByteLookupTable(0,tabella);
// costruisco l'operatore che mi serve
LookupOp iR=new LookupOp(inversione,null);
// lo applico
BufferedImage temp=iR.filter(I, null);
return temp;
}
IL MODULO LO FAI CON LA %
Message was edited by:
danjavatrix
# 13
lut:
public BufferedImage otherLUT(BufferedImage I)
{
byte [][] tabella = new byte [4][256];
for(int i=0; i<129; i++) //for per invertire
{
tabella[ALPHA]=(byte)255;//alfa non varia
tabella[RED]=(byte)(255-i);//faccio l'inversione
tabella[GREEN]=(byte)(255-i);
tabella[BLUE]=(byte)(255-i);
}
for(int i=129; i<256; i++) //for per decrementare i valodi d 129
{
tabella[ALPHA]=(byte)255;//alfa non varia
tabella[RED]=(byte)(i-129);
tabella[GREEN]=(byte)(i-129);
tabella[BLUE]=(byte)(i-129);
}
////////////////////////////////////////////////////////////////////////
// creo la tabella LUT necessaria
// PROBLEMA: la corrispondenza indici colori 猫
// un po' "da scoprire". inverto tutti e tre i canali
// tranne alfa
// l'inversione di alfa mi 猫 al momento incomprensibile...
// dalla tabello ottengo la LUT corrispondente
ByteLookupTable inversione=new ByteLookupTable(0,tabella);
// costruisco l'operatore che mi serve
LookupOp iR=new LookupOp(inversione,null);
// lo applico
BufferedImage temp=iR.filter(I, null);
return temp;
////////////////////////////////////////////////////////////////////////////////////////////////
}
# 14
your problem is calculate modulesmodulo =a%b
# 15
kernel: penso k sia giusto
public static Kernel otherFilter()
{
int k = Integer.parseInt(JOptionPane.showInputDialog("immetti il range:"));
k = 2*k+1;
float [] c =new float [k*k];
float media=0F;
for(int i= 0; i<k;i++)
{
media+= i*k+i; // sommo tutti i valori del diagonale;
}
media = media/k;//faccio la media
for(int i= 0; i><k;i++)
{
c[i*k+i]+= media; // assegno la media al diagonale
}
return new Kernel(k,k,c);
}>
# 16
ahi, che bellu stesame.....
# 17
RASTER:
int b=0;
int a=0;
/////////////// se uno dei due valori sfora mi faccio dare un altro valore
do{
a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));
}while(a<0&&a>=src.getWidth());
do{
b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));
}while(b<0&&b>=src.getHeight());
for(int i=0;i< src.getWidth();i++)
{
for(int j=0;j<src.getHeight();j++)
{
/////////// scorro l'immagine pixel per pixel
float[] val=in.getPixel(i,j,(float[])null);
///////////////// calcolo la distanza del pixel da quello dato
int primo=(int)(Math.abs(i-a));
int secondo=(int)(Math.abs(j-b));
int r;
if(primo>secondo) r=primo;
else r=secondo;
///////////// imposto i colori
val[RED]=(val[RED]+r)%256;
val[GREEN]=(val[GREEN]+r)%256;
val[BLUE]=(val[BLUE]-r)%256;
//////////// scrivo il pixel
out.setPixel(i,j,val);
}
}
# 18
kernel dosn't work....now we post
# 19
KERNEL:
public static Kernel otherFilter() {
int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del c?"));
k=2*k+1;//Lato del c
float[] c = new float[k*k];
for(int i=0;i<k*k;i=i+1+k)/////////////questo rappresenta la prima diagonale
c[i]=1F/(2k-1);
for(int i=k-1;i<=k*k-k;i=i-1+k)////////////////questo rappresenta la seconda diagonale
c[i]=1F/(2k-1);
return new Kernel(k,k,c);
}
>
# 20
GRAZIE!!
TIME TO RASTER:
private static final int ALPHA=3;
private static final int BLUE=2;
private static final int GREEN=1;
private static final int RED=0;
public BufferedImage filter(BufferedImage src, BufferedImage dest) {
dest=null;
if (dest==null) dest=createCompatibleDestImage(src,null);
WritableRaster out=dest.getRaster();
Raster in=src.getRaster();
int b=0;
int a=0;
do{
a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));
}while(a<0&&a>=src.getWidth());
do{
b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));
}while(b<0&&b>=src.getHeight());
for(int i=0;i< src.getWidth();i++) {
for(int j=0;j<src.getHeight();j++) {
float[] val=in.getPixel(i,j,(float[])null);
int r=(int)( Math.max( (i%a) , (j%b) ) );
val[RED]=(val[RED]-r)%256;
val[GREEN]=(val[GREEN]-r)%256;
val[BLUE]=(val[BLUE]+r)%256;
out.setPixel(i,j,val);
}
}
return dest;
}
correggetelo se sbagliato, io sto andando TOTALMETE a CASO! CANNIBALIZZO CODICE!>
# 21
public BufferedImage filter(BufferedImage src, BufferedImage dest)
{
dest=null;//Se tolgo sto null lavoro sull'originale...
if (dest==null)
dest=createCompatibleDestImage(src,null);
WritableRaster out=dest.getRaster();
Raster in=src.getRaster();
//////////////////////////////////////////////////////////////////
int A = Integer.parseInt(JOptionPane.showInputDialog("immetti A"));
int B = Integer.parseInt(JOptionPane.showInputDialog("immetti B"));
for(int i = 0; i < src.getWidth(); i++)//scorro per righe
{
for(int j = 0; j< src.getHeight(); j++)//scorro per colonne
{
float val[] = in.getPixel(i,j,(float[])null);
float r = Math.max(Math.abs(i-A),Math.abs(j-B));//la formula multimediale
val[RED] = 1F*((int)(val[RED]+r)%256);
val[GREEN] = 1F*((int)(val[GREEN]+r)%256);
val[GREEN] = 1F*((int)(val[GREEN]-r)%256);
out.setPixel(i,j,val);//scrivo sul pixel
}
}
return dest;
}
# 22
imposible to compilate but tabella is a matrix tabella[ALPHA ]=(byte)255if i innizialized an array it's function?
# 23
a siti na carpata di bastaddi...soprattutto mi spiegate perch postate in inglese ca siti chi catanisi di mia!
PS: il kernel non compila mi va in panic che faccio?
help me
cmq scherzo prima che poi entrate in para
tutto giusto fidatevi della rondine
vi voglio bene
grazie di esistere tosky...
by
il tuo fuckclub
# 24
imposible to compilate but tabella is a matrix
tabella[ALPHA ]=(byte)255
if i innizialized an array it's function?
perch matrix?forse sto kernel schiva i colpi?
vi saluta da sucaminchia di trinity
# 25
se metto come matrice nn funsionaperche tabella[ALPHA][?]=*****************se no metto tabella[alpha]=*************
# 26
la mia lut funziona...prendi quella
# 27
IL KERNEL NON FUNZICA GALLO MALANDRINO!
# 28
il problema sta nella parola "funsiona"...si scrive con la "z" e cmq basta solamente copiare il codice che vi abbiamo postato!!
# 29
forse sto kernel ok:
public static Kernel otherFilter()
{
int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del k?"));
k=2*k+1;//Lato del c
float[] c = new float[k*k];
for(int i= 0; i<k;i++)
{
c[i*k+i] = 1F/(2*k-1); // assegno la media al diagonale
}
for(int i= 1; i><=k;i++)
{
c[(k-1)] = 1F/(2*k-1); // assegno la media al diagonale
}
return new Kernel(k,k,c);
}
# 30
Che cazzo quel "><" ?
# 31
public static Kernel otherFilter()
{
int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del k?"));
k=2*k+1;//Lato del c
float[] c = new float[k*k];
for(int i= 0; i<k;i++)
{
c[i*k+i] = 1F/(2*k-1); // assegno la media al diagonale
}
for(int i= 1; i><=k;i++)
{
c[(k-1)] = 1F/(2*k-1); // assegno la media al diagonale
}
return new Kernel(k,k,c);
}
# 32
illegal start of expressionfor(int i=1; i><=k;i++) {
# 33
ma il kernel sfoca l'immagine come media dei angoli?
# 34
leva il maggiorefor(int i= 0; i<k;i++)>
# 36
no in base ai dialognaliMessage was edited by: willjunior
# 37
come mai hai fatto: c[i*k+i] = 1F/(2*k-1);Qualche commento in piu'?
# 38
Ma normale che mi spunta una cornice nera attorno l'immagine dopo che applico la convoluzione?
# 39
ma il for del kernel e'for(int i= 0; i>k;i++)
# 40
Della seconda diagonale? maggiore o maggiore-uguale?
# 41
se metto cosi diventa scuro ad aumentare il numero
# 42
a me fa una CORNICE ENORME se aumento il numero!!! cazzarola!
# 43
public BufferedImage otherLUT(BufferedImage I)
{
byte []tabella = new byte [4] ; //[256];
for(int i=0; i<129; i++) //for per invertire
{
tabella[ALPHA]=(byte)255;//alfa non varia
tabella[RED]=(byte)(255-i);//faccio l'inversione
tabella[GREEN]=(byte)(255-i);
tabella[BLUE]=(byte)(255-i);
}
for(int i=129; i<256; i++) //for per decrementare i valodi d 129
{
tabella[ALPHA]=(byte)255;//alfa non varia
tabella[RED]=(byte)(i-129);
tabella[GREEN]=(byte)(i-129);
tabella[BLUE]=(byte)(i-129);
}
e' giusto?
# 44
ma perch 2*k-1 nel kernel?
# 45
noMessage was edited by: willjunior
# 46
no COSA?AOOO U BBESSAMU STU SPACCH'I'CHENNEL?
# 49
con la CORNICE NERA GIUSTO?ma sticazzi!Message was edited by: etienn3
# 50
io alla fine sto mettendo questo
public static Kernel otherFilter() {
int k=Integer.parseInt(JOptionPane.showInputDialog("Inserire la dimensione del kernel"));
k=2*k+1;
float[] c = new float[k*k];
for(int i=0;i<k*k;i=i+1+k)
c[i]=1F/(2*k-1);
for(int i=k-1;i<=k*k-k;i=i-1+k)
c[i]=1F/(2*k-1);
return new Kernel(k,k,c);
}
>
# 51
il kernel ho fatto io funziona anche!!!!!anche l'altro funziona