programextensions/image/demos/photo-lab.xtl
The photo lab: a photo is an array. Buzz Aldrin on the Moon (Apollo 11, NASA, public domain: demos/data/PROVENANCE.txt) read as numbers; filters and edges by rotating the array (the Life idiom), a color toning by an inner product, and the SVD compressing it at several ranks -- the native code reads, writes and decomposes, X_eTaL does the rest. Pictures go to work/photo-lab/. Run: just demo image photo-lab
1. the photo as numbers: 240 by 246, gray from 0 (black) to 1
2. filters by rotation: each pixel and its 8 neighbors, as Life
box : Float
counts neighbors (the edges wrap around, as rotations do)
box ← ('+ r̲/₁₂ -1 0 1 o̲-₁₂ p) ÷ 9.0
sx : Float
edges: Sobel, horizontal and vertical differences of the blurred rows and columns, and their length
sx ← ((-1 o̲-₂ p) − 1 o̲-₂ p)
Used in: gx
edge : Float
edge ← 1.0 m̲in 0.5 × ((gx ^ 2.0) + gy ^ 2.0) ^ 0.5
Used in: extensions/image/demos/photo-lab.xtl:39, n
3. color: a sepia toning, every pixel's red, green and blue times
sepia : Float
sepia ← 3 3 r̲eshape 0.393 0.349 0.272 0.769 0.686 0.534 0.189 0.168 0.131
Used in: toned
4. the SVD: the photo as a sum of rank-1 pictures, largest first;
ᵘr̲ank : Int -> Float
ᵘr̲ank ← { k → ((k t̲ake₂ u) × (s̲hape k t̲ake₂ u) r̲eshape k t̲ake s) '+ '× i̲nner 2 1 t̲ranspose k t̲ake₂ v }