color_enhance_python.zip

  • i1_643211
    了解作者
  • 1MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-30 02:01
    上传日期
Python实现GIMP色彩增强插件,主要在CMYK,BGR和HSV颜色空间进行处理。
color_enhance_python.zip
  • color_enhance_python
  • color_enhance.py
    1.8KB
  • test_img.jpg
    1MB
内容介绍
import os, sys import cv2, time import numpy as np # 色彩增强 def color_enhance(image): # 转换颜色空间到CMY image_BGR = image.copy() image_CMY = 255 - image_BGR # 找CMY空间中最小值 image_min = image_CMY[:,:,0].copy() image_min[image_CMY[:,:,0]>image_CMY[:,:,1]] = image_CMY[:,:,1][image_CMY[:,:,0]>image_CMY[:,:,1]] image_min[image_min>image_CMY[:,:,2]] = image_CMY[:,:,2][image_min>image_CMY[:,:,2]] # 减去最小值 image_CMY[:,:,0] = image_CMY[:,:,0] - image_min image_CMY[:,:,1] = image_CMY[:,:,1] - image_min image_CMY[:,:,2] = image_CMY[:,:,2] - image_min # 转换得到的CMY图像到HSV空间 image_HSV = cv2.cvtColor(image_CMY, cv2.COLOR_BGR2HSV) # 找V信道极大极小值,极大值可调整最终色彩鲜艳程度 max_v = np.max(image_HSV[:,:,2]) / 255.0 min_v = np.min(image_HSV[:,:,2]) / 255.0 # 重新量化V值 image_HSV[:,:,2] = ((image_HSV[:,:,2]/255.0 - min_v) / (max_v - min_v)) * 255.0 image_HSV[:,:,2][image_HSV[:,:,2] > 255] = 255 image_HSV[:,:,2][image_HSV[:,:,2] < 0] = 0 # HSV->BGR,注意此时result_image值范围为0-255,超过值会自动减-255 result_image = cv2.cvtColor(image_HSV, cv2.COLOR_HSV2BGR) result_image = result_image / 255 result_image[:,:,0] = result_image[:,:,0] + image_min / 255 result_image[:,:,1] = result_image[:,:,1] + image_min / 255 result_image[:,:,2] = result_image[:,:,2] + image_min / 255 result_image[result_image <= 1] = 1 - result_image[result_image <= 1] result_image[result_image > 1] = 0.0 result_image = (result_image*255).astype(np.uint8) return result_image if __name__ == '__main__': image = cv2.imread('test_img.jpg') color_image = color_enhance(image) cv2.imshow('result', color_image) cv2.waitKey(0)
评论
    相关推荐
    • Python
      Python
    • python
      Python 这是用于大多数基本和简单python代码的示例模板的存储库。
    • Python
      Python项目 Python是一些简单的Python项目,它是一种解释性的高级通用编程语言,我愿意学习它为将来的许多项目做出贡献! 入门 您必须安装Python 3.9.2才能尝试这些项目。 这些项目来自各种书籍,您可以根据需要进行...
    • Python
      Python Dit是Mijn储存库van Python
    • python
      Python 基本的python编程
    • Python
      Python python和pyspark
    • python
      关于python的学习资料。。。。。。。
    • python学习
      python学习 安装Python 我们转到Python页面进行初始下载:( )在为Mac OSX选择了最新版本(3.9.2)之后,我将其下载到了我的计算机上。 然后,我们搜索了“ Python入门”,并确认VS Code是适用于Python的可行代码...
    • Fluent Python
      This book was written for practicing Python programmers who want to become proficient in Python 3. If you know Python 2 but are willing to migrate to Python 3.4 or later, you should be fine. At the ...
    • Python
      Python 该存储库包含与Python编程研究相关的文档