用圆锥形渐变填充矩阵

问题描述

我是Python的新手,想要一些建议。我将一些代码放在一起以生成具有锥形灰度渐变的图像。因此,黑色中心向白色过渡过渡为放射状。我已经建立了一个零维度的矩阵,它的尺寸是我想要的和循环的,我将用0到255的值填充这个矩阵,但是我不确定设置初始循环后该怎么做。我看过一些为矩阵的每个空间分配RGB值的代码,但是这种方法不适用于我拥有的后者应用程序。因此,我希望有一个0到255值的最终矩阵,可以将其绘制成灰度图。 这就是我到目前为止所拥有的...

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

Pi = 3.14159265359
twpi = 150
#Set up an all zero  matrix 12080 by 1024 with a depth 3
arr = np.zeros((1272,1024),dtype=np.int64)



#set the final image set to nbe the size oft he first two colmns of the blank array
imgsize = arr.shape[:2]

MiniVal = 0
MaxVal = 255


height = imgsize[1]
width = imgsize[0]

for y in range(height):
for x in range(width):
   
    
    #Find the distance to the center
    distanceToCenter = np.sqrt((x - width//2) ** 2 + (y - height//2) ** 2)
    
    #Make it on a scale from 0 to 1innerColor
    distanceToCenter = distanceToCenter / (np.sqrt(2) * width/2)
   
   
    fill = MaxVal * distanceToCenter + MiniVal * (1 - distanceToCenter)
    
    arr[y,x] = (fill)

干杯们,谢谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...