r/PlotterArt • • Jul 07 '25

Finally I have a contour plotting algorithm running

Inspired by multiple people who achieved this effect already, I was eager to do it myself. The first time I tried to come up with an algorithm my approach was much too complex and wouldn't yield any good results. The final solution I came up with is actually much simpler. Basically, treat the image as a "speed map", perform a fast marching method on it and finally calculate the isocontours (height map).

In the first image I also played with different thicknesses of pens for different levels of details.

537 Upvotes

43 comments sorted by

View all comments

Show parent comments

2

u/Mickeymoe1992 Jul 08 '25

Dude that was quick! Nice work.

Do you by any chance run into the problem, where the result looks more like this than my original post?

8

u/Ruths138 Jul 08 '25

yes I think that captures the problem.
I now bring the gamma down to reduce contrast and higher line density is helpful (duh). Above image has 300 contours levels.
I also sample slightly more lines in the lighter parts than in the darker ones which helps to dial in the right amount. Now gonna have to figure out some sort of smoothing to take care of small artifacts... funn

btw. this is by far the most interesting contour finding method that I've come across. DrawingBotv3 implements many such methods, but I prefer the results of this one.

3

u/Mickeymoe1992 Jul 08 '25

Then maybe you are running into the same problem as I have. I'm not 100% sure if I understand the underlaying working principles of skfmm.travel_time, but I think the propagation time of a pixel is based on the inverse of the grayscale value. But I want it to be linearly proportional to the grayscale value, i.e. I want the difference from a value 10 to a value 20 pixel to be the same as from a value 240 to 250 pixel. Therefore I calculate the inverse of the "slowness map" first and then pass it to the skfmm.travel_time function. Something like this:

    normalized_intensity = image_data.astype(np.float32) / 255.0
    slowness_map = 1.0 - normalized_intensity
    
    # Clamp slowness to avoid division by zero. A tiny slowness means a huge speed.
    epsilon = 1e-6
    slowness_map = np.maximum(slowness_map, epsilon)

    # 2. Convert the Slowness Map to the Speed Map required by scikit-fmm
    # The library needs F, and we have S. The relationship is F = 1/S.
    speed_map_for_skfmm = 1.0 / slowness_map

    # Then call skfmm.travel_time
    T_map = skfmm.travel_time(phi, speed_map_for_skfmm, dx=1)

See if this helps :)

1

u/Odd_Drawer_9086 Jul 09 '25

Can you share the code, it looks lovely.

1

u/Ruths138 Jul 09 '25

See my response in the top comment

1

u/dekonta Jul 13 '25

hey yes. I have a similar problem on certain pictures. not all of them. is quite trippy but maybe you can give me a hand and share why the dark areas could be just missing?