1 | initial version |
Just a quick answer. Sorry for the rough code snippets. They are untested and incomplete but might give a rough idea. So the general approach would be to find a filtering function that targets whatever distinguishes the grid lines from the graph line. Three approaches:
1. Filter by Orientation: the grid is strictly horizontal and vertical, the graph not. You can filter by orientation of the gradient (filter out orientation = 0° and 90° etc.). Rough idea (google gradient orientation for more results)
2. Filter by Thickness: as sturkmen suggested, morphological filtering is an easy way to filter out thinner lines. It can also be used to filter by line orientation, but will not perform as well as filtering through the gradient. If the thickness differs more than two pixels it should be enough to
3. Filter by Periodicity: the grid is periodic, the graph line not. The grid could be sorted out via the peaks in the Fourier Transform. Problem: not easy to handle if you don't have experience with that, and the grid is not even really periodic in your example. So not an option here.
2 | No.2 Revision |
Just a quick answer. Sorry for the rough code snippets. They are untested and incomplete but might give a rough idea. So the general approach would be to find a filtering function that targets whatever distinguishes the grid lines from the graph line. Three approaches:
1. Filter by Orientation: the grid is strictly horizontal and vertical, the graph not. You can filter by orientation of the gradient (filter out orientation = 0° and 90° etc.). Rough idea (google gradient orientation for more results)
2. Filter by Thickness: as sturkmen suggested, morphological filtering is an easy way to filter out thinner lines.
It can also be used to filter by line orientation, but this will not perform probably not work as well as filtering through the gradient.
gradient orientation.
If the thickness differs more than two pixels it should be enough to
3. Filter by Periodicity: the grid is periodic, the graph line not. The grid could be sorted out via the peaks in the Fourier Transform. Problem: not easy to handle if you don't have experience with that, and the grid is not even really periodic in your example. So not an option here.
3 | No.3 Revision |
Just a quick answer. Sorry for the rough code snippets. They are untested and incomplete but might give a rough idea. So the general approach would be to find a filtering function that targets whatever distinguishes the grid lines from the graph line. Three approaches:
1. Filter by Orientation: the grid is strictly horizontal and vertical, the graph not. You can filter by orientation of the gradient (filter out orientation = 0° and 90° etc.). Rough idea (google gradient orientation for more results)
2. Filter by Thickness: as user sturkmen suggested, suggested in the comment above, morphological filtering is an easy way to filter out thinner lines.
It can also be used to filter by line orientation, but this will probably not work as well as filtering through the gradient orientation.
If the thickness differs more than two pixels it should be enough to do the following: - Step 1: strel =cv::getStructuringElement(MORPH_ELLIPSE, 3, 3) - Step2: cv::dilate(img, strel,...) //repeat this step until the grid has disappeared. - Step 3: cv::threshold( img,...,128, BINARY_INVERSE) - Step 4: cv::findNonZero()
3. Filter by Periodicity: the grid is periodic, the graph line not. The grid could be sorted out via the peaks in the Fourier Transform. Problem: not easy to handle if you don't have experience with that, and the grid is not even really periodic in your example. So not an option here.
4 | No.4 Revision |
Just a quick answer. Sorry for the rough code snippets. They are untested and incomplete but might give a rough idea. So the general approach would be to find a filtering function that targets whatever distinguishes the grid lines from the graph line. Three approaches:
1. Filter by Orientation: the grid is strictly horizontal and vertical, the graph not. You can filter by orientation of the gradient (filter out orientation = 0° and 90° etc.). Rough idea (google gradient orientation for more results)
2. Filter by Thickness: as user sturkmen suggested in the comment above, morphological filtering is an easy way to filter out thinner lines. It can also be used to filter by line orientation, but this will probably not work as well as filtering through the gradient orientation.
If the thickness of the lines of the grid and the plot differs more than two pixels pixels, it should be enough to do the following:
- Step 1: strel =cv::getStructuringElement(MORPH_ELLIPSE, 3, 3)
- Step2: cv::dilate(img, strel,...) //repeat this step until the grid has disappeared.
disappeared (can be done by setting the iterations or by manually calling the function several times).
- Step 3: cv::threshold( img,...,128, BINARY_INVERSE)
- Step 4: cv::findNonZero()
3. Filter by Periodicity: the grid is periodic, the graph line not. The grid could be sorted out via the peaks in the Fourier Transform. Problem: not easy to handle if you don't have experience with that, and the grid is not even really periodic in your example. So not an option here.