def GammaCorrection(img, c=1.0, g=2.2): # 伽马校正 out = (np.power(img / 255, 1.0 / g) / c) * 255 return out.astype(np.uint8)
时间: 2024-03-18 07:43:30 浏览: 80
这是一个用于进行伽马校正的函数,它的参数包括一张图片、伽马值和缩放系数。函数首先将图片中的每个像素值除以 255,将其值缩放到 [0, 1] 的范围内,然后将其取 g 次方,再除以缩放系数 c,并将结果乘以 255,最后将其转换为整数类型作为输出。伽马校正可以用于调整图片的亮度和对比度,提高图像的清晰度和细节。
相关问题
def Gamma(): img_path = "result" save_path = "Gammaresult" img_names = os.listdir(img_path) for img_name in img_names: img = os.path.join(img_path, img_name) img = imageio.imread(img) # 伽马校正 img2 = GammaCorrection(img) dir_name = ''.join(random.sample(string.ascii_letters + string.digits, 8)) cv2.imwrite(os.path.join(save_path, dir_name + '.jpg'), img2) cv2.imwrite(os.path.join(save_path, img_name), img)
这是一个用于给一个文件夹中的所有图片进行伽马校正的函数。函数首先需要指定输入图片所在的文件夹路径和输出图片所要保存的文件夹路径。然后获取输入文件夹中所有图片的文件名,对于每个文件名,读取对应的图片。接着,使用 GammaCorrection 函数对该图片进行伽马校正,使用随机生成的文件名将校正后的图片保存到输出文件夹中。最后,将原始图片也保存到输出文件夹中,但不进行伽马校正。
gamma校正_3Dmax场景gamma伽马设置插件脚本
Gamma校正是一种对图像颜色进行调整的方法,可以使色彩更加准确地显示在不同的设备上。在3Dmax场景中,也需要对Gamma进行设置,以确保渲染出的图像色彩准确无误。下面介绍一个Gamma设置插件脚本,可以帮助你快速进行Gamma设置。
1. 打开3Dmax软件,在菜单栏选择“Scripting”,打开Script Editor。
2. 在Script Editor中选择“Maxscript”,然后输入以下代码:
```
try(destroyDialog GammaSetting)catch()
rollout GammaSetting "Gamma Setting" width:180
(
checkbox chkEnableGamma "Enable Gamma Correction" width:160 height:20 align:#center
spinner spnGamma "Gamma Value:" range:[0.1, 5.0, 2.2] width:160 height:16
button btnSetGamma "Set Gamma" width:160 height:24 align:#center
on btnSetGamma pressed do
(
if chkEnableGamma.checked then
gammaCorrection spnGamma.value
else
gammaCorrection 1.0
)
)
createDialog GammaSetting width:180
```
3. 点击“Run”按钮执行以上代码,将会弹出一个Gamma设置的窗口。
4. 在窗口中,勾选“Enable Gamma Correction”复选框,然后设置Gamma值,点击“Set Gamma”按钮即可完成Gamma设置。
这个插件脚本可以帮助你快速进行Gamma设置,方便高效。