How can I trace a path around an image consisting of only black and white lines?
Depending on the accuracy of the trace you wish to achieve, there are a couple of ways you can do this:

The most straightforward way is to:


Convert the image to grayscale
Threshold, to achieve a completely binary image
Apply a high pass mask to get rid of the constant areas


For example $\begin{matrix} 1 &amp; 1 &amp; 1 \\ 1 &amp; -9 &amp; 1 \\ 1 &amp; 1 &amp; 1 \end{matrix}$



The result looks like this:



This technique is not without limitations, because as you can see, Pink Panther's whiskers have been drawn boldly and therefore have been "traced" and the highlight in his left eye has been interpreted as "background", producing an inner trace. To reduce these artifacts you can use a "wider" filter (for example, a $5 \times 5$ square of $1$s with a $-25$ in the middle. This produces a stronger wider trace line), morphological operations or adaptive application of the mask depending on features of the patch you are looking at.

The "path based" tracer you seem to suggest is how active contours work. In this case, you would initialise the active contour on the image rectangle and then iterate it towards the outer edges of the cartoon. Scikit-image has an implementation of active contours.

But based on the work you have done already, you could switch from a "Traveling salesman" route discovery to a convex hull of the points you collect.

The convex hull will trace an outline that encloses the set of points and give it a "cartoonistic" sketch view as well. Again, scipy has a convex hull implementation and so does Octave, from which I am posting this indicative output. 

You will need to have the image package loaded for the following code to work and I am re-using the last image of the traced Pink Panther from above to extract the points, but that is just because I had it already, you can simply feed the convex hull the points you have extracted right after thresholding. It might be a lot of data indeed but convex hull is not solving a TSP and returns much quicker.

I = imread("thetracedimage.png");  % Load the image
Z = find(I);  % Find the outline (anything that is nonzero)
[Qy, Qx] = ind2sub(size(I),Z);  % Convert the index values returned by find, to image coordinates (in Qx, Qy) NOTICE ORDER OF X,Y!
H = convhull(Qx, -Qy);  % Obtain the convex hull
% H is the index of the existing points that make up the convex hull and we are assuming that these are connected by lines. To retrieve the actual points:
Fx=Qx(H);
Fy=Qy(H);
% Now plot everything. Notice the reversal of y purely because of the plotting coordinate system that puts 0,0 at the bottom left corner.
plot(Qx, -Qy,'.',Fx,-Fy);axis image;


And this results to:



Which of course is less accurate, but it depends on what you are trying to do and you seem to indicate that the approximate output of the TSP is sort of satisfactory (?).

Hope this helps.