Replace the color of block in gray scale image in Python


I have an Image of 128×128 pixels in which, there are 1024 blocks of 4×4 pixels each.

If the coordinates of the first block areblock1= im[0:4, 0:4], then I want to replace the colour of pixels into a specific pixel intensity(or colour),example-128.

So what I want to do is I want to change the colour of the image something like this-


Note that the image is in the grayscale.Thanks in advance.

Asked By: Hero31



You can do that like this:

colorValue = 150
im[0:4,0:4] = colorValue
Answered By: flamelite