# Tracing line in a graph

9 views (last 30 days)

Show older comments

Dear all,

I have question on how to 'trace' a line in a graph. This is my first attempt to do 'image-processing' in Matlab, so pardon me if my explanation is a bit lenghty.

Let me start from the beginning,

- I have a graph (in paper) that i need to convert to data for further processing.The graph contains several lines (two line groups), each line need to be read (converted to data) as rigorously as possible (so less to none interpolation operation).
- What i did is scanned the graph, and traced each line group as closely as possible with two colors (blue and green in MS Paint), then i read the file in Matlab (bitmap). By applying some threshold in RGB channel, i get the blue and green line. (no problem here)
- The green line is a single continous line. The blue lines contain several 'open curves' and also several 'closed curve'. Each line of the blue lines has different label, so i need to further defines the blue line.
- I am able to trace the 'open curve' blue lines by creating difference mask. If the difference is above certain threshold then it belongs to another line..
- The question how can i trace the 'closed curve' blue lines? When i implement the same approach for the 'open curve', i only get the bottom half of the curve (logical, because the difference threshold).
- I tried to trace it with more 'brute'-way, i masked the white-part (background) to NaN and i do while loop in x-axis, find the top and bottom of y-axis for each x-axis (script skip to the next x when several nan encountered). The idea is to loop forward and backward (when the last x is processed, say lower half of the curve is traced, do backward processing for top half until the starting point is reached). However the 'closed line' is not really closed . There are several gaps in the line . When there is gap, the do-while part of the script tend to pick points of other closely located closed-curve line.

To support my explanation, i attach the picture of the graph (blue lines, halfly traced). I don't think i can put the data and the script here though..

PS: I only have Matlab, no additional toolboxes. :)

Thanks, ILham

### Answers (1)

Image Analyst
on 9 Aug 2015

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!