0

I have used the following code to extract pixel values of an image.

    int[][] pixels = new int[w][h];

    for( int i = 0; i < w; i++ )
        for( int j = 0; j < h; j++ )
            pixels[i][j] = imgBuffer.getRGB( i, j );

Now I modified the pixel values and drew the new figure by

    BufferedImage image=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
    for( int i = 0; i < w; i++ )
        for( int j = 0; j < h; j++ )
            image.setRGB( i, j,pixels[i][j] );

Now when i try to get the values by

    int[][] pixels1 = new int[w1][h1];

    for( int i = 0; i < w1; i++ )
        for( int j = 0; j < h1; j++ )
            pixels1[i][j] = imgBuffer1.getRGB( i, j );

This is giving me completely new values

  • 2
    Could you produce a http://sscce.org/ for this? – Cruncher Oct 02 '13 at 18:58
  • To make an SSCCE of a problem involving images, it will be necessary to hot-link to some small (in bytes) images, or generate them (in memory) at run-time. – Andrew Thompson Oct 02 '13 at 19:01
  • @jefflunt Huh? 1) I was simply pointing out that that an SSCCE involving images requires ..an image. 2) While *I* or *you* can embed images in SO, I don't think the OP has enough rep. (not sure though) 3) Hot-linked images can work easily as well if the images are hot-linked from an average 'image upload site' and.. 4) Thanks for the info., but I am 'already aware of it'. E.G. as seen in [this answer](http://stackoverflow.com/a/6296381/418556), [this answer](http://stackoverflow.com/a/10862262/418556), [this answer](http://stackoverflow.com/a/10836833/418556).. ;) – Andrew Thompson Oct 02 '13 at 19:19
  • I have written the code for jpeg images. This happens with any jpeg image. I have actually modified the LSB of the initial image to get the new pixel values. With the new pixel values I drew the modified image. Now to get back the changes in the LSB i need to use the pixels of the modified image. There is a glitch though, this is not the same as one with which I drew the modified image. – Vinith Vemana Oct 02 '13 at 19:22
  • I was trying to write an Image Steganography program. – Vinith Vemana Oct 02 '13 at 19:24
  • *"I have written the code for jpeg images."* I Think that is the first mistake here. Unless saving the JPEG as 'no compression' the final image will be different to the original. But as mentioned by @Cruncher over 30 minutes ago, post an SSCCE. Then I could have told you that 30 minutes ago, and have tested the code by 25 minutes ago. ..Are you getting the picture I'm painting, here? – Andrew Thompson Oct 02 '13 at 19:33
  • yeah thank you, sorry abt the same. Shall do it soon. – Vinith Vemana Oct 02 '13 at 19:39
  • am sorry the code is too long to be posted here and cant be compressed further but thank you that actually ans my question i need lossless compression. Thank you Sir..:) – Vinith Vemana Oct 02 '13 at 19:49

1 Answers1

0

You're not showing where imgBuffer and imgBuffer1 come from. Are they the same object, or are they two different objects referring to the same buffer in memory, or are they two different objects referromg to entirely different buffers? If they don't point to the same buffer in memory then it stands to reason that they at least could, and probably would, produce different outputs.

Also, have you tried doing simple tests, like using a solid color buffer (say, solid blue) for the input and extracting the pixel data multiple times to see if it's different from the input? Also, if it's different, is it at least consistently different (the same shift happens between one color and the next, the same color always comes out the second time regardless of the input, etc.)?

Part of what your question is currently lacking is the process by which you've tried to determine why this is happening - what have you already tried in order to figure out what's happening, and what were the results?

jefflunt
  • 33,527
  • 7
  • 88
  • 126
  • Well i have taken an image in `imgBuffer` modified the pixels now i have taken the pixel values of the modified one and compared it with the image formed by using these values(modified image in `imgBuffer1`). They are not being the same. – Vinith Vemana Oct 02 '13 at 19:15
  • I have modified the LSB of the initial image to form the modified image. – Vinith Vemana Oct 02 '13 at 19:16
  • Ok, I think I understand. So, you're comparing the values in `pixels` to the values in `pixels1` and wondering why **those** aren't the same? Is that correct? – jefflunt Oct 02 '13 at 19:19
  • @VinithVemana - Ah, well it seems that you're creating two separate 2D arrays to store the pixel data. When you modify the bufffer it does NOT also modify the pixel arrays that you declared, so making the change in once place doesn't affect the other. I hope that helps. Basically, you're making an independent copy of the data into a 2D array, then modifying the buffer, then copying the data into another, separate 2D array which is in no way connected to the first 2D array, nor the image buffer. So the two sets of `pixels` and `pixels1` arrays are independent of each other and the image buffer. – jefflunt Oct 02 '13 at 19:34
  • So, the reason that `pixels` and `pixels1` are different is because they are copies of the data - one before the modification was made, and one after the modification was made. They will, therefore, be different. – jefflunt Oct 02 '13 at 19:34
  • I have actually modified `pixels` and drew the modified image. Now from the modified image i retrieved `pixels1`. SO basically they both correspond to the modified image. – Vinith Vemana Oct 02 '13 at 19:38
  • Is the data consistently inconsistent? Is it different in some regular, always-mutated-the-same-way sort of way? – jefflunt Oct 02 '13 at 20:19
  • @jefflunt thank you, i actually got the flaw in my code. I have been using it for jpeg images which is lossy hence the problem. – Vinith Vemana Oct 02 '13 at 20:53
  • Ah. Interesting. Glad you figured it out. – jefflunt Oct 02 '13 at 21:38