在相同像素上的setPixel()和getPixel()之后,位图像素值有所不同 [英] Bitmap pixel values differ after setPixel() and getPixel() on same pixel

查看:380
本文介绍了在相同像素上的setPixel()和getPixel()之后,位图像素值有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个类项目开发一个隐写术应用程序,允许用户在另一个图像中编码一个秘密消息图像。在修改像素整数值以包含消息值之后,我使用 Bitmap.getPixel(x,y)来检索像素信息。然后,我使用 Bitmap.setPixel(x,y)将修改后的像素放置在位图中。解码图像并检索隐藏的消息后,我注意到一些像素变色。我发现某些像素在修改后不包含正确的值。如果我使用

  int before = encoded_value; 
bitmap.setPixel(x,y,before);
int after = bitamp.getPixel(x,y);

在==之前的大部分像素之后,但在某些之前!=之后。如果我通过添加或减去之前不断修改(这只会稍微改变消息图像中的颜色),然后再次设置像素,则前后的值仍然不同。在解码图像中关闭几个像素并不是什么大问题。但是,如果其中一个问题像素出现在我编码消息图像信息(图像尺寸)的位置,解码后的尺寸通常将包含非数字值,例如2q3x300。当应用程序尝试将此字符串转换为整数值时,将会发生异常。我也尝试使用整数缓冲区获取和设置像素,但是相同的像素会导致问题。另外通过一些调试,我发现某些像素会导致问题,并且如果使用加倍的维度字符串213213x300300对图像进行编码,字符串将从图像解码为2q32q3x300300,某些值会导致问题。我不确定这是从图像文件解码位图时开始的问题,还是getPixel()和setPixel()方法中的错误。看起来某些像素会导致一点点关闭。在上面的例子1(其中包含ascii值为49或00110001)被解码为q(其中包含ascii值113或01110001),只有一个比特值与该集合不同,并且可能会导致比特问题。位图位于ARGB_8888中,因此应该能够包含任何也可以包含在整数值中的值。为了立体拍摄,我正在修改alpha,red,green和blue值的至少2位来存储1个字节。我将消息图像缩小为RGB_332,以便它可以包含在最少位中。

 我放-53029643 = 1111 1100 1101 0110 1101 0100 1111 0101另一个例子是试图设置像素为-53029643。 
并得到回报-53029387 = 1111 1100 1101 0110 1101 0101 1111 0101
---------------------------- ------------------------ XOR
= 0000 0000 0000 0000 0000 0001 0000 0000 = 256

尽管这两者在绿色值的最小位数上只有不同。通过从每一位获取至少2位来解码该整数值得到00100101而不是00100001,这些字节的形式为RRRGGGBB,因此绿色值从000变为001,并且所得到的位图将包含具有绿色值为001000而不是000000,因为解码后的位图在RGB_565中,并且从绿色开始的十进制值是8而不是0.这里3个png图像首先是载体图像(将消息图像编码到图像中)第二个图像是消息图像(在载体图像中编码的图像),第三个是从载体图像解码后的消息图像。

载体图像





留言图片



解码的信息图像。此图像为8位颜色,红色或绿色的像素是受此错误影响的像素。

解决方案

此缺陷在android api中似乎与我遇到的相同问题有关。由于在从像素阵列创建位图或解码到消息图像时无法解决此问题,因此我必须在图像解码后使用图像过滤。我使用的中值过滤器已被修改为针对问题像素,这里是带有和不带中值过滤器的图像示例。



未过滤





过滤


I'm developing a steganography app for a class project which allows a user to encode a secret message image with in another image. I use Bitmap.getPixel(x,y) to retrieve pixel information after modifying the pixel integer value to contain the message value. I then used Bitmap.setPixel(x,y) to place the modified pixel in the bitmap. After decoding the image and retrieving the hidden message I've noticed some pixels were discolored. I've found that certain pixels do not contain the correct value after being modified. if I use

int before = encoded_value;
bitmap.setPixel(x,y, before);
int after = bitamp.getPixel(x,y);

for most of the pixels before==after however on some before!=after. If I continuously modify before by adding or subtracting one( this only changes the color slightly in the message image ) and then set the pixel again the values of before and after still differ. Having a few pixels off in the decoded image wouldn't be that big of a deal. However, when one of the problem pixels shows up where I encoded the message image information( the images dimensions ) the decoded dimensions will usually contain a non digit value such as "2q3x300". Which will through an exception when the application tries to turn this string into integer values. I've also tried to get and set pixels using a integer buffer however the same pixels cause problem. Also through some debugging I've found that certain pixels cause problems and certain values cause problems if I encode the image with with a doubled dimension string "213213x300300" the string is decoded from the image as "2q32q3x300300". I'm not sure if this is a problem that start when decoding the bitmap from an image file or its a bug in the getPixel() and setPixel() methods. It seems that certain pixels cause a bit to be off. In the above example 1( which contains an ascii value of 49 or 00110001) is decoded as q( which contains an ascii value of 113 or 01110001) only a single bit value differs from the set and get however it can cause bit problems. The Bitmap is in ARGB_8888 and thus should be able to contain any value that can also be contained in an integer value. For the stereography to work I'm modifying the least 2 bits of the alpha, red, green and blue values to store 1 byte. I reduce the message image to RGB_332 so that It can be contained in the least bits. One more example is trying to set a pixel to -53029643.

I put           -53029643 = 1111 1100 1101 0110 1101 0100 1111 0101
and get returns -53029387 = 1111 1100 1101 0110 1101 0101 1111 0101
                ----------------------------------------------------XOR
                          = 0000 0000 0000 0000 0000 0001 0000 0000 = 256 

Although these two only differ in the least bit of the green value. The decoding of this integer value by taking the least 2 bits from each bit yields 00100101 instead of 00100001 the bytes are in the form RRRGGGBB thus green value is changing from 000 to 001 and the resulting bit map will contain a pixel with a green value of 001000 instead of 000000 since the decoded bit map is in RGB_565 and thuse the decimal value from green is 8 instead of 0. Here the 3 png images the first is the carrier image( the image that has the message image encoded into it) the second is the message image( the image that is encoded in the carrier image) and the third is the message image after it has been decoded from the carrier image.

carrier image

message image

decoded message image. This image is in 8 bit color the pixels that are more red or green are the ones affected by this error.

解决方案

This defect in the android api appears to relate to the same issue i'm having. Since there was no way to solve this issue while creating the bitmap from a pixel array or when decoding into the message image I've had to resort to using image filtering after the image has been decoded. I'm using a median filter that has been modified to target problem pixels here is an example of an image with and without the median filter.

unfiltered

filtered

这篇关于在相同像素上的setPixel()和getPixel()之后,位图像素值有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆