java - How to combine 2 images to form hybrid image? -


i implementing hybrid image imagej , stuck @ merging low filter image , high filter image form hybrid image.

this done.i have 2 images gaussian blur , laplician of gaussian filer. need merge these 2 images layer after that. idea how achieve it?

import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; import ij.plugin.*; import ij.io.*; import java.io.*;   public class hybridimage_plugin implements pluginfilter{     int cfsize=3;    string img_lowpass; string img_highpass; private double[][] filter; private double sigma;  float w=2 ,delta=0 , thr=0;     int mode=0;  //dialogbox private boolean gui() {     genericdialog gd = new genericdialog("enter values", ij.getinstance());                  gd.addnumericfield("sigma (3,5,9,17,35)", cfsize, 0);            gd.addstringfield("low-pass", "/home/atrx/imagej/plugins/hybridimage/l1.tif");     gd.addstringfield("high-pass", "/home/atrx/imagej/plugins/hybridimage/l2.tif");     return getuserparams(gd); }  //get parameters     private boolean getuserparams(genericdialog gd) {        gd.showdialog();             if (gd.wascanceled())     {         return false;     }                cfsize = (int) gd.getnextnumber();     img_lowpass = gd.getnextstring();            img_highpass= gd.getnextstring();                        return true; }     public int setup(string arg, imageplus imp) {       return pluginfilter.no_image_required; }  public void run(imageprocessor ip) {     int[][] result;     if(gui() == false)     {         return;     }        else     {                    opener opener1 = new opener();         opener opener2 = new opener();         imageplus imp1= opener1.openimage(img_lowpass);         imageplus imp2= opener2.openimage(img_highpass);         //imp1.show("low pass image");         //imp2.show("highpass image");                   imageprocessor ip1 = imp1.getprocessor();         imageprocessor ip2 = imp2.getprocessor();          //lowpass filter(gaussian blur)         ip1.blurgaussian(cfsize);         showprocessor(ip1,"low pass filtered image");          //highpass filter(log)         int csize = ip2.getheight();         int rsize = ip2.getwidth();         rectangle rect = ip2.getroi();         int d0,a0,acr,dow,it;             int  i,x,y;             double h12, h21, ft, h1h2, h2h1, fmu, dh, dv;         double r, dt, dmx, dmn;         float logaus[] = new float[(rect.width>rect.height)? rect.width : rect.height];         float   gaus[] = new float[(rect.width>rect.height)? rect.width : rect.height];         float  dgaus[] = new float[(rect.width>rect.height)? rect.width : rect.height];         long zcn =0;         byte pixels[] = (byte[])ip2.getpixels();         int img_in[]  = new int[rect.width*rect.height];             if (cfsize<0) cfsize=3;             if (cfsize>35) cfsize=35;         if(w<0) w=0;         int fsize = (int)(cfsize*w);         if (fsize%2 == 0)         {             fsize += 1;         }         double dimg[] = new double[rect.height*rect.width];         double dr[] = new double[rect.height*rect.width];          i=0;          for(y=rect.y;y<(rect.y+rect.height);y++)         {             for(x=rect.x;x<(rect.x+rect.width);x++)             {                 img_in[i] = (pixels[(y*rsize)+x]&0xff);                 i++;             }             }         int size = rect.width + fsize -1;         int image[] = new int[(rect.width+fsize-1)*(rect.height+fsize-1)];         int extension= (fsize/2);             for( i=0; i<rect.height;i++)         {             system.arraycopy(img_in,(i*rect.width),image,( ((i+extension)*(rect.width+fsize-1))+ extension ),rect.width);         }              h1h2= h2h1 = h12 =0.0;              for(i=1; i<( (fsize+1) /2);i++)         {             w = (float)cfsize/(float)2.0/(float)1.414;             ft = i/w;                            gaus[i] = (float)math.exp(-ft*ft/2);             h1h2 += 2.0 *(gaus[i]);             logaus[i] =(float)(1-ft*ft)*(float)math.exp(-ft*ft/2);             h2h1 += 2.0*(logaus[i]);             dgaus[i] =(float)ft*(float)math.exp(-ft*ft/2);             }         fmu = (h2h1 + 1)* (h1h2+1);                   int prel[] = new int[rect.width+1];         dmx = -99999.9;         dmn =  99999.9;          int limit = ((rect.width+fsize-1)*(rect.height+fsize-1));             for(d0=0;d0<rect.height;d0++)         {             for(a0=0;a0<rect.width;a0++)             {                  acr = a0 + fsize/2;                 dow = d0 + fsize/2;                 dh = dv = 0.0;                 h1h2 = h2h1 = 0.0;                 (int j=1; j<(fsize+1)/2; j++)                 {                     int a0d0, a0d1, a1d0, a1d1;                     h12=h21=0.0;                      for(i=1;i<(fsize+1)/2;i++)                     {                         a0d0 = acr-i+((dow-j)*size);                         a0d1 = acr-i+((dow+j)*size);                         a1d0 = acr+i+((dow-j)*size);                         a1d1 = acr+i+((dow+j)*size);                          h12 += logaus[i]*(image[a0d0] + image[a0d1]+                                     image[a1d0] + image[a1d1]);                         h21 += gaus[i]*  (image[a0d0] + image[a0d1] +                                     image[a1d0] + image[a1d1]);                         }                     a0d0 = acr-j+dow*size;                     a0d1 = acr+(dow-j)*size;                     a1d0 = acr+j+dow*size;                     a1d1 = acr+(dow+j)*size;                      h1h2 += gaus[j] * (h12+ image[a0d0]+image[a0d1]+                                 image[a1d0]+image[a1d1]);                     h2h1 += logaus[j]*(h21+ image[a0d0]+ image[a0d1] +                                 image[a1d0] + image[a1d1] );                      if(thr != 0.0)                     {                         dh += dgaus[j] * ( image[a1d0] - image[a0d0] );                         dv += dgaus[j] * ( image[a1d1] - image[a0d1] );                     }                 }                 dt = dimg[d0*rect.width+a0] = h1h2 + h2h1 + (2*image[dow*size+acr]) ;                 if (dt > dmx) dmx = dt;                 if (dt < dmn) dmn = dt;                 if( thr!= 0.0)                 {                     dr[(d0*rect.width)+a0] = math.abs(dh) + math.abs(dv);                 }             }         }         dmx = (dmx-dmn) / 2;         dmn += dmx;         int row=0, column=0;         for(d0=0;d0<rect.height;d0++)         {             for(a0=0;a0<rect.width;a0++)             {                 int id = (d0*rect.width) +a0;                 int index = rsize*(rect.y+d0) + (a0+rect.x);                                     int k = 15;                                      = (int)(dt = (dimg[id] - (dmn-delta*dmx))*255 / (dmx*(1+math.abs(delta))));                                                              switch(mode){                     case 0:                         pixels[index] = (byte)((dt-dmn+dmx)/dmx*127);                         break;                     case 1:                         pixels[index] = (byte)math.abs(it);                         break;                     case 2:                         pixels[index] = (byte)( ((dt!=0)?((dt>0) ? 1: -1) : 0) * 192);                         break;                     case 3:                     default:                         r = dr[id];                         = ( (dt!=0) ? ((dt>0) ? 1: -1) : 0);                         if( it==0 && r>=thr)                         {                             k = 255;                                     zcn++;                         }                         else                         {                             if( (it*prel[a0]<0 || it*prel[a0+1]<0) && r>=thr)                             {                                 k = 255;                                 zcn++;                             }                         }                         prel[a0+1] = it;                         if(k==255 || mode!=3)                         pixels[index] = (byte)k;                         break;                 }             }         }          showprocessor(ip2,"high pass filtered image");               }  }  static void showprocessor(imageprocessor ip, string title){     imageplus win = new imageplus(title,ip);     win.show(); } 

}

have tried performing weighted sum?

out = w*lpf + (1 - w)*hpf 

this kind of sum used everywhere. in particular, image blending, alpha matting , in optimization schemes.

however because there patches of varying spatial frequencies around image, may have make weight adaptive. have choose 1 want emphasize more. want low pass or high pass information stand out more? depending on want, might want use information in either 1 of images , run through distance or similarity measure right weight.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -