java - Steganography Lsb information hold capacity -
i know using lsb means u can store messages @ around 12% of image carrier size. made java program splits message n fragments , fills image carrier these fragments until 12 % occupied.i cropping image,the message wouldn't lost. problem resulting image distorted , different original image.i thought if fill 12% of image,more lsb of image,the image wouldn't distorted.
int numhides = imlen/(totallen*data_size); // number of messages can store in image int offset = 0; for(int h=0; h < numhides; h++) //hide frags, numhides times for(int i=0; < num_frags; i++) {//num_frags ..the number of fragments hidestegofrag(imbytes, stegofrags[i], offset);//the method hides fragment picture starting @ offset position offset += stegofrags[i].length*data_size; } private static boolean hidestegofrag(byte[] imbytes,byte[] stego,int off){ int offset=off; (int = 0; < stego.length; i++) { // loop through stego int byteval = stego[i]; for(int j=7; j >= 0; j--) { // loop through 8 bits of stego byte int bitval = (byteval >>> j) & 1; // change last bit of image byte stego bit imbytes[offset] = (byte)((imbytes[offset] & 0xfe) | bitval); offset++; } } return true; } the code transforming buffered image bits
private static byte[] accessbytes(bufferedimage image) { writableraster raster = image.getraster(); databufferbyte buffer = (databufferbyte) raster.getdatabuffer(); return buffer.getdata(); } the code creates new image provided name , buffered image of source image
public static boolean writeimagetofile(string imfnm , bufferedimage im){ try { imageio.write(im, "png", new file(imfnm)); } catch (ioexception ex) { logger.getlogger(multisteg.class.getname()).log(level.severe, null, ex); } return true; }

the output image have posted 16-color paletted image.
the data seeing shows have applied changes palette index, not colors of image. reason seeing distortion because of way palette organized, aren't modifying lsb of color, you're modifying lsb of index, change different (and noticeable, can see) color. (actually, you're modifying lsb of every other index, 16-color form 4 bits per pixel, 2 pixels per byte.)
it looks loaded raw image data , didn't decode in rgb color information. algorithm work on raw rgb (or raw grayscale) data; 3 bytes (or 1 grayscale) per pixel. need convert image rgb888 or similar before operate on it. when save it, need save in lossless, full color (unless can fit colors in palette) format too, otherwise risk losing information.
your problem doesn't lie in steganography portion of program, in loading , saving of image data itself.
when load image data, need convert rgb format. convenient format application bufferedimage.type_3byte_bgr, stores each pixel 3 bytes in blue, green, red order (so byte array b,g,r,b,g,r,b,g,r,...). can so:
public static bufferedimage loadrgbimage (string filename) { // load original image bufferedimage originalimage = imageio.read(filename); // create buffer converted image in rgb format bufferedimage rgbimage = new bufferedimage(originalimage.getwidth(), originalimage.getheight(), bufferedimage.type_3byte_bgr); // render original image buffer, changes destination format rgbimage.getgraphics().drawimage(originalimage, 0, 0, null); return rgbimage; } if working source images in bgr format anyways, can make 1 easy optimization not convert image if it's in format want:
public static bufferedimage loadrgbimage (string filename) { bufferedimage originalimage = imageio.read(filename); bufferedimage rgbimage; if (originalimage.gettype() == bufferedimage.type_3byte_bgr) { rgbimage = originalimage; // no need convert, return original } else { rgbimage = new bufferedimage(originalimage.getwidth(), originalimage.getheight(), bufferedimage.type_3byte_bgr); rgbimage.getgraphics().drawimage(originalimage, 0, 0, null); } return rgbimage; } you can use converted image of operations. note byte array converted image contain 3 * rgbimage.getwidth() * rgbimage.getheight() bytes.
you shouldn't have make changes current image saving code; imageio detect image rgb , write 24-bit png.
Comments
Post a Comment