10 Replies - 583 Views - Last Post: 21 April 2012 - 03:20 AM Rate Topic: -----

#1 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

StringIndexOutOfBoundsException

Posted 19 April 2012 - 05:24 AM

Hello respected members of the forum
I am doing a project on steganography and need some help.
i am not able to detect where the exception is being thrown
below i am posting a part of the code
	import java.awt.event.*;
	import javax.swing.*;
	import java.awt.image.BufferedImage;
	import javax.swing.JFrame;
	import javax.swing.SwingUtilities;
	import java.io.*;
	import javax.swing.JFileChooser;
	import javax.swing.filechooser.FileFilter;
	import javax.swing.filechooser.FileNameExtensionFilter;
	import javax.imageio.ImageIO;
	import java.awt.*;
	import java.lang.*;

	class demo extends JFrame implements ActionListener
	{
	 
	 static int count=0;
	 JTextArea tohide;
	 public static void main(String args[])
	 {
		demo ti=new demo();
		ti.txtinput();
	 }
	 
	 
	 public String[] skindet()
	 {
	  float[] hsvval;
	  float hue,sat,val;
	  int counter = 0;
	  String[] skinpixel = new String[200000];
	  int scount = 0;
	  try
	  {
	   
	   BufferedImage image = ImageIO.read(new File("lena.png"));
	   int[][] rgb=new int[550][550];
	   int w = image.getWidth();
	   int h = image.getHeight();
	   hsvval=new float[3];
	   int red,green,blue;
	   for (int i=0;i<w;i++) 
	   {
		for (int j=0;j<h;j++)
		{
		 rgb[i][j] =image.getRGB(i,j);
		 red=(rgb[i][j] >> 16) & 0xff;
		 green=(rgb[i][j] >> 8) & 0xff;
		 blue=(rgb[i][j]) & 0xff;
		 float[] values = Color.RGBtoHSB(red,green,blue,null);
		 for(int s=0;s<3;s++)
		 {
		  hsvval[counter]=values[s];
		  counter++;
		 }
		 hue=hsvval[0];
		 sat=hsvval[1];
		 val=hsvval[2];
		 if(hue>0 && hue<0.11 && sat>0.2 && sat<0.7)
		 {
		  String xcor=Integer.toString(i);
		  String ycor=Integer.toString(j);
		  skinpixel[scount]=xcor;
		  scount++;
		  skinpixel[scount]=ycor;
		  scount++;
		 }
		}
	   }
	   
	  }
	  catch(Exception e)
	  {}
	  return skinpixel;
	  
	 }
	

	 
	 public void txtinput()
	 {
	  
	  String ct;
	  JPanel j=new JPanel();
	  JLabel def=new JLabel("Enter the text to be encrypted");
	  tohide=new JTextArea("",5,20);
	  JButton jb=new JButton(" CHECK AND EMBED ");
	  tohide.setBorder(BorderFactory.createLoweredBevelBorder());
	  j.add(def);
	  j.add(tohide);
	  j.add(jb);
	  add(j);
	  setSize(500,500);
	  setVisible(true);
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  setLocationRelativeTo(null);
	  jb.addActionListener(this);
	  
	 }
	 
	 public void actionPerformed(ActionEvent ae)
	 {
	 
	  String txt=tohide.getText();
	  StringBuilder msgbits = new StringBuilder();
	  char[] cname=txt.toCharArray();
	  int len=txt.length();
	  int[] cascii=new int[len];
	  int rem=0,temp=0;
	  
	  erfor(int i=0 ; i<len ; i++)
	  {
	   cascii[i]=(int)cname[i];
	  }
	  
	  for(int i=0 ; i<len ; i++)
	  {
	   temp=cascii[i];
	   
	   while(temp!=0)
	   {
		rem=temp%2;
		temp/=2;
		msgbits.append(rem);    
	   }
	   
	   
	  }
	  
	  
	  String[] skinarea=skindet();
	  DWT dwt = new DWT();
	  
	  
	  
	  
	  try
	  {
	  BufferedImage bufimg = ImageIO.read(new File("lena.png"));
	  
	  
	  int[][] hh_dwt = dwt.dwtFunc(skinarea,bufimg);
	  
	  
		
	  int lenofskin = dwt.ret_length();
	  int lenoftxt = msgbits.length();
	  
	  if(lenofskin < lenoftxt)
	  {
	  
	   JOptionPane.showMessageDialog(new demo(),"The text is too long and hence cannot be embedded into the image");
	   
	  }
	  
	  else
	  {
		 
	   Embedding embedding =new Embedding();
	   int pair_ary[][]=embedding.lehmer(hh_dwt);
	   int[][] modified_matrix=embedding.embedd_values(pair_ary,cascii,bufimg);
	   embedding.merge(new DWT().ret_comloc(),modified_matrix);
	   }
	  }
	  catch(Exception e)
	  {
		e.printStackTrace();
	  }
	  
	 }
	}


	class DWT
	{
	 int comb2;
	 int[] comloc;
	 
	 public int[][] dwtFunc(String[] skin,BufferedImage image)
	 {
	  int skinlen=skin.length;
	  int[] skinloc=new int[skinlen];
	  int[] blueloc=new int[512*512];
	  int k=0;
	  
	  for(int n=0;n<skinlen;n++)
	  {
	  Character c=new Character(skin[n].charAt(n));
	  String s=c.toString();
	  skinloc[n]=Integer.parseInt(s);
	  }
	  
	  int[][] rgb=new int[550][550];
	  int red,green,blue;
	  
	  for(int i=0;i<image.getHeight();i++)
	  {
	  
	   for(int j=0;j<image.getWidth();j++)      
	   {
	   
		rgb[i][j]  = image.getRGB(i,j);
		red   = (rgb[i][j] >> 16) & 0xff;
		green  = (rgb[i][j] >> 8) & 0xff;
		blue  = (rgb[i][j]) & 0xff;
		 
		if((blue >= red) && (blue >= green))
		{
			blueloc[k]   = i;
			blueloc[k++] = j;
			k++;
		}
				
	   }
	   
	  }
			
	  int com=0;
	  
			for (int pp=0;pp<skinloc.length;pp+=2)
			{
				for(int s=0;s<blueloc.length;s+=2)                
				{
					if(( skinloc[pp]==blueloc[s] ) && ( skinloc[pp+1]==blueloc[s+1] ))
					{
						comloc[com]   = skinloc[pp];
						comloc[com+1] = skinloc[pp+1];    //common locations
						com+=2; 

					}
				}
			}
	  com =comloc.length;
	  comb2= com/2;
	  int row_col=(int)Math.sqrt(comb2+0.5);
	  int pixel,comblue;
	  int[][] a=new int[550][550];
	  for(int w=0,r=0;w<row_col;w++)         //initialisation of array
	  {
	  
	   for(int v=0;v<row_col;v++)
	   {
		pixel=image.getRGB(comloc[r],comloc[r++]);
		comblue = (pixel) & 0xff;
		a[w][v]=comblue;
		r++;
	   }
	   
	  }
	  
	  //dwt starts here 
	  int row  = a.length;
	  int column = a[0].length;
	  int[][] mat =  new int[row][column];
	  int[][] mat2 =  new int[row][column];

	  for(int y=0;y<row_col;y++)
	  {
	   for(int z=0;z<row_col;z++)
	   {
		mat[y][z]    = a[y][z]+a[y][z+1];
		mat[y][z+(column/2)]  = a[y][z]-a[y][z+1];
	   }
	  }
	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;q<row;q++)
	   {
		mat2[q][r]   = mat[q][r]+mat[q+1][r];
		mat2[q+(row/2)][r] = mat[q][r]-mat[q+1][r];
	   }
	  }
	//extracting & returning HH portion

	  int[][] final_array=new int[(row/2)+1][(column/2)+1];

	  for(int h=0,g=row/2;h<final_array.length||g<=row;h++,g++)
	  {
	   for(int l=0,m=column/2;l<final_array[0].length||m<=column;l++,m++)
	   {
		final_array[h][l]=mat2[g][h];     

	   }
	  }
	  
	  return(final_array);
	 }
	 

	 public int ret_length()
	 {
	  return comb2;
	 }
	 public int[] ret_comloc()
	 { 
	   return comloc;
	 }
	 
	 public int[][] dwtFunc1(String[] skin,BufferedImage image)
	 {
	  int skinlen=skin.length;
	  int[] skinloc=new int[skinlen];
	  int[] blueloc=new int[512*512];
	  int k=0;
	  String p="";
	  for(int n=0;n<skinlen;n++)
	  {
	   p=skin[n];
	   skinloc[n]=Integer.parseInt(p);
	  }
	  
	  int[][] rgb=new int[550][550];
	  int red,green,blue;
	  
	  for(int i=0;i<image.getHeight();i++)
	  {
	  
	   for(int j=0;j<image.getWidth();j++)      
	   {
	   
		rgb[i][j]  = image.getRGB(i,j);
		red   = (rgb[i][j] >> 16) & 0xff;
		green  = (rgb[i][j] >> 8) & 0xff;
		blue  = (rgb[i][j]) & 0xff;
		 
		if((blue >= red) && (blue >= green))
					{
					   blueloc[k]   = i;
					   blueloc[k++] = j;
					   k++;
					}
				
	   }
	   
	  }
			
	  int com=0;
	  
			for (int pp=0;pp<skinloc.length;pp+=2)
	  {
	   for(int s=0;s<blueloc.length;s+=2)                
	   {
					if(( skinloc[pp]==blueloc[s] ) && ( skinloc[pp+1]==blueloc[s+1] ))
					{
						comloc[com]   = skinloc[pp];
						comloc[com+1] = skinloc[pp+1];    //common locations
						com+=2; 

					}
	   }
	  }
	  com =comloc.length;
	  comb2= com/2;
	  int row_col=(int)Math.sqrt(comb2+0.5);
	  int pixel,comblue;
	  int[][] a=new int[550][550];
	  for(int w=0,r=0;w<row_col;w++)         //initialisation of array
	  {
	  
	   for(int v=0;v<row_col;v++)
	   {
		pixel=image.getRGB(comloc[r],comloc[r++]);
		comblue = (pixel) & 0xff;
		a[w][v]=comblue;
		r++;
	   }
	   
	  }
	  
	  //dwt starts here 
	  int row  = a.length;
	  int column = a[0].length;
	  int[][] mat =  new int[row][column];
	  int[][] mat2 =  new int[row][column];

	  for(int y=0;y<row_col;y++)
	  {
	   for(int z=0;z<row_col;z++)
	   {
		mat[y][z]    = a[y][z]+a[y][z+1];
		mat[y][z+(column/2)]  = a[y][z]-a[y][z+1];
	   }
	  }
	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;q<row;q++)
	   {
		mat2[q][r]   = mat[q][r]+mat[q+1][r];
		mat2[q+(row/2)][r] = mat[q][r]-mat[q+1][r];
	   }
	  }
		
	  return mat2;
	 }
	  
	}  


	class Embedding
	{
	 
	 public  int[][] lehmer(int array1[][])
	 {
	  int rw_len = array1.length;
	  int col_len = array1[0].length;
	  int tot_len = rw_len*col_len;
	  int[][] loc_ary=new int[tot_len][2];
	  boolean[][][] chk_avl=new boolean[rw_len][col_len][1];
	  
	  for(int e=0;e<rw_len;e++)
	  {
	   for(int f=0;f<col_len;f++)
	   {
		chk_avl[e][f][0]=false;
	   }
	  }
	  int loc_ary_rw=0;
	  int counter=0;
	  do
	  {
	   int i=0;
	   int j=0;
	   
	   while(chk_avl[i][j][0]==true)
	   {
		j++;
		if(j==(col_len-1))
		{
		 j=0;
		 i++;
		}
		if(i==(rw_len-1))
		{
		 i=0;
		}
	   }
	   loc_ary[loc_ary_rw][0]=i;
	   loc_ary[loc_ary_rw][1]=j;
	   chk_avl[i][j][0]=true;
	   loc_ary_rw++;
	   counter++;
	   int t=(i*col_len)+j;
	  //lehmer part is written here
	   int n=(int)Math.pow(2,16)+1;
	   int g=75;
	   int random=g*t%n+1; 
	  //lehmer part ends here
	   random=random%tot_len;
	   i=random/rw_len;
	   j=random%col_len;
		
	   while(chk_avl[i][j][0]==true)
	   {
		j++;
		if(j==(col_len-1))
		{
		 j=0;
		 i++;
		}
		if(i==(rw_len-1))
		{
		 i=0;
		}
	   }
	 
	   loc_ary[loc_ary_rw][0]=i;
	   loc_ary[loc_ary_rw][1]=j;
	   chk_avl[i][j][0]=true;
	   loc_ary_rw++;
	   counter++;
	  
	  }while(counter<tot_len);
	  
	  return loc_ary;   
	 }

	 public int[][] embedd_values(int[][] loc_ary,int[] info,BufferedImage B)/>
	 {
	  int length      =loc_ary.length;
	  int e               =length/2;
	  int row_col     =((int)Math.sqrt(e))*2;

	  int rgb,blue;
	  int[][] modi_mat=new int[row_col][row_col];
	  int i=0;

	  for(int x=0;x<row_col;x++)
	  {
	   for(int y=0;y<row_col;y++)
	   {
		rgb=b.getRGB(loc_ary[i][0],loc_ary[i][1]);
		i++;
		blue=(rgb)& 0xff;
		modi_mat[x][y]=blue;
		rgb=0;
		blue=0;

	   }
	  }


	  int c=0;
	  int tmp;

	  for(int v=0;v<row_col;v++)
	  {
	   for(int w=0;w<row_col;w=w+2)
	   {
		tmp=0;

		if(modi_mat[v][w]==modi_mat[v][w+1])
		 continue;

		switch(info[c])
		{
		 case 0:
		   if(modi_mat[v][w]>modi_mat[v][w+1])
		   {
			 tmp                           =modi_mat[v][w];
			 modi_mat[v][w]        =modi_mat[v][w+1];
			 modi_mat[v][w+1]   =tmp;

		   }    
		   break;
		   
		 case 1:
		   if(modi_mat[v][w]<modi_mat[v][w+1])
		   {
			tmp                           =modi_mat[v][w];
			modi_mat[v][w]        =modi_mat[v][w+1];
			modi_mat[v][w+1]   =tmp;
	  
		   }    
		   break;
		}
		c++;
	   }
	  }
		   
	  return modi_mat;

	 
	 } 
	 
	 
	 public void merge(int comloc[],int modified_matrix[][])
	 {
	 try{
	  demo lm=new demo();
	  String[] skinp=new String[200000];
	  skinp=new demo().skindet();
	  BufferedImage buf=ImageIO.read(new File("lena.png"));
	  
	 
	  int [][]mat3=new DWT().dwtFunc1(skinp,buf);   //mat2 is returned here
	 
	  int row=mat3.length;
	  int column=mat3[0].length;
	 
	  int a=0;
	  int b=0;
	 
	  for(int e=(row/2)-1;e<row;e++)
	  {
	   for(int f=(column/2)-1;f<column;f++)
	   {
		mat3[e][f]=modified_matrix[a][b];
		b++;
	   }
	   a++;
	  }
	  int[][] x=new int[row][column];  
	  int[][] y=new int[row][column];
	  
	  BufferedImage b1=ImageIO.read(new File("lena.png"));
	  int len=comloc.length;
	  int[] pel=new int[len];
	  

	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;a<row;q++)
	   {
		x[q][r]  =(mat3[q][r]+mat3[q+(row/2)][r])/2;
		x[q+1][r]=mat3[q][r]-x[q][r];
	   }
	  }

	  for(int f=0;f<row;f++)
	  {
	   for(int z=0;z<column;z++)
	   {
		y[f][z]   =(x[f][z]+x[f][z+(column/2)])/2;
		y[f][z+1] =x[f][z]-y[f][z];
		}
		
	  }
	   int xx=0,yy=0;
	   
	   for (int i=0;i<row;i++)
	   {
		for(int j=0;j<column;j++,yy++,xx++)
		{
		 pel[yy]=b1.getRGB(comloc[xx],comloc[xx++]);
		 pel[yy]=setValue(pel[yy],y[i][j]);
		 
		 
		 
		}
		
	   }
	   new ReprintImage().drawimage(pel,comloc);
	   }
	   catch(Exception e){}
	 }
	 public int setValue(int argb, int val) 
	 { 
	  argb= (argb & 0xff) | val; 
	  return argb;
	 }
	}

	class ReprintImage
	{

	 public void drawimage(int[] pixelement,int[] comlocation)
	 {
	 try{
	  BufferedImage bim=ImageIO.read(new File("lena.png"));
	  for(int i=0;i< comlocation.length;i++)
	  {
	   bim.setRGB(comlocation[i],comlocation[i+1],pixelement[i]);
	  }
	  String format="png";
	 
	  ImageIO.write(bim,format, new File("StegoImage.png"));
	  }
	  catch(java.io.IOException exp)
	  {
	   }
	 }
	}


my project is on steganography where i am trying to embed data into an image containing skin of humans using Discrete Wavelet Transform .thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: StringIndexOutOfBoundsException

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,655
  • Joined: 20-September 08

Re: StringIndexOutOfBoundsException

Posted 19 April 2012 - 08:13 AM

http://technojeeves....free/118-errors
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: StringIndexOutOfBoundsException

Posted 19 April 2012 - 09:18 PM

And we are supposed to figure out ?
Post you stack trace all the info is most probably in it
Was This Post Helpful? 0
  • +
  • -

#4 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

Re: StringIndexOutOfBoundsException

Posted 19 April 2012 - 11:14 PM

View Postpbl, on 19 April 2012 - 09:18 PM, said:

And we are supposed to figure out ?
Post you stack trace all the info is most probably in it

Was This Post Helpful? 0
  • +
  • -

#5 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

Re: StringIndexOutOfBoundsException

Posted 19 April 2012 - 11:29 PM

View Postpbl, on 19 April 2012 - 09:18 PM, said:

And we are supposed to figure out ?
Post you stack trace all the info is most probably in it

sir the problem is that no action is performed when i JButton jb , of TextInput class and get exceptions when i click on JButton next=new JButton("NEXT-->") of Extraction class. Below i have attached the code of TextInput class and the exceptions arising from Extraction class .Thanks in advance.

class TextInput extends JFrame implements ActionListener
	{
	 
	 static int count=0;
	 JTextArea tohide;
	 
	 public void txtinput()
	 {
	  
	  String ct;
	  JPanel j=new JPanel();
	  JLabel def=new JLabel("Enter the text to be encrypted");
	  tohide=new JTextArea("",5,20);
	  JButton jb=new JButton(" CHECK AND EMBED ");
	  tohide.setBorder(BorderFactory.createLoweredBevelBorder());
	  j.add(def);
	  j.add(tohide);
	  j.add(jb);
	  add(j);
	  setSize(500,500);
	  setVisible(true);
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  setLocationRelativeTo(null);
	  jb.addActionListener(this);
	  
	 }
	 
	 public void actionPerformed(ActionEvent ae)
	 {
	 
	  String txt=tohide.getText();
	  StringBuilder msgbits = new StringBuilder();
	  char[] cname=txt.toCharArray();
	  int len=txt.length();
	  int[] cascii=new int[len];
	  int rem=0,temp=0;
	  
	  for(int i=0 ; i<len ; i++)
	  {
	   cascii[i]=(int)cname[i];
	  }
	  
	  for(int i=0 ; i<len ; i++)
	  {
	   temp=cascii[i];
	   
	   while(temp!=0)
	   {
		rem=temp%2;
		temp/=2;
		msgbits.append(rem);    
	   }
	   
	   
	  }
	  
	  LoadImage lim=new LoadImage();
	  String[] skinarea=lim.skindet();
	  DWT dwt = new DWT();
	  
	  
	  String path= lim.returnpath();
	  
	  try
	  {
	  BufferedImage bufimg = ImageIO.read(new File(path));
	  
	  
	  int[][] hh_dwt = dwt.dwtFunc(skinarea,bufimg);
	  
	  
		
	  int lenofskin = dwt.ret_length();
	  int lenoftxt = msgbits.length();
	  
	  if(lenofskin < lenoftxt)
	  {
	   JOptionPane.showMessageDialog(new TextInput(),"The text is too long and hence cannot be embedded into the image");
	  }
	  
	  else
	  {
		 
	   Embedding embedding =new Embedding();
	   int pair_ary[][]=embedding.lehmer(hh_dwt);
	   int[][] modified_matrix=embedding.embedd_values(pair_ary,cascii,bufimg);
	   embedding.merge(new DWT().ret_comloc(),modified_matrix);
	   }
	  }
	  catch(Exception e)
	  {}
	  
	 }
	}






and the exceptions

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at DWT.dwtFunc(Steganography.java:306)
        at Extraction.idwt(Steganography.java:818)
        at Extraction$1.actionPerformed(Steganography.java:800)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.awt.EventQueue$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)




Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,655
  • Joined: 20-September 08

Re: StringIndexOutOfBoundsException

Posted 20 April 2012 - 04:05 AM

Quote

   at DWT.dwtFunc(Steganography.java:306)


So, that tells you that the NPE cause is at line 306 of Steganography.java
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,125
  • Joined: 19-March 11

Re: StringIndexOutOfBoundsException

Posted 20 April 2012 - 07:03 AM

View Postg00se, on 20 April 2012 - 06:05 AM, said:

Quote

   at DWT.dwtFunc(Steganography.java:306)


So, that tells you that the NPE cause is at line 306 of Steganography.java



Which, as far as I can see, we don't have here.
Was This Post Helpful? 0
  • +
  • -

#8 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

Re: StringIndexOutOfBoundsException

Posted 20 April 2012 - 08:25 AM

View Postg00se, on 20 April 2012 - 04:05 AM, said:

Quote

   at DWT.dwtFunc(Steganography.java:306)


So, that tells you that the NPE cause is at line 306 of Steganography.java

sir but i have a DWT class defined in my original code which i have not pasted here because of space constraints.
I have used the DWT class to mainly perform discrete wavelet transform

View Postg00se, on 20 April 2012 - 04:05 AM, said:

Quote

   at DWT.dwtFunc(Steganography.java:306)


So, that tells you that the NPE cause is at line 306 of Steganography.java

sir but i have a DWT class defined in my original code which i have not pasted here because of space constraints.
I have used the DWT class to mainly perform discrete wavelet transform
should i post the DWT class also???
Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,655
  • Joined: 20-September 08

Re: StringIndexOutOfBoundsException

Posted 20 April 2012 - 09:31 AM

It's not possible to say really whether it's the DWT class or the way you're using it in Steganography.java. You can start by posting the latter
Was This Post Helpful? 0
  • +
  • -

#10 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

Re: StringIndexOutOfBoundsException

Posted 20 April 2012 - 01:24 PM

View Postg00se, on 20 April 2012 - 09:31 AM, said:

It's not possible to say really whether it's the DWT class or the way you're using it in Steganography.java. You can start by posting the latter

as you say sir but its 850 odd lines of code
Was This Post Helpful? 0
  • +
  • -

#11 purnosaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-April 12

Re: StringIndexOutOfBoundsException

Posted 21 April 2012 - 03:20 AM

here i hava attach the full code

View Postpurnosaha, on 21 April 2012 - 03:17 AM, said:

here i have attached the full code



	//Importing Packages and Classes

	import java.awt.event.*;
	import javax.swing.*;
	import java.awt.image.BufferedImage;
	import javax.swing.JFrame;
	import javax.swing.SwingUtilities;
	import java.io.*;
	import javax.swing.JFileChooser;
	import javax.swing.filechooser.FileFilter;
	import javax.swing.filechooser.FileNameExtensionFilter;
	import javax.imageio.ImageIO;
	import java.awt.*;
	import java.lang.*;


	public class Steganography extends JFrame  //Main Class
	{
	  
	 public Steganography()  //First Frame
	 {
	  
	  setLayout(null);
	  JButton embed=new JButton("EMBED INFO");
	  embed.setBounds(100,100,150,20);
	  JButton extract=new JButton("EXTRACT INFO");
	  extract.setBounds(100,150,150,20);
	  JButton exit=new JButton("EXIT APPLICATION");
	  exit.setBounds(100,200,150,20);
	  exit.addActionListener(new ActionListener()   //exit Button
	  {
	   public void actionPerformed(ActionEvent ae)
	   {
		System.exit(0);
	   }
	  });
	  embed.addActionListener(new ActionListener()  //embed button
	  {
	   public void actionPerformed(ActionEvent ae)
	   {
		setVisible(false);
		LoadImage lim=new LoadImage();
		lim.loadimgfile();
	   }   
	  });
	  extract.addActionListener(new ActionListener()  //extract button
	  {
	   public void actionPerformed(ActionEvent ae)
	   {
		setVisible(false);
		Extraction extract=new Extraction();
		extract.initUI();
	   }   
	  });
		
	  add(exit);
	  add(embed);
	  add(extract);
	  setTitle("SKIN TONE STEGANOGRAPHY");
	  setIconImage(Toolkit.getDefaultToolkit().getImage("cartoon.gif"));
	  setSize(600,600);
	  setLocationRelativeTo(null);
	  setDefaultCloseOperation(EXIT_ON_CLOSE);
	 
	 }
	  
	  
	 public static void main(String args[])  		//main Function
	 {
	  SwingUtilities.invokeLater(new Runnable()  	//Thread safe
	  {
	   public void run()
	   {
		Steganography stego=new Steganography();
		stego.setVisible(true);
	   }
	  });
	 }
	}

	class LoadImage extends JFrame
	{
	  
	 JButton next=new JButton("NEXT-->");
	 public static String spath;
	 public static BufferedImage image;
	  
	 public void loadimgfile()
	 {
	  JFileChooser fileopen = new JFileChooser();        									//Choosing a file
	  FileFilter filter = new FileNameExtensionFilter("jpeg files", "jpeg");
	  fileopen.addChoosableFileFilter(filter);
	  int ret = fileopen.showDialog(null, "Open file");
	  
	  try
	  {
	   if (ret == JFileChooser.APPROVE_OPTION) 
	   {
		JPanel panel=new JPanel();
		File file = fileopen.getSelectedFile();
		spath=file.getAbsolutePath();
		image = ImageIO.read(new File(spath));
		ImageIcon imgicon=new ImageIcon(spath);
		JLabel label=new JLabel(); 
		label.setIcon(imgicon);
		panel.add(label);
		panel.add(next);
		getContentPane().add(panel);
	   }
	 
	   setVisible(true);
	   setTitle("SKIN TONE STEGANOGRAPHY");
	   setIconImage(Toolkit.getDefaultToolkit().getImage("cartoon.gif"));
	   setSize(600,600);
	   setLocationRelativeTo(null);
	   setDefaultCloseOperation(EXIT_ON_CLOSE);
	  
	   next.addActionListener(new ActionListener()    //NEXT button to move to the input text frame
	   {
		public void actionPerformed(ActionEvent ae)
		{
		 setVisible(false);
		 TextInput txtip=new TextInput();
		 txtip.txtinput();
		}
	   });
	  }
	  catch(IOException ioe)
	  {}
	 }
	 
	 public BufferedImage retimg()
	 {
	  return image;
	 }
	 
	 public String returnpath()
	 {
	  return spath;
	 }
	 
	 public String[] skindet()
	 {
	  float[] hsvval;
	  float hue,sat,val;
	  int counter = 0;
	  String[] skinpixel = new String[200000];
	  int scount = 0;
	  try
	  {
	   File file= new File(spath);
	   image = ImageIO.read(file);
	   int[][] rgb=new int[550][550];
	   int w = image.getWidth();
	   int h = image.getHeight();
	   hsvval=new float[3];
	   int red,green,blue;
	   for (int i=0;i<w;i++) 
	   {
		for (int j=0;j<h;j++)
		{
		 rgb[i][j] =image.getRGB(i,j);
		 red=(rgb[i][j] >> 16) & 0xff;
		 green=(rgb[i][j] >> 8) & 0xff;
		 blue=(rgb[i][j]) & 0xff;
		 float[] values = Color.RGBtoHSB(red,green,blue,null);
		 for(int s=0;s<3;s++)
		 {
		  hsvval[counter]=values[s];
		  counter++;
		 }
		 hue=hsvval[0];
		 sat=hsvval[1];
		 val=hsvval[2];
		 if(hue>0 && hue<0.11 && sat>0.2 && sat<0.7)
		 {
		  String xcor=Integer.toString(i);
		  String ycor=Integer.toString(j);
		  skinpixel[scount]=xcor;
		  scount++;
		  skinpixel[scount]=ycor;
		  scount++;
		 }
		}
	   }
	   
	  }
	  catch(Exception e)
	  {}
	  return skinpixel;
	  
	 }
	}


	class TextInput extends JFrame implements ActionListener
	{
	 
	 static int count=0;
	 JTextArea tohide;
	 
	 public void txtinput()
	 {
	  
	  String ct;
	  JPanel j=new JPanel();
	  JLabel def=new JLabel("Enter the text to be encrypted");
	  tohide=new JTextArea("",5,20);
	  JButton jb=new JButton(" CHECK AND EMBED ");
	  tohide.setBorder(BorderFactory.createLoweredBevelBorder());
	  j.add(def);
	  j.add(tohide);
	  j.add(jb);
	  add(j);
	  setSize(500,500);
	  setVisible(true);
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  setLocationRelativeTo(null);
	  jb.addActionListener(this);
	  
	 }
	 
	 public void actionPerformed(ActionEvent ae)
	 {
	 
	  String txt=tohide.getText();
	  StringBuilder msgbits = new StringBuilder();
	  char[] cname=txt.toCharArray();
	  int len=txt.length();
	  int[] cascii=new int[len];
	  int rem=0,temp=0;
	  
	  for(int i=0 ; i<len ; i++)
	  {
	   cascii[i]=(int)cname[i];
	  }
	  
	  for(int i=0 ; i<len ; i++)
	  {
	   temp=cascii[i];
	   
	   while(temp!=0)
	   {
		rem=temp%2;
		temp/=2;
		msgbits.append(rem);    
	   }
	   
	   
	  }
	  
	  LoadImage lim=new LoadImage();
	  String[] skinarea=lim.skindet();
	  DWT dwt = new DWT();
	  
	  
	  String path= lim.returnpath();
	  
	  try
	  {
	  BufferedImage bufimg = ImageIO.read(new File(path));
	  
	  
	  int[][] hh_dwt = dwt.dwtFunc(skinarea,bufimg);
	  
	  
		
	  int lenofskin = dwt.ret_length();
	  int lenoftxt = msgbits.length();
	  
	  if(lenofskin < lenoftxt)
	  {
	   JOptionPane.showMessageDialog(new TextInput(),"The text is too long and hence cannot be embedded into the image");
	  }
	  
	  else
	  {
		 
	   Embedding embedding =new Embedding();
	   int pair_ary[][]=embedding.lehmer(hh_dwt);
	   int[][] modified_matrix=embedding.embedd_values(pair_ary,cascii,bufimg);
	   embedding.merge(new DWT().ret_comloc(),modified_matrix);
	   }
	  }
	  catch(Exception e)
	  {}
	  
	 }
	}


	class DWT
	{
	 int comb2;
	 int[] comloc;
	 
	 public int[][] dwtFunc(String[] skin,BufferedImage image)
	 {
	  int skinlen=skin.length;
	  int[] skinloc=new int[skinlen];
	  int[] blueloc=new int[512*512];
	  int k=0;
	  
	  for(int n=0;n<skinlen;n++)
	  {
	  Character c=new Character(skin[n].charAt(n));
	  String s=c.toString();
	  skinloc[n]=Integer.parseInt(s);
	  }
	  
	  int[][] rgb=new int[550][550];
	  int red,green,blue;
	  
	  for(int i=0;i<image.getHeight();i++)
	  {
	  
	   for(int j=0;j<image.getWidth();j++)      
	   {
	   
		rgb[i][j]  = image.getRGB(i,j);
		red   = (rgb[i][j] >> 16) & 0xff;
		green  = (rgb[i][j] >> 8) & 0xff;
		blue  = (rgb[i][j]) & 0xff;
		 
		if((blue >= red) && (blue >= green))
		{
			blueloc[k]   = i;
			blueloc[k++] = j;
			k++;
		}
				
	   }
	   
	  }
			
	  int com=0;
	  
			for (int pp=0;pp<skinloc.length;pp+=2)
			{
				for(int s=0;s<blueloc.length;s+=2)                
				{
					if(( skinloc[pp]==blueloc[s] ) && ( skinloc[pp+1]==blueloc[s+1] ))
					{
						comloc[com]   = skinloc[pp];
						comloc[com+1] = skinloc[pp+1];    //common locations
						com+=2; 

					}
				}
			}
	  com =comloc.length;
	  comb2= com/2;
	  int row_col=(int)Math.sqrt(comb2+0.5);
	  int pixel,comblue;
	  int[][] a=new int[550][550];
	  for(int w=0,r=0;w<row_col;w++)         //initialisation of array
	  {
	  
	   for(int v=0;v<row_col;v++)
	   {
		pixel=image.getRGB(comloc[r],comloc[r++]);
		comblue = (pixel) & 0xff;
		a[w][v]=comblue;
		r++;
	   }
	   
	  }
	  
	  //dwt starts here 
	  int row  = a.length;
	  int column = a[0].length;
	  int[][] mat =  new int[row][column];
	  int[][] mat2 =  new int[row][column];

	  for(int y=0;y<row_col;y++)
	  {
	   for(int z=0;z<row_col;z++)
	   {
		mat[y][z]    = a[y][z]+a[y][z+1];
		mat[y][z+(column/2)]  = a[y][z]-a[y][z+1];
	   }
	  }
	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;q<row;q++)
	   {
		mat2[q][r]   = mat[q][r]+mat[q+1][r];
		mat2[q+(row/2)][r] = mat[q][r]-mat[q+1][r];
	   }
	  }
	//extracting & returning HH portion

	  int[][] final_array=new int[(row/2)+1][(column/2)+1];

	  for(int h=0,g=row/2;h<final_array.length||g<=row;h++,g++)
	  {
	   for(int l=0,m=column/2;l<final_array[0].length||m<=column;l++,m++)
	   {
		final_array[h][l]=mat2[g][h];     

	   }
	  }
	  
	  return(final_array);
	 }
	 

	 public int ret_length()
	 {
	  return comb2;
	 }
	 public int[] ret_comloc()
	 { 
	   return comloc;
	 }
	 
	 public int[][] dwtFunc1(String[] skin,BufferedImage image)
	 {
	  int skinlen=skin.length;
	  int[] skinloc=new int[skinlen];
	  int[] blueloc=new int[512*512];
	  int k=0;
	  String p="";
	  for(int n=0;n<skinlen;n++)
	  {
	   p=skin[n];
	   skinloc[n]=Integer.parseInt(p);
	  }
	  
	  int[][] rgb=new int[550][550];
	  int red,green,blue;
	  
	  for(int i=0;i<image.getHeight();i++)
	  {
	  
	   for(int j=0;j<image.getWidth();j++)      
	   {
	   
		rgb[i][j]  = image.getRGB(i,j);
		red   = (rgb[i][j] >> 16) & 0xff;
		green  = (rgb[i][j] >> 8) & 0xff;
		blue  = (rgb[i][j]) & 0xff;
		 
		if((blue >= red) && (blue >= green))
					{
					   blueloc[k]   = i;
					   blueloc[k++] = j;
					   k++;
					}
				
	   }
	   
	  }
			
	  int com=0;
	  
			for (int pp=0;pp<skinloc.length;pp+=2)
	  {
	   for(int s=0;s<blueloc.length;s+=2)                
	   {
					if(( skinloc[pp]==blueloc[s] ) && ( skinloc[pp+1]==blueloc[s+1] ))
					{
						comloc[com]   = skinloc[pp];
						comloc[com+1] = skinloc[pp+1];    //common locations
						com+=2; 

					}
	   }
	  }
	  com =comloc.length;
	  comb2= com/2;
	  int row_col=(int)Math.sqrt(comb2+0.5);
	  int pixel,comblue;
	  int[][] a=new int[550][550];
	  for(int w=0,r=0;w<row_col;w++)         //initialisation of array
	  {
	  
	   for(int v=0;v<row_col;v++)
	   {
		pixel=image.getRGB(comloc[r],comloc[r++]);
		comblue = (pixel) & 0xff;
		a[w][v]=comblue;
		r++;
	   }
	   
	  }
	  
	  //dwt starts here 
	  int row  = a.length;
	  int column = a[0].length;
	  int[][] mat =  new int[row][column];
	  int[][] mat2 =  new int[row][column];

	  for(int y=0;y<row_col;y++)
	  {
	   for(int z=0;z<row_col;z++)
	   {
		mat[y][z]    = a[y][z]+a[y][z+1];
		mat[y][z+(column/2)]  = a[y][z]-a[y][z+1];
	   }
	  }
	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;q<row;q++)
	   {
		mat2[q][r]   = mat[q][r]+mat[q+1][r];
		mat2[q+(row/2)][r] = mat[q][r]-mat[q+1][r];
	   }
	  }
		
	  return mat2;
	 }
	  
	}  


	class Embedding
	{
	 
	 public  int[][] lehmer(int array1[][])
	 {
	  int rw_len = array1.length;
	  int col_len = array1[0].length;
	  int tot_len = rw_len*col_len;
	  int[][] loc_ary=new int[tot_len][2];
	  boolean[][][] chk_avl=new boolean[rw_len][col_len][1];
	  
	  for(int e=0;e<rw_len;e++)
	  {
	   for(int f=0;f<col_len;f++)
	   {
		chk_avl[e][f][0]=false;
	   }
	  }
	  int loc_ary_rw=0;
	  int counter=0;
	  do
	  {
	   int i=0;
	   int j=0;
	   
	   while(chk_avl[i][j][0]==true)
	   {
		j++;
		if(j==(col_len-1))
		{
		 j=0;
		 i++;
		}
		if(i==(rw_len-1))
		{
		 i=0;
		}
	   }
	   loc_ary[loc_ary_rw][0]=i;
	   loc_ary[loc_ary_rw][1]=j;
	   chk_avl[i][j][0]=true;
	   loc_ary_rw++;
	   counter++;
	   int t=(i*col_len)+j;
	  //lehmer part is written here
	   int n=(int)Math.pow(2,16)+1;
	   int g=75;
	   int random=g*t%n+1; 
	  //lehmer part ends here
	   random=random%tot_len;
	   i=random/rw_len;
	   j=random%col_len;
		
	   while(chk_avl[i][j][0]==true)
	   {
		j++;
		if(j==(col_len-1))
		{
		 j=0;
		 i++;
		}
		if(i==(rw_len-1))
		{
		 i=0;
		}
	   }
	 
	   loc_ary[loc_ary_rw][0]=i;
	   loc_ary[loc_ary_rw][1]=j;
	   chk_avl[i][j][0]=true;
	   loc_ary_rw++;
	   counter++;
	  
	  }while(counter<tot_len);
	  
	  return loc_ary;   
	 }

	 public int[][] embedd_values(int[][] loc_ary,int[] info,BufferedImage B)/>
	 {
	  int length      =loc_ary.length;
	  int e               =length/2;
	  int row_col     =((int)Math.sqrt(e))*2;

	  int rgb,blue;
	  int[][] modi_mat=new int[row_col][row_col];
	  int i=0;

	  for(int x=0;x<row_col;x++)
	  {
	   for(int y=0;y<row_col;y++)
	   {
		rgb=b.getRGB(loc_ary[i][0],loc_ary[i][1]);
		i++;
		blue=(rgb)& 0xff;
		modi_mat[x][y]=blue;
		rgb=0;
		blue=0;

	   }
	  }


	  int c=0;
	  int tmp;

	  for(int v=0;v<row_col;v++)
	  {
	   for(int w=0;w<row_col;w=w+2)
	   {
		tmp=0;

		if(modi_mat[v][w]==modi_mat[v][w+1])
		 continue;

		switch(info[c])
		{
		 case 0:
		   if(modi_mat[v][w]>modi_mat[v][w+1])
		   {
			 tmp                           =modi_mat[v][w];
			 modi_mat[v][w]        =modi_mat[v][w+1];
			 modi_mat[v][w+1]   =tmp;

		   }    
		   break;
		   
		 case 1:
		   if(modi_mat[v][w]<modi_mat[v][w+1])
		   {
			tmp                           =modi_mat[v][w];
			modi_mat[v][w]        =modi_mat[v][w+1];
			modi_mat[v][w+1]   =tmp;
	  
		   }    
		   break;
		}
		c++;
	   }
	  }
		   
	  return modi_mat;

	 
	 } 
	 
	 
	 public void merge(int comloc[],int modified_matrix[][])
	 {
	  LoadImage lm=new LoadImage();
	  String[] skinp=new String[200000];
	  skinp=lm.skindet();
	  BufferedImage buf=lm.retimg();
	  
	 
	  int [][]mat3=new DWT().dwtFunc1(skinp,buf);   //mat2 is returned here
	 
	  int row=mat3.length;
	  int column=mat3[0].length;
	 
	  int a=0;
	  int b=0;
	 
	  for(int e=(row/2)-1;e<row;e++)
	  {
	   for(int f=(column/2)-1;f<column;f++)
	   {
		mat3[e][f]=modified_matrix[a][b];
		b++;
	   }
	   a++;
	  }
	  int[][] x=new int[row][column];  
	  int[][] y=new int[row][column];
	  LoadImage im=new LoadImage();
	  im.loadimgfile();
	  BufferedImage b1=im.retimg();
	  int len=comloc.length;
	  int[] pel=new int[len];
	  

	  for(int r=0;r<column;r++)
	  {
	   for(int q=0;a<row;q++)
	   {
		x[q][r]  =(mat3[q][r]+mat3[q+(row/2)][r])/2;
		x[q+1][r]=mat3[q][r]-x[q][r];
	   }
	  }

	  for(int f=0;f<row;f++)
	  {
	   for(int z=0;z<column;z++)
	   {
		y[f][z]   =(x[f][z]+x[f][z+(column/2)])/2;
		y[f][z+1] =x[f][z]-y[f][z];
		}
		
	  }
	   int xx=0,yy=0;
	   
	   for (int i=0;i<row;i++)
	   {
		for(int j=0;j<column;j++,yy++,xx++)
		{
		 pel[yy]=b1.getRGB(comloc[xx],comloc[xx++]);
		 pel[yy]=setValue(pel[yy],y[i][j]);
		 
		 
		 
		}
		
	   }
	   new ReprintImage().drawimage(pel,comloc);
	 }
	 public int setValue(int argb, int val) 
	 { 
	  argb= (argb & 0xff) | val; 
	  return argb;
	 }
	}

	class ReprintImage
	{

	 public void drawimage(int[] pixelement,int[] comlocation)
	 {
	  LoadImage ld=new LoadImage();
	  ld.loadimgfile();
	  BufferedImage bim=ld.retimg();
	  for(int i=0;i< comlocation.length;i++)
	  {
	   bim.setRGB(comlocation[i],comlocation[i+1],pixelement[i]);
	  }
	  String format="jpeg";
	 try
	 {
	  ImageIO.write(bim,format, new File("StegoImage.jpeg"));
	  }
	  catch(java.io.IOException exp)
	  {
	   }
	 }
	}

	class Extraction extends JFrame
	{
	 char[] ar;
	 BufferedImage image;
	 String spath;
	 public void initUI()
	 {
	  JFileChooser fileopen = new JFileChooser();        //Choosing a file
	  FileFilter filter = new FileNameExtensionFilter("jpeg files", "jpeg");
	  fileopen.addChoosableFileFilter(filter);
	  int ret = fileopen.showDialog(null, "Open file");
	  JButton next=new JButton("NEXT-->");
	  try
	  {
	   if (ret == JFileChooser.APPROVE_OPTION) 
	   {
		JPanel panel=new JPanel();
		File file = fileopen.getSelectedFile();
		spath=file.getAbsolutePath();
		image = ImageIO.read(new File(spath));
		ImageIcon imgicon=new ImageIcon(spath);
		JLabel label=new JLabel(); 
		label.setIcon(imgicon);
		panel.add(label);
		panel.add(next);
		getContentPane().add(panel);
	   }
	 
	   setVisible(true);
	   setTitle("SKIN TONE STEGANOGRAPHY");
	   setIconImage(Toolkit.getDefaultToolkit().getImage("cartoon.gif"));
	   setSize(600,600);
	   setLocationRelativeTo(null);
	   setDefaultCloseOperation(EXIT_ON_CLOSE);
	   next.addActionListener(new ActionListener()    //NEXT button to move to the text frame
	   {
		public void actionPerformed(ActionEvent ae)
		{
		 idwt();
		 FinalImageandText findtxt=new FinalImageandText();
		 setVisible(false);
		}
	   });
	  }
	  catch(IOException ioe)
	  {}
	  
	  
	 }
	 
	 public void idwt()
	 {
	  String[] skinpix = new String[200000];
	  LoadImage ldi = new LoadImage();
	  skinpix = ldi.skindet();
	  image=ldi.retimg();
	  int[][] hh_dwt1 = new DWT().dwtFunc(skinpix,image);
	  int row=hh_dwt1.length;
	  int col=hh_dwt1[0].length;
	 
	  int tot=row*col;
	  int tot_pair=tot/2;

	  Embedding ed=new Embedding();
	  
	  
	  int []bin_st=new int[tot_pair];
		 
	  int location_a[][]=ed.lehmer(hh_dwt1);

	  int len=location_a.length;
	  int rgb1;
	  int []blue1=new int[len];
	  for(int i=0;i<len;i++)
	   for(int j=0;j<2;j++)
	   {
		rgb1= image.getRGB(location_a[i][j],location_a[i][j++]);
		blue1[i]  = (rgb1) & 0xff;
	   }
	   
	  for(int k=0,z=0;k<len;k=k+2)
	  {
	   if(blue1[k]<blue1[k++])
	   {
		bin_st[z]=0;
		z++;
	   }
	   else
	   {
		bin_st[z]=1;
		z++;
	   }
			}

	//binary to text
	  int dec;
	  int y=0;
	  int bin_st_len=bin_st.length;
	  ar=new char[(bin_st_len/8)+1];
	  char letter;
	  for(int e=0;e>bin_st_len;e=e+8)
	  {
	   dec=0;
	   dec=(int)Math.pow(2,7)*bin_st[e];
	   dec+=(int)Math.pow(2,6)*bin_st[e+1];
	   dec+=(int)Math.pow(2,5)*bin_st[e+2];
	   dec+=(int)Math.pow(2,4)*bin_st[e+3];
	   dec+=(int)Math.pow(2,3)*bin_st[e+4];
	   dec+=(int)Math.pow(2,2)*bin_st[e+5];
	   dec+=(int)Math.pow(2,1)*bin_st[e+6];
	   dec+=(int)Math.pow(2,0)*bin_st[e+7];     
	  
	   letter =(char)dec;
	   ar[y]=letter;
	   y++;
	 
	  }
	 } 
	 
	 public char[] ret_text()
	 {
	  return ar;
	 }
	}

	class FinalImageandText extends JFrame
	{

	 public FinalImageandText()
	 {
	 try{
	  Extraction ex=new Extraction();
	  char[] arr=ex.ret_text();
	  String text=new String(arr);
	  String path =new LoadImage().returnpath();
	  BufferedImage bufimg = ImageIO.read(new File(path));
	  JTextArea hiddentxt=new JTextArea("",5,20);
	  hiddentxt.append(text);
	  JPanel panel=new JPanel();
	  ImageIcon imgicon=new ImageIcon(path);
	  JLabel label=new JLabel(); 
	  label.setIcon(imgicon);
	  panel.add(label);
	  panel.add(hiddentxt);
	  getContentPane().add(panel);
	  setSize(400,400);
			setLocation(200,200);
			setVisible(true);
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  }
	  catch(IOException ioe){}
	 }
	 
	}






Was This Post Helpful? 0
  • +
  • -

Page 1 of 1