步骤:
第 1 步:手动均衡
第 2 步:通过使用 OpenCV 函数
什么是图像直方图?
它是图像强度分布的图形表示。它量化了所考虑的每个强度值的像素数。
第 1 步:手动均衡
%matplotlib inline
from IPython.display import display, Math, Latex
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
img = Image.open('DATA/einstein.jpg')
plt.imshow(img) 
 输出:
<matplotlib.image.AxesImage at 0x1d0b37d2250>
 
 显示彩色图像
将图像转换为 numpy 数组,以便 OpenCV 可以使用:
img = np.asanyarray(img)
img.shape 
 输出:
(2354, 2560, 3) 
 将 RGB 转换为灰度:
import cv2
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img.shape 
 输出:
(2354, 2560) 
 显示图像:
plt.imshow(img, cmap='gray') 
 输出:
<matplotlib.image.AxesImage at 0x1d0b415e100>
 
 我们现在知道如何处理直方图了
img.max() 
 输出:
255 
 img.min() 
 输出:
0 
 img.shape 
 输出:
(2354, 2560) 
 把它展平:
flat 

                  
                  
                  
                  
本文介绍了图像直方图的概念,并详细讲解如何使用OpenCV进行直方图均衡化,包括手动均衡化和使用`equalizeHist()`函数。通过实例展示了直方图均衡化如何扩大图像强度值的分布范围,从而改善图像质量。
          
最低0.47元/天 解锁文章
                          
                      
      
          
                
                
                
                
              
                
                
                
                
                
              
                
                
              
            
                  
					659
					
被折叠的  条评论
		 为什么被折叠?
		 
		 
		
    
  
    
  
            


            