图像阴影修复

举报
风吹稻花香 发表于 2021/06/06 00:22:37 2021/06/06
【摘要】   深度学习进修阴影检测 https://github.com/jacke121/DSC   matlab能修复: https://github.com/kittenish/Image-Shadow-Detection-and-Removal 效果不好: https://github.com/zyr17/ShadowRemoval pyth...

 

深度学习进修阴影检测

https://github.com/jacke121/DSC

 

matlab能修复:

https://github.com/kittenish/Image-Shadow-Detection-and-Removal

效果不好:

https://github.com/zyr17/ShadowRemoval

python的:

https://github.com/srijan-mishra/Shadow-Removal

 

shadowRemoval

 

没图:

https://github.com/cjc96/shadowRemoval

https://github.com/sbbug/Researching-Image-Shadow-Removal

https://github.com/abhiishekpal/Shadow-Removal

https://github.com/Orcuslc/ShadowRemoval

 

https://github.com/mykhailomostipan/shadow-removal

 

https://github.com/Rakosi/shadow-removal

 

这个代码还需再看:

https://codeday.me/bug/20190322/804326.html


  
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #############
  4. # LIBRARIES
  5. #############
  6. import numpy as np
  7. import cv2
  8. import os
  9. import sys
  10. import matplotlib.image as mpimg
  11. import matplotlib.pyplot as plt
  12. from PIL import Image
  13. import scipy
  14. from scipy.optimize import leastsq
  15. from scipy.stats.mstats import gmean
  16. from scipy.signal import argrelextrema
  17. from scipy.stats import entropy
  18. if __name__ == '__main__':
  19. # Get Image
  20. img = cv2.imread("d:/shudong.jpg")
  21. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  22. h, w = img.shape[:2]
  23. plt.imshow(img)
  24. plt.title('Original')
  25. plt.show()
  26. img = cv2.GaussianBlur(img, (5,5), 0)
  27. # Separate Channels
  28. r, g, b = cv2.split(img)
  29. im_sum = np.sum(img, axis=2)
  30. im_mean = gmean(img, axis=2)
  31. # Create "normalized", mean, and rg chromaticity vectors
  32. # We use mean (works better than norm). rg Chromaticity is
  33. # for visualization
  34. n_r = np.ma.divide( 1.*r, g )
  35. n_b = np.ma.divide( 1.*b, g )
  36. mean_r = np.ma.divide(1.*r, im_mean)
  37. mean_g = np.ma.divide(1.*g, im_mean)
  38. mean_b = np.ma.divide(1.*b, im_mean)
  39. rg_chrom_r = np.ma.divide(1.*r, im_sum)
  40. rg_chrom_g = np.ma.divide(1.*g, im_sum)
  41. rg_chrom_b = np.ma.divide(1.*b, im_sum)
  42. # Visualize rg Chromaticity --> DEBUGGING
  43. rg_chrom = np.zeros_like(img)
  44. rg_chrom[:,:,0] = np.clip(np.uint8(rg_chrom_r*255), 0, 255)
  45. rg_chrom[:,:,1] = np.clip(np.uint8(rg_chrom_g*255), 0, 255)
  46. rg_chrom[:,:,2] = np.clip(np.uint8(rg_chrom_b*255), 0, 255)
  47. plt.imshow(rg_chrom)
  48. plt.title('rg Chromaticity')
  49. plt.show()
  50. #-----------------------
  51. ## 2. Take Logarithms ##
  52. #-----------------------
  53. l_rg = np.ma.log(n_r)
  54. l_bg = np.ma.log(n_b)
  55. log_r = np.ma.log(mean_r)
  56. log_g = np.ma.log(mean_g)
  57. log_b = np.ma.log(mean_b)
  58. ## rho = np.zeros_like(img, dtype=np.float64)
  59. ##
  60. ## rho[:,:,0] = log_r
  61. ## rho[:,:,1] = log_g
  62. ## rho[:,:,2] = log_b
  63. rho = cv2.merge((log_r, log_g, log_b))
  64. # Visualize Logarithms --> DEBUGGING
  65. plt.scatter(l_rg, l_bg, s = 2)
  66. plt.xlabel('Log(R/G)')
  67. plt.ylabel('Log(B/G)')
  68. plt.title('Log Chromaticities')
  69. plt.show()
  70. plt.scatter(log_r, log_b, s = 2)
  71. plt.xlabel('Log( R / 3root(R*G*B) )')
  72. plt.ylabel('Log( B / 3root(R*G*B) )')
  73. plt.title('Geometric Mean Log Chromaticities')
  74. plt.show()
  75. #----------------------------
  76. ## 3. Rotate through Theta ##
  77. #----------------------------
  78. u = 1./np.sqrt(3)*np.array([[1,1,1]]).T
  79. I = np.eye(3)
  80. tol = 1e-15
  81. P_u_norm = I - u.dot(u.T)
  82. U_, s, V_ = np.linalg.svd(P_u_norm, full_matrices = False)
  83. s[ np.where( s <= tol ) ] = 0.
  84. U = np.dot(np.eye(3)*np.sqrt(s), V_)
  85. U = U[ ~np.all( U == 0, axis = 1) ].T
  86. # Columns are upside down and column 2 is negated...?
  87. U = U[::-1,:]
  88. U[:,1] *= -1.
  89. ## TRUE ARRAY:
  90. ##
  91. ## U = np.array([[ 0.70710678, 0.40824829],
  92. ## [-0.70710678, 0.40824829],
  93. ## [ 0. , -0.81649658]])
  94. chi = rho.dot(U)
  95. # Visualize chi --> DEBUGGING
  96. plt.scatter(chi[:,:,0], chi[:,:,1], s = 2)
  97. plt.xlabel('chi1')
  98. plt.ylabel('chi2')
  99. plt.title('2D Log Chromaticities')
  100. plt.show()
  101. e = np.array([[np.cos(np.radians(np.linspace(1, 180, 180))), \
  102. np.sin(np.radians(np.linspace(1, 180, 180)))]])
  103. gs = chi.dot(e)
  104. prob = np.array([np.histogram(gs[...,i], bins='scott', density=True)[0]
  105. for i in range(np.size(gs, axis=3))])
  106. eta = np.array([entropy(p, base=2) for p in prob])
  107. plt.plot(eta)
  108. plt.xlabel('Angle (deg)')
  109. plt.ylabel('Entropy, eta')
  110. plt.title('Entropy Minimization')
  111. plt.show()
  112. theta_min = np.radians(np.argmin(eta))
  113. print('Min Angle: ', np.degrees(theta_min))
  114. e = np.array([[-1.*np.sin(theta_min)],
  115. [np.cos(theta_min)]])
  116. gs_approx = chi.dot(e)
  117. # Visualize Grayscale Approximation --> DEBUGGING
  118. plt.imshow(gs_approx.squeeze(), cmap='gray')
  119. plt.title('Grayscale Approximation')
  120. plt.show()
  121. P_theta = np.ma.divide( np.dot(e, e.T), np.linalg.norm(e) )
  122. chi_theta = chi.dot(P_theta)
  123. rho_estim = chi_theta.dot(U.T)
  124. mean_estim = np.ma.exp(rho_estim)
  125. estim = np.zeros_like(mean_estim, dtype=np.float64)
  126. estim[:,:,0] = np.divide(mean_estim[:,:,0], np.sum(mean_estim, axis=2))
  127. estim[:,:,1] = np.divide(mean_estim[:,:,1], np.sum(mean_estim, axis=2))
  128. estim[:,:,2] = np.divide(mean_estim[:,:,2], np.sum(mean_estim, axis=2))
  129. plt.imshow(estim)
  130. plt.title('Invariant rg Chromaticity')
  131. plt.show()

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/95742017

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。