You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

hist_equalize.py 1.9 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. /**
  3. * Copyright 2020 Zhejiang Lab. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================
  17. */
  18. """
  19. import cv2
  20. import numpy as np
  21. def hist_equalize(img):
  22. """The implementation of histgram equalization in channel L"""
  23. img_HLS = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
  24. h, l, s = cv2.split(img_HLS)
  25. lH = cv2.equalizeHist(l)
  26. temp = cv2.merge((h, lH, s))
  27. re = cv2.cvtColor(temp, cv2.COLOR_HLS2BGR)
  28. return re
  29. def YUV_hist_equalize(img):
  30. """The implementation of histgram equalization in channel YUV"""
  31. imgYUV = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
  32. channelYUV = cv2.split(imgYUV)
  33. channelYUV[0] = cv2.equalizeHist(channelYUV[0])
  34. channels = cv2.merge(channelYUV)
  35. re = cv2.cvtColor(channels, cv2.COLOR_YCrCb2BGR)
  36. return re
  37. def adaptive_hist_equalize(img):
  38. """The implementation of constrast limited adaptive histgram equalization"""
  39. clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
  40. imgYUV = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
  41. channelYUV = cv2.split(imgYUV)
  42. channelYUV[0] = clahe.apply(channelYUV[0])
  43. channels = cv2.merge(channelYUV)
  44. re = cv2.cvtColor(channels, cv2.COLOR_YCrCb2BGR)
  45. return re
  46. def log_trans(img):
  47. img_out = 42 * np.log(1.0 + img)
  48. img_out = np.uint8(img_out + 0.5)
  49. return img_out

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)