资源简介
根据参考图像各个通道的灰度分布,将一副图像的灰度分布映射过去,使映射后的两幅图像灰度分布非常接近,被称为histogram matching或者histogram specification,常用于网络训练的图像数据扩增
代码片段和文件信息
#!/usr/bin/env python3
“““
@license: Apache License Version 2.0
@author: Stefano Di Martino
Exact histogram matching
“““
from scipy import misc
from histogram_matching import ExactHistogramMatcher
import numpy as np
import png
def histogram_matching_rgb():
target_img = misc.imread(‘F:/X15207198.png‘)
reference_img = misc.imread(‘F:/307-1001059240_512.png‘)
reference_histogram = ExactHistogramMatcher.get_histogram(reference_img)
new_target_img = ExactHistogramMatcher.match_image_to_histogram(target_img reference_histogram)
misc.imsave(‘F:/rgb_out.png‘ new_target_img)
def histogram_matching_grey_values():
target_img = misc.imread(‘F:/307-1001057260.dcm.png‘)
reference_img = misc.imread(‘F:/X15207198.png‘)
reference_histogram = ExactHistogramMatcher.get_histogram(reference_img)
new_target_img = ExactHistogramMatcher.match_image_to_histogram(target_img reference_histogram)
new_target_img = new_target_img.astype(np.uint16)
# misc.imsave(‘F:/grey_out.png‘ new_target_img)
filename = ‘F:/grey_out.png‘
with open(filename ‘wb‘) as f:
writer = png.Writer(width=new_target_img.shape[1] height=new_target_img.shape[0] bitdepth=16 greyscale=True)
zgray2list = new_target_img.tolist()
writer.write(f zgray2list)
def main():
# histogram_matching_rgb()
histogram_matching_grey_values()
if __name__ == “__main__“:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-07-18 09:16 ExactHistogramSpecification-master\
文件 1203 2018-06-17 14:22 ExactHistogramSpecification-master\.gitignore
目录 0 2018-07-19 10:14 ExactHistogramSpecification-master\.idea\
文件 596 2018-07-17 18:34 ExactHistogramSpecification-master\.idea\deployment.xm
文件 455 2018-07-17 18:34 ExactHistogramSpecification-master\.idea\ExactHistogramSpecification-master.iml
目录 0 2018-07-17 18:34 ExactHistogramSpecification-master\.idea\inspectionProfiles\
文件 288 2018-07-17 18:33 ExactHistogramSpecification-master\.idea\misc.xm
文件 320 2018-07-17 18:33 ExactHistogramSpecification-master\.idea\modules.xm
文件 12373 2018-07-19 10:14 ExactHistogramSpecification-master\.idea\workspace.xm
文件 1428 2018-07-18 09:16 ExactHistogramSpecification-master\example.py
文件 8374 2018-07-18 09:01 ExactHistogramSpecification-master\histogram_matching.py
目录 0 2018-06-17 14:22 ExactHistogramSpecification-master\images\
目录 0 2018-07-17 18:48 ExactHistogramSpecification-master\images\GreyValue\
文件 982940 2018-06-17 14:22 ExactHistogramSpecification-master\images\GreyValue\Luna_medium.jpg
文件 1192627 2018-06-17 14:22 ExactHistogramSpecification-master\images\GreyValue\Luna_White_Balance_medium.jpg
目录 0 2018-07-17 18:48 ExactHistogramSpecification-master\images\RGB\
文件 1338556 2018-06-17 14:22 ExactHistogramSpecification-master\images\RGB\Luna_medium.jpg
文件 2167112 2018-06-17 14:22 ExactHistogramSpecification-master\images\RGB\Luna_White_Balance_medium.jpg
文件 11357 2018-06-17 14:22 ExactHistogramSpecification-master\LICENSE
文件 839 2018-06-17 14:22 ExactHistogramSpecification-master\README.md
评论
共有 条评论