2019年7月22日 星期一

OpenCV(Python) Vertical and Horizontal Binary Histogram Projection Line Chart

將圖像二值化後,將其二維矩陣之個軸 (x, y) 單獨加總,例如求得 x 軸總和即為行加總,y  軸總和即為列加總。

求得之加總 x,y 值則各自會變成一維資料,而此方法則為線性代數之投影量,稱為 Histogram Projection。




Python:

import numpy as np

pic = cv2.imread("imagePath", 0)
pic = cv2.resize(pic, (1384, 675), interpolation=cv2.INTER_CUBIC)

ret,thresh2 = cv2.threshold(pic,190,255,cv2.THRESH_BINARY)

thresh2 = 255-thresh2 
xsum = np.sum(thresh2,axis=0).tolist() #vertical
ysum = np.sum(thresh2,axis=1).tolist() #horizontal
    
plt.plot(img_row_sum)
plt.show()

Reference:
https://ccjou.wordpress.com/2010/04/19/%E6%AD%A3%E4%BA%A4%E6%8A%95%E5%BD%B1-%E5%A8%81%E5%8A%9B%E5%BC%B7%E5%A4%A7%E7%9A%84%E4%BB%A3%E6%95%B8%E5%B7%A5%E5%85%B7/
https://docs.opencv.org/3.1.0/d1/db7/tutorial_py_histogram_begins.html
https://stackoverflow.com/questions/21348609/horizontal-and-vertical-projection-of-an-image
https://stackoverflow.com/questions/4295006/horizontal-histogram-in-opencv/4297121
https://stackoverflow.com/questions/54285839/how-to-construct-horizontal-projection-of-binary-image-in-opencv
https://www.twblogs.net/a/5cb445aebd9eee48d788c42b
https://blog.csdn.net/lichengyu/article/details/21888609
https://stackoverflow.com/questions/48126335/drawing-a-histogram-in-opencv-python

沒有留言:

張貼留言

© ERIC RILEY , 自由無須告知轉貼
Background Japanese Sayagata by Olga Libby