Ciao a tutti,
ho un problema banale ma che non riesco a risolvere,devo scrivere una sequenza di numeri in formato di matrice (es 20x20) per poiricostruire una immagine, il problema è che quando scrivo mi va a capo nel file di testo dopo ogni numero...
Come risolvo?
Posto il codice:
graziecodice:public static ImageProcessor periodicWaterMarking(ImageProcessor a,int nx,int ny,ImageProcessor b,int nx_b,int ny_b) { ImageProcessor processed = a.duplicate(); ImageProcessor processed_b = b.duplicate(); PrintStream output=null; try { output = new PrintStream(new FileOutputStream("/home/erpupone/ImageJ/plugins/WaterMarking/mtx.txt")); } catch(Exception e) { } int cont=0,mult,numPixels=0; String linea=""; double passo; //variabile che indica ogni quanti pixel inserine uno 'markato' passo = Math.floor((nx*ny)/(nx_b*ny_b)); int[] array = new int[4]; int[] array_b = new int[4]; IJ.write("Numero pixel immagine Originale: "+(nx*ny)+" Immagine da nascondere: "+(nx_b*ny_b)); IJ.write("Passo: "+passo+" Raggiunti: "+(nx_b*ny_b*passo)); for(int x=0;x<nx;x++){ linea=""; for(int y=0;y<ny;y++) { if((cont % (int)passo)==0 && numPixels<=(nx_b*ny_b)) { numPixels++; //genero random la sequnza di +/- 1 if(Math.random()>=0.5) mult=1; else mult=-1; linea = linea+""+mult+" "; array = processed.getPixel(x,y,array); array_b = processed_b.getPixel(x,y,array_b); IJ.write("Pixel ("+x+","+y+") R: "+array[0]+" G: "+array[1]+" B: "+array[2]); if(mult==1) { array[0]=array[0]+array_b[0]; array[1]=array[1]+array_b[1]; array[2]=array[2]+array_b[2]; } else if(mult==-1) { array[0]=array[0]-array_b[0]; array[1]=array[1]-array_b[1]; array[2]=array[2]-array_b[2]; } if(array[0]>255) array[0]=array[0] % 255; else if(array[0]<0) array[0]=Math.abs(array[0]); if(array[1]>255) array[1]=array[1] % 255; else if(array[1]<0) array[1]=Math.abs(array[1]); if(array[2]>255) array[2]=array[2] % 255; else if(array[2]<0) array[2]=Math.abs(array[2]); IJ.write("Pixel ("+x+","+y+") R: "+array[0]+" G: "+array[1]+" B: "+array[2]); processed.putPixel(x,y,array); } cont++; } //comando che effettua la stampa try {output.print(""+linea+"\n");} catch(Exception e){} } IJ.write("cont: "+cont+" numPixels: "+numPixels); try {output.close();} catch(Exception e){} //valuta il pSNR WaterMarking.getpSNR(a,processed,nx,ny); return processed; }
Ciao
Giovanni

Rispondi quotando