Python:标准化图像曝光

标签 python image image-processing

我正在从事一个测量和可视化图像相似性的项目。我数据集中的图像来自书籍中图像的照片,其中一些具有非常高或低的曝光率。例如,下面的图片来自两本不同的书;上图是下图的过度曝光重印,曝光看起来不错:

enter image description here enter image description here

我想用 Python 规范化每张图像的曝光。我想我可以使用以下天真的方法来做到这一点,它试图将每个像素值居中在 0 到 255 之间:

from scipy.ndimage import imread
import sys

def normalize(img):
  '''
  Normalize the exposure of an image.
  @args:
    {numpy.ndarray} img: an array of image pixels with shape:
      (height, width)
  @returns:
    {numpy.ndarray} an image with shape of `img` wherein
      all values are normalized such that the min=0 and max=255
  '''
  _min = img.min()
  _max = img.max()
  return img - _min * 255 / (_max - _min)

img = imread(sys.argv[1])
normalized = normalize(img)

只有在运行之后我才意识到这种归一化只会帮助最亮值小于 255 或最暗值大于 0 的图像。

是否有一种直接的方法来标准化图像的曝光,例如上面的顶部图像?如果其他人可以就此问题提供任何想法,我将不胜感激。

最佳答案

Histogram equalisation对于这种事情,效果出奇的好。它通常更适合摄影图像,但它甚至对艺术线条也有帮助,只要有一些非黑/白像素。

它也适用于彩色图像:拆分波段,分别均衡每个波段,然后重新组合。

我试过你的示例图片:

after hist equal

使用 libvips :

$ vips hist_equal sample.jpg x.jpg

或从 Python 使用 pyvips :

x = pyvips.Image.new_from_file("sample.jpg")
x = x.hist_equal()
x.write_to_file("x.jpg")

关于Python:标准化图像曝光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49546179/

相关文章:

python - webbrowser.get ("firefox") 在装有 Firefox "could not locate runnable browser"的 Mac 上

python - 适用于 python 的 Google Api 客户端库不会在文件 : list method with query 中返回 nextPageToken

Java 检查 file.exists() 是否不能与 ImageIO.read(file) 一起使用

javascript - 如何清除或替换缓存的图像

使用 numpy 快速降低图像分辨率的 Python 代码

c++ - openCV 的 fftshift C++ 实现

python - 如何根据时间段剪切wav文件?

python - 新手 : installing and upgrading python module

Asp.net 图像随机给出 401 未经授权的错误

java - 它显示异常错误