Results 1 to 5 of 5
  1. #1
    m@7m0uD is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default program to do Optical illusions by merge two images

    hello,

    I am need for a program that do Optical illusions by merge two images
    by java.


    we take two pictures


    for the first image we will:
    do edge detection for the fitst
    do negative for the output image
    then to smooth for the output

    for the second image we will:
    do smooth

    and in the last do marge between the two output images

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Cool, it sounds great assignment. Please post your code here or a link to your code when you're done as I know that others and I would love to try it out.

    Much luck!

  3. #3
    m@7m0uD is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Hello,
    i am need if any one help me to do the program

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by m@7m0uD View Post
    Hello,
    i am need if any one help me to do the program
    Ah, but that's a horse of a different color. The problem I see with your first post and even the most recent is that you have not posted a definite question. Just posting the assignment and a general call to help will get you directed to the tutorials but little more.

    I think that you want to read this link here which may help you to get help here and at other fora: How to ask smart questions in a programming forum

    I know that the site linked to above has helped me.

  5. #5
    m@7m0uD is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    I have a code for this assignment , but it not the Not required for the best solution

    Java Code:
    import java.io.*;
    import java.awt.image.*;
    import java.awt.*;
    import javax.imageio.ImageIO;
    public class TestImage{
    	
    	// To Do Edge for the picture
        public static BufferedImage edg(BufferedImage t,BufferedImage src){
        	float data[] = { 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f,
            -1.0f };
            Kernel kernel = new Kernel(3, 3, data);
          ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
            null);
            convolve.filter(src, t);
            for(int i=0;i<t.getHeight();i++){
                for(int j=0;j<t.getWidth();j++){
                    int c = t.getRGB(j,i);
                    int  trans = (c & 0xff000000) >> 24;
                    //red=0;
                    int  red = (c & 0x00ff0000) >> 16;
                    //red=0;
                    int  green = (c & 0x0000ff00) >> 8;
                    //green=0;
                    int  blue = c & 0x000000ff;
                    //blue=0;
                    //double uuu=((0.212671*red)+(0.715160*green)+(0.072169*blue));
                    //System.out.println((int)uuu);
                    /*
                    int c2=200;
                    c2=c2 <<24;
                    int red1=red<<16;
                    c2=c2 | red1;
                    int green1=green<<8;
                    c2=c2 | green1;
                    int blue1=blue;
                    c2=c2 | blue1;
                    */
                    //Color c1 = new Color((int)red,(int)green,(int)blue);
                    Color c1 =  new Color(255-(int)red,255-(int)green,255-(int)blue);
                    t.setRGB(j,i,c1.getRGB());
                    //t.setRGB(j,i,c2);
                }
            }
            return t;
        }
        
        // To Do Smooth for the picture
        public static BufferedImage smooth(BufferedImage t,BufferedImage src){
        float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
            0.0625f, 0.125f, 0.0625f };
        Kernel kernel = new Kernel(3, 3, data);
        ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
            null);
            convolve.filter(src, t);
            for(int i=0;i<t.getHeight();i++){
                for(int j=0;j<t.getWidth();j++){
                    int c = t.getRGB(j,i);
                    int  trans = (c & 0xff000000) >> 24;
                    //red=0;
                    int  red = (c & 0x00ff0000) >> 16;
                    //red=0;
                    int  green = (c & 0x0000ff00) >> 8;
                    //green=0;
                    int  blue = c & 0x000000ff;
                    //blue=0;
                    //double uuu=((0.212671*red)+(0.715160*green)+(0.072169*blue));
                    //System.out.println((int)uuu);
                    /*
                    int c2=200;
                    c2=c2 <<24;
                    int red1=red<<16;
                    c2=c2 | red1;
                    int green1=green<<8;
                    c2=c2 | green1;
                    int blue1=blue;
                    c2=c2 | blue1;
                    */
                    //Color c1 = new Color((int)red,(int)green,(int)blue);
                    Color c1 =  new Color(255-(int)red,255-(int)green,255-(int)blue);
                    t.setRGB(j,i,c1.getRGB());
                    //t.setRGB(j,i,c2);
                }
            }
            return t;
        }
        
        
        
        
        
        
        public static BufferedImage readImage(String path){
            BufferedImage res=null;
            try{
                res= ImageIO.read(new BufferedInputStream(new FileInputStream(path)));
            }catch(Exception e){
                System.out.println(e);
            }
            return res;
        }
        
        
        
    
        public static void writeImage(String path,BufferedImage image){
            try{
                File h=new File(path);
                ImageIO.write(image,"jpg",h);
            }catch(Exception e){
                System.out.println(e);
            }
        }
        
    
    
            public static void main(String [] args){
            BufferedImage i=readImage("c:\\~ps10F_tmp_1.jpg");
            BufferedImage m=readImage("c:\\~ps10F_tmp_1.jpg");
            i=edg(i,m);
        
          
           BufferedImage k=readImage("c:\\3dwp10_20070924_1989280572.jpg");
           BufferedImage s=readImage("c:\\3dwp10_20070924_1989280572.jpg");
           k=smooth(k,s);
           for(int u=0;u<k.getHeight();u++){
           	for(int p=0;p<k.getWidth();p++){
           		int c = k.getRGB(p,u);
           		int  red = (c & 0x00ff0000) >> 16;
                    //red=0;
                    int  green = (c & 0x0000ff00) >> 8;
                    //green=0;
                    int  blue = c & 0x000000ff;
                    Color c1 =  new Color(255-(int)red,255-(int)green,255-(int)blue);
                    
                    
                    k.setRGB(p,u,c1.getRGB());
                    //blue=0;
           		
           
           }
           	}
           	writeImage("C:\\2.jpg",k);
           	BufferedImage ss=k;
                   for(int t=0;t<i.getHeight();t++){
                for(int j=0;j<i.getWidth();j++){
                Color cc=new Color(0xffffff);
               
                if(i.getRGB(j,t)!=cc.getRGB())
                {
                
                int c2=i.getRGB(j,t);
               ss.setRGB(j,t,c2);
               
               }
    
                  }
            }
      /*BufferedImage ss=k;
         
            for(int t=0;t<i.getHeight();t++){
                for(int j=0;j<i.getWidth();j++){
                
                if(t%2==0){
                
                int c2=i.getRGB(j,t);
                ss.setRGB(j,t,c2);
               }
                   }
            }*/
           // return ss;
           
           
             writeImage("c:\\1.jpg",i);
           
           writeImage("C:\\3.jpg",ss);
           
    
           
            
      
            /*
            for(int k=0;k<i.getWidth();k++){
                for(int m=0;m<i.getHeight();m++){
                    if(k==m){i.setRGB(k,m,343565);}
                }
            }
             */
            //i.setRGB(10,10,1000);
            
        }
    }

Similar Threads

  1. [SOLVED] How can i merge 2 images?
    By angelinehelena in forum Java 2D
    Replies: 5
    Last Post: 05-13-2010, 11:29 PM
  2. Ready To Program, Images in HSA Console?
    By habbah in forum New To Java
    Replies: 2
    Last Post: 01-17-2010, 03:50 AM
  3. need help in uploading images in swing program!!!
    By ashton in forum New To Java
    Replies: 10
    Last Post: 01-26-2009, 10:01 AM
  4. Merge XML using XSL
    By palanikumark in forum XML
    Replies: 1
    Last Post: 08-16-2008, 12:14 AM
  5. Replies: 1
    Last Post: 03-27-2008, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •