Is there a way to automatically recognize the position of a line chart in a photo and to digitize it?

140 views Asked by At

I have the following problem, we are supposed to digitize historical records of tide levels of different cities. The data is in the form of photographs and all of them look something like this:

enter image description here

The line chart remains the same over all the years, i.e. they all have the same axis, labels, grid, etc. Only the entered values and curves differ from day to day.

The main problem at the moment is to identify the line chart in the picture and then to identify the curves in it, some of which (as shown in the picture) are very thin or very thick.

I would like to have an algorithm that recognizes the chart in the image so that I can concentrate on reading the values. The solution should be in Python. Any ideas?

1

There are 1 answers

0
Alex Alex On

First, you can select the grid on the chart. Try this:

import cv2

image = cv2.imread('dia.jpg')
image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
se=cv2.getStructuringElement(cv2.MORPH_RECT , (3,3))
close=cv2.morphologyEx(image, cv2.MORPH_CLOSE, se)
close=cv2.absdiff(close, image)
cv2.normalize(close, close,  0, 255, cv2.NORM_MINMAX, cv2.CV_8UC1)
grid=cv2.bitwise_not(close)
cv2.imshow('grid', grid)  
cv2.imwrite('grid.png',grid)

Result: enter image description here