title: How to change pixels in an image?
body: <p>I want to make changes to the pixels, but the pixels in the new image file are different from the pixels I've changed.</p>
  
  <p>When I check the cycles one by one, the pixels change correctly, but when I create the new picture, it's different.</p>
  
  <p>How can I solve the problem?</p>
  
  <pre class="lang-py prettyprint-override"><code>def str2bin(data): 
          strbin = []  
  
          for i in data: 
              strbin.append(format(ord(data), '08b')) 
          return strbin 
  
  def hide_str(img, data):
      datalist = str2bin(data)
      lendata = len(datalist)
  
      h, w, ch = 0, 0, 0
  
      for i in range(lendata):
          for j in range(0, 8):
              if ch &gt; 2:
                  ch = 0
                  w += 1
  
              val = img[h, w]
  
              if (datalist[i][j] == '0') &amp; ( val[ch] % 2 != 0):
                  val[ch] -= 1
  
              if (datalist[i][j] == '1') &amp; ( val[ch] % 2 == 0):
                  val[ch] += 1
  
              ch += 1
  
              img[h, w] = tuple(val)
  
      return img
  </code></pre>
  
  <p>Example my string is = <code>"T"</code> and my string binary = <code>"01010100"</code>:</p>
  
  <pre><code>img = cv2.imread("image.jpg")
  img[0, 0] output [0, 0, 0]
  cv2.imwrite("image2.jpg", hide_str(img, str))
  img2 = cv2.imread("image2.jpg")
  img2[0, 0] output [0, 9, 0]
  </code></pre>
  
  <p>Other pixels are the same as I want.</p>