java - why jTransform makes image turn yellow -


the fft , ifft sequence using jtransform not generates same results, although no visible difference can seen. visualized difference , found out not matter input image is, diff.jpg yellow, why happening? how can fix that?

original image

diff

here testing code, in check.java;

import org.jtransforms.fft.doublefft_2d; import org.jtransforms.fft.doublefft_3d;  import static java.lang.math.abs; public class check {     public static void main(string[] args){         try {             double[][][] im=parser.getimagergb("res//kato_megumi.jpg");             doublefft_3d f3d=new doublefft_3d(im.length,im[0].length,im[0][0].length/2);             f3d.complexforward(im);             f3d.complexinverse(im,true);             parser.setimagergb(im,"reflect.jpg");             double[][][] ref=parser.getimagergb("reflect.jpg");             double[][][] cmp=new double[im.length][im[0].length][im[0][0].length];             for(int i=0;i<im.length;i++)                 for(int j=0;j<im[0].length;j++)                     for(int k=0;k<im[0][0].length;k+=2)                         cmp[i][j][k]=ref[i][j][k]-im[i][j][k];             parser.setimagergb(cmp,"diff.jpg");         } catch (exception e) {             e.printstacktrace();         }     } } 

here parser.java:

import org.jtransforms.fft.doublefft_2d;  import javax.imageio.imageio; import java.awt.image.bufferedimage; import java.io.file; import java.util.arraylist; import java.util.collections; import java.util.random;  import static java.lang.math.min; import static java.lang.math.rint;  public class parser {     static int[] hmap,wmap;     static double alpha=5.45;     private static boolean debug=true;     public static double[][][] getimagergb(string filename)throws exception{         bufferedimage im= imageio.read(new file(filename));         int[] image;         int h=im.getheight(), w=im.getwidth(), type=im.gettype(),cnt=0,tmp;         image=im.getrgb(0,0,w,h,null,0,w);         double[][][] ret=new double[3][h][2*w];         for(int i=0;i<h;i++)             for(int j=0;j<w;j++){                 tmp=image[cnt++];                 ret[0][i][2*j]=(tmp&0xff);            //b                 ret[1][i][2*j]=((tmp&0xff00)>>8);    //g                 ret[2][i][2*j]=((tmp&0xff0000)>>16);  //r             }        return ret;     }      public static void setimagergb(double[][][] im, string filename)throws exception{         file file=new file(filename);         if(!file.exists()) file.createnewfile();         int h=im[0].length,w=im[0][0].length/2,cnt=0,r,g,b;         bufferedimage bim =new bufferedimage(w,h,bufferedimage.type_int_rgb);         int[] out=new int[h*w];         for(int i=0;i<h;i++)             for(int j=0;j<w;j++){                 b=min(new double(rint(im[0][i][2*j])).intvalue(),255);                 g=min(new double(rint(im[1][i][2*j])).intvalue(),255);                 r=min(new double(rint(im[2][i][2*j])).intvalue(),255);                 out[cnt++]=(r<<16)|(g<<8)|(b);             }         bim.setrgb(0,0,w,h,out,0,w);         imageio.write(bim,"jpeg",file);     }        private static int[] setmap(int seed,int len){         int[] save=new int[len];         arraylist<integer> sh=new arraylist<>();         for(int i=0;i<len;i++)sh.add(i);         collections.shuffle(sh,new random(seed));         for(int i=0;i<len;i++)save[i]=sh.get(i);         return save;     }     private static double[][][] encode(double[][][] input,int h,int w,int seed){         hmap=setmap(seed,h/2);wmap=setmap(seed+1,w/2);         double[][][] ret=new double[input.length][h][w];         for(int ch=0;ch<input.length;ch++){             for(int i=0;i<input[0].length;i++)                 for(int j=0;j<input[0][0].length/2;j++)                     ret[ch][hmap[i]][2*wmap[j]]=input[ch][i][2*j];             for(int i=0;i<h/2;i++)                 for(int j=0;j<w/2;j++)                     ret[ch][h-1-i][w-2*(j+1)]=ret[ch][i][2*j];         }         return ret;     }     private static double[][][] decode(double[][][] input,int h,int w,int seed){         hmap=setmap(seed,h/2);wmap=setmap(seed+1,w/2);         double[][][] wm=new double[3][h][w];         for(int ch=0;ch<3;ch++){             for(int j=0;j<h/2;j++)                 for(int k=0;k<w/2;k++)                     wm[ch][j][2*k]=input[ch][hmap[j]][2*wmap[k]];             for(int j=0;j<h/2;j++)                 for(int k=0;k<w;k+=2)                     wm[ch][h-1-j][w-2-k]=wm[ch][j][k];         }         return wm;     }     private static void cpxfft(double[][] input){         doublefft_2d f2d=new doublefft_2d(input.length,input[0].length/2);         f2d.complexforward(input);     }     private static void cpxifft(double[][] input){         doublefft_2d f2d=new doublefft_2d(input.length,input[0].length/2);         f2d.complexinverse(input,true);     }     public static void encrypt(string fn1,string fn2,string output)throws exception{         double[][][] im=getimagergb(fn1);         double[][][] wm=getimagergb(fn2);         double[][][] rwm=encode(wm,im[0].length,im[0][0].length,666666);         for(int i=0;i<im.length;i++){             cpxfft(im[i]);             for(int j=0;j<im[0].length;j++)                 for(int k=0;k<im[0][0].length;k++)                     im[i][j][k]+=rwm[i][j][k]*alpha;             cpxifft(im[i]);         }         setimagergb(im,output);         system.out.println("encrypt completed!");     }     public static void decrypt(string fn1,string fn2,string output)throws exception{         double[][][] im=getimagergb(fn1);         double[][][] src=getimagergb(fn2);         assert( src.length==im.length&&                 src[0].length==im[0].length&&                 src[0][0].length==im[0][0].length);         int ch=src.length,h=src[0].length,w=src[0][0].length;         double[][][] dwm=new double[ch][h][w];         for(int i=0;i<ch;i++){             cpxfft(src[i]);             cpxfft(im[i]);             for(int j=0;j<h;j++)                 for(int k=0;k<w;k+=2)                     dwm[i][j][k]=(im[i][j][k]-src[i][j][k])/alpha;         }         double[][][] wm=decode(dwm,h,w,666666);         setimagergb(wm,output);         system.out.println("decrypt completed!");     }     public static void main(string[] args)throws exception{         encrypt("res//kato_megumi.jpg","res//wm2.bmp","testoutput.jpg");         decrypt("res//kato_megumi.jpg","testoutput.jpg","decoded.png");         } } 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -