我正在尝试构建Java类以实现LSB图像隐写术。
我正在为此使用OpenCV 3.2。
我在类encodeImage(String message)
的方法LSBImageStego
中编写了编码逻辑,它将获取秘密消息并将其编码在给定的Cover Image中(该封面图像将由Constructor获取)。 / p>
我可以通过更改LSB位来修改Pixel值(我仅更改单个通道的LSB位)。我正在使用MatObj.put(row,col,data)
写回新的Pixel值。在put()
之后打印这些新的Pixel值,并且Pixel值已成功更改。
我要返回CoverImage(因为我已经通过编码消息进行了更改),并通过imwrite()
保存了图像。
现在,当我尝试解码EncodedImage时,我发现该图像具有旧的Pixel值,但没有Encoded Pixel值。这表明,尽管我在{{1}中使用put()
编写了EncodedPixel值}},encodeImage(String message)
对象未返回。
这是Mat
类的encodeImage(String message)
的代码
LSBImageStego
而我正在另一类的/**
getBeautifiedBinaryString()
Returns a binary string of length 8 by taking a number.
This function is working perfectly.
*/
/**
binaryStringMessage
is a private String in the class & contains the Binary form of the Secret Message.
*/
/**
This function takes Secret Message and replaces 2 bits from LSB(First Channel of Image)
with the bits of Message
*/
public Mat encodeImage(String message){
/**
//coverImage is a Mat Object & following is the code in constructor of a class
this.coverImage = coverImage;
this.coverImage_rows = (int)coverImage.size().height;
this.coverImage_cols = (int)coverImage.size().width;
*/
System.out.println("Number of Rows : " + this.coverImage_rows);
System.out.println("Number of Columns : " + this.coverImage_cols);
// This is used as a pointer in the BinaryString ,so that,it can be embedded easily
int messageStringCounter = 0;
for(int rowCount = 0 ; rowCount <= this.coverImage_rows -1 ; rowCount++){
for(int colCount = 0; colCount <= this.coverImage_cols -1 ; colCount++){
try{
if(messageStringCounter > this.binaryStringMessage.length() - 2 ){
System.out.println("RETURNING pic");
return this.coverImage;
}
String newLSBBits = this.binaryStringMessage.substring(messageStringCounter , messageStringCounter+2);
System.out.println(">> "+messageStringCounter + " >> " + newLSBBits);
messageStringCounter+=2;
System.out.println("ORIGINAL : "+this.getBeautifiedBinaryString(this.coverImage.get(rowCount , colCount)[0]));
String modifiedBinaryString = this.getBeautifiedBinaryString(this.coverImage.get(rowCount , colCount)[0]).substring(0 , this.getBeautifiedBinaryString(this.coverImage.get(rowCount , colCount)[0]).length() - 2) + newLSBBits;
System.out.println("MODIFIED : " + modifiedBinaryString);
double[] data = new double[3];
data[0] = Integer.parseInt(modifiedBinaryString , 2);
data[1] = this.coverImage.get(rowCount , colCount)[1];
data[2] = this.coverImage.get(rowCount , colCount)[2];
// Im checking whether the Pixel values are being changed as expected or not.
System.out.println("BEFORE : " + this.coverImage.get(rowCount , colCount)[0]);
this.coverImage.put(rowCount , colCount , data);
System.out.println("AFTER : " + this.coverImage.get(rowCount , colCount)[0]);
// The Pixel values were changed as expected
}catch(Exception e){
System.out.println("Exception Handled");
}
}
}
return this.coverImage;
}
中调用上述方法,如下所示。
main()
我处理了其他逻辑,例如Message的binaryString的长度为奇数或偶数等...
唯一的问题是我要保存到磁盘的EncodedImage,它不包含Encoded Pixel Values。
请提出建议。
预先感谢:)
答案 0 :(得分:0)
JPEG会进行有损压缩。因此,已编码的像素值将丢失,并且很有可能与原来的原始像素值相同,因为仅更改了像素强度的LSB。但是事实并非如此。 PNG或位图。
阅读this以获取有关JPEG压缩算法的更多信息。