Lineart
Introduction
String art
- Radon transform (inverse of)
- 2d FFT
- Optimization
Radon Transform
The sum of the intensities in each direction (a line integral).
The new image will be
Thus, which gives and if the angle is not close to 0 or 180 degrees.
Idea; pipeline
- image
- resize??
- Radon transform
- for every Radon pixel:
- weight
- distance
- angle
- Radon lines -> Weight -> Nearest Nail pair -> Geometric error -> accept/reject
- Intersection with the circle
- sort candidates by weight
- convert (distance, angle) → physical line
- find nail intersections
- draw string
Coordinate systems
Center the artwork at: with the circle , .
The intersections of the line and your nail circle is . Substitute the line into the circle:. This gives the quadratic Failed to parse (syntax error): {\displaystyle (1+k^2)x^2+2kbx+(b^2−R^2)=0} . So the two intersection points come from the quadratic formula. Define Failed to parse (syntax error): {\displaystyle D=R^2 (1+k^2)−b^2} . If D<0, the line doesn't intersect the circle. If Failed to parse (syntax error): {\displaystyle x_1 = \frac{−kb+\sqrt D}{1+k^2}} and Failed to parse (syntax error): {\displaystyle x_2 = \frac{−kb-\sqrt D}{1+k^2}} .
Note on coord system
we actually don't need k and b to find the intersections at all. The line has a unit normal vector n=(cosθ,sinθ) and a direction vector d=(−sinθ,cosθ). The closest point on the line to the origin is p_0=ρn. The distance from that point to either circle intersection is s= R^2−ρ^2. Therefore the two endpoints are simply p_1 =ρn+sd and p2 =ρn−sd. This is actually the method I would use in the final program, because it works perfectly even for the vertical line at 0∘, where y=kx+b breaks down. Circle
Line where the closest point on the line to the origin is and the direction along the line is perpendicular to The distance from the origin to the line is , so the distance to either circle intersection is Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \sqrt{R^2 - \rho^2} }
Accepting or rejecting the lines (y=kx+b)
Histogram.
Ask a very interesting question: what percentage of Radon lines would be physically drawable for a given nail diameter?
Try several values of dd and and print print(len(accepted)).
Suppose 30 different Radon lines all map to nail 23 → nail 117.
- Currently: Radon endpoint → find nearest nail → accept only if distance < dd.
- Alternative: Radon endpoint → always choose nearest nail → use that nail pair.
A Radon value is a sum along a line.
- white background = 255
- black object = 0
A line through the white background has a large Radon value, while a line through the black object has a smaller value. So if we simply sort descending: lines = lines[np.argsort(lines[:, 0])[::-1]] we are preferentially selecting background lines.
Optimization
Let the target function be gaussian blurred absolute difference. The metric could have multiple scales L=w1Lσ1+w2Lσ2+w3Lσ3 or have both an image-space term and a structural term; eg
Variables
- Opacity
- Number of lines, but the maximum number is constrained
- The blur variance
and then
- Number of nails
- Radon resolution?
1
Virtually Passed YT
White canvas with nails around the circumference and add straight black lines between the nails.
Video: The Mathematics of String Art
- Starting nail angle and ending nail angle . Maximum number of lines is
- Convert image array to vectors, and make the linear combination: . Solve .
- Problems:
- Line darkness. Use some antialiasing algorithm; from step function to some other.
- Pseudoinverse gives not binary result. Greedy algorithm.
- FFT in part II gives much better results
Video: How To Make a Computer Create Something Beautiful: String Art
- Radon transform; density function .
- plot sinogram: .
- Make linear transform Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \rho_{line_1}(\alpha, s) x_1 +\rho_{line_2}(\alpha, s) x_2 + \cdots \approx \rho(\alpha, s)} where are the binary weights.
- Need a Radon transform for lines.
- max because the lines are of different length.
Michael Crum
https://michael-crum.com/string_art_generator/
- Nail and the next nail using greedy algorithm (chooses the one that is best at the current situation). For other method, see https://en.wikipedia.org/wiki/Dynamic_programming
- Gradient descent as a finite difference approximation and minimize L2 error.
- Fix the error function to include the possibility to fix the error later with other color.
- Include the natural blurring of human eye: https://www.sothebys.com/en/articles/pointillism-7-things-you-need-to-know
- Convolution
- Resize the original image such that one pixel corresponds to the diameter of the thread.
- Blurring: Downscale by a factor and add transparency of .
- Use Bresenham's line algorithm for the line.
- Radon transform and Fourier slice theorem "The Fourier Slice Theorem shows that the Fourier Transform of the Radon transform of reading forms a radial "slice" of the 2D FFT of the original image. After using the slices to recreate the 2D FFT, an inverse FFT results in the reconstructed image.". https://www.researchgate.net/profile/S-Ren-Zhao/publication/3638293_A_new_Fourier_method_for_fan_beam_reconstruction/links/5c02207b92851c63cab2bafd/A-new-Fourier-method-for-fan-beam-reconstruction.pdf
Datagenetics
https://datagenetics.com/blog/december12019/index.html
References
- https://elderlawattorneyblog.com/dharruk/circle-string-art-instructions.php
- TOP 5 EASIEST STRING ART PICTURES #1 | DIY TUTORIAL | MANDALA IN CIRCLE | 3 COLOURS https://www.youtube.com/watch?v=5gbwxqFnWek
- https://geometryexpressions.com/downloads/StringArt.pdf
- https://ar5iv.labs.arxiv.org/html/2008.10693
- https://ccicada.org/wp-content/uploads/2023/09/String-Art-Creating-Constructing-and-Computing.pdf
- https://arxiv.org/pdf/2008.10693
- https://quenell.org/PSU/pubpdf/stringart.pdf
- https://www.stringartlaboratory.com/post/beginners-guide-to-string-art-understanding-its-origins-basic-tools-and-materials
- https://chessapig.github.io/files/hyperbolic_string_art.pdf
- https://polypad.amplify.com/lesson/string-art
- https://plus.maths.org/content/bridges-string-art-and-bezier-curves
- https://meangreenmath.com/2023/01/20/parabolas-from-string-art-part-7/
- https://www.peterwonka.net/Publications/pdfs/2018.EG.Birsak.StringArt.pdf
- https://yetanothermathprogrammingconsultant.blogspot.com/2024/01/string-art.html
- https://hackaday.com/2021/03/18/an-algorithm-for-art-thread-portraits/
- https://circuit4us.medium.com/neopixel-assisted-string-art-weaving-9c34a169b18a Paywall
- https://hackaday.io/project/130951-diy-knit-portrait
- Parameters: Radius, Number of hooks, Number of lines, Contrast, Scale
Art
Ready-made instructions
https://en.wikipedia.org/wiki/Hough_transform