title: How to merge pixels WITHIN an image based on their rgb values in python?
body: <p>So far , I've divided an image into blocks of specific size and these blocks have the mean color of the original block. Now, I have to merge these blocks based on their similarity,  where each block contains a single pixel value(mean color value). For this , I have been trying to merge pixels within an image based on their rgb values. So far I've not found anything that would help me with this. So kindly help me to solve this problem. What I've done so far...</p>
  
  <p>x and y are the block sizes. Here x=y=16. </p>
  
  <p>Input :<a href="https://i.stack.imgur.com/gJWT8.png" rel="nofollow noreferrer">Original Image</a>
  Output: <a href="https://i.stack.imgur.com/VUzoc.png" rel="nofollow noreferrer">Processed image</a>
  I've not implemented anything after this since I don't know how to proceed further. Now I've to group the pixels in the processed image based on their similarity.</p>
  
  <pre><code>i=0
  j=0
  m=16
  n=16
  
  l=[]   
  data = np.zeros( (256,256,3), dtype=np.uint8 )
  while(m&lt;=256):
      while(n&lt;=256):
          l=image[i:m,j:n]
  
          print(l)
          r=0
          g=0
          b=0
          for q in range(len(l)):
              for w in range(len(l)):
                  r=r+l[q][w][0]
                  g=g+l[q][w][1]
                  b=b+l[q][w][2]
  
          r=r/(x*y)
          b=b/(x*y)
          g=g/(x*y)
          k=[r,g,b]
          data[i:m,j:n]=k
          j=j+16
          n=n+16
  
      i=i+16
      m=m+16
      j=0
      n=16
  img = smp.toimage( data )
  data1 = np.asarray( img, dtype="int32" )
  
  
  cv2.imwrite(os.path.join('G:/AI package/datasets/_normalized',filename),data1)
  </code></pre>