首页 > 解决方案 > 从直方图中确定最常见的字体大小

问题描述

我们如何使用黑色分量的直方图找到文档图像中出现频率最高的字体大小?下面是显示图像直方图的代码:

import matplotlib.pyplot as plt
import numpy as np
import os.path

if __name__ == '__main__':

    image_counter = 1

    while True:

        if not os.path.isfile(str (image_counter) + '.png'):
            break

        image_path = str(image_counter) + '.png'
        image = plt.imread(image_path)


        #Display Histogram
        #print(image)
        #print(image.ravel())
        n, bins, patches = plt.hist(image.ravel(), bins = 256)
        plt.title('Image Patch # ' + str(image_counter))
        plt.xlabel('Grey Value')
        plt.ylabel('Frequency')
        window = plt.get_current_fig_manager()
        window.canvas.set_window_title('Histogram')
        plt.show()

        image_counter = image_counter + 1

标签: pythonimage-processinghistogramsignal-processing

解决方案


推荐阅读