Important: Use custom search function to get better results from our thousands of pages

Use " " for compulsory search eg:"electronics seminar" , use -" " for filter something eg: "electronics seminar" -"/tag/" (used for exclude results from tag pages)


Tags: java, steganography, image processing,
 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to hide an image in another image using dwt in java
Post: #1

I am doing my final year project in computer engineering. I want to hide an image into another image using dwt method of steganography in java. Can anybody send me the sample code for doing this
Post: #2

java Syntax (Toggle Plain Text)
//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){}
}

}

Please Use Search http://projects-seminars.net/search.php wisely To Get More Information About A Seminar Or Project Topic
 


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Image Verification
(case insensitive)
Please enter the text within the image on the left in to the text box below. This process is used to prevent automated posts.

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Image Verification
(case insensitive)
Please enter the text within the image on the left in to the text box below. This process is used to prevent automated posts.

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  large scale power generation using fuel cell ppt and document and abstract Guest 0 0 Today 06:17 AM
Last Post: Guest
  patient fall detection using hip and abdomen sensors Guest 1 0 24-03-2017 09:36 AM
Last Post: jaseela123
  child tracking system using android phones srs ppt Guest 1 0 24-03-2017 09:25 AM
Last Post: jaseela123
  concealed weapon detection using digital image processing ppt Guest 1 0 23-03-2017 10:08 AM
Last Post: jaseela123
  ppt on electrical power generation system using railway track slides Guest 1 0 22-03-2017 04:09 PM
Last Post: jaseela123
  aqua communication using modem ppt download Guest 1 0 22-03-2017 03:41 PM
Last Post: jaseela123
  matlab source code for image compression using dct Guest 1 0 21-03-2017 01:06 PM
Last Post: jaseela123
  pdf double acting hacksaw machine using scotch yoke mechanism Guest 3 0 21-03-2017 11:57 AM
Last Post: jaseela123
  ppt on double acting hacksaw machine by using scotch yoke mechanism Guest 1 0 21-03-2017 11:34 AM
Last Post: jaseela123
Thumbs Down image forgery detection using DCT Guest 2 0 15-03-2017 09:18 AM
Last Post: jaseela123
This Page May Contain What is how to hide an image in another image using dwt in java And Latest Information/News About how to hide an image in another image using dwt in java,If Not ...Use Search to get more info about how to hide an image in another image using dwt in java Or Ask Here

Options: