简体   繁体   English

在Python中替换灰度图像中的块颜色

[英]Replace the color of block in gray scale image in Python

I have an Image of 128x128 pixels in which, there are 1024 blocks of 4x4 pixels each. 我有一个128x128像素的图像,其中有1024个4x4像素的块。

If the coordinates of the first block are block1= im[0:4, 0:4] , then I want to replace the colour of pixels into a specific pixel intensity(or colour),example-128. 如果第一个块的坐标为block1= im[0:4, 0:4] ,那么我想将像素的颜色替换为特定的像素强度(或颜色),例如128。

So what I want to do is I want to change the colour of the image something like this- 所以我想做的就是像这样改变图像的颜色-

block1=im[0:4,0:4]
block1.replace_colour=128

Note that the image is in the grayscale.Thanks in advance. 请注意,图像是灰度的。

You can do that like this: 您可以这样做:

colorValue = 150
im[0:4,0:4] = colorValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM