Looking for a gmic + python scripter to help me out here.

Ah me. Time to rename G’MIC as ‘David’s Delightful Distraction Machine.’ Methinks he worked past midnight. I’m five hours behind CET…

Five hours behind him, I’ve been fooling around with a diagonalizer.

  1. It starts with images of arbitrary dimension and spectra.
  2. Take the lumenance, threshold it to make the seedmap image, then unroll it.
  3. It is my wont to interpret this as the smallest, most offset +/- diagonal.
  4. Calculating N is a two-stepper.
    a. Find the ‘ideal N’ by the quadratic formula.
    b. It has a fractional part, almost always. I prefer to round this ‘ideal N’ up to the next highest even number, and declare this to be N. I find that even N makes padding and positioning these diagonals somewhat more tractable later on.
  5. Having rounded up N, it is necessary to resize the length of the smallest diagonal so that it matches. N*(N-1) tells me what the new length is. It is resized without interpolation and periodic boundary policy; might be more appropriate to change that to black fill policy instead, though no harm seems to come of it.
  6. The lesser diagonal is essentially a copy of the smallest diagonal, resized to N^2-1, no interpolation and periodic boundary policy as before.
  7. The main diagonal, N^2 is created and filled with 4*(N-1)^2
  8. The the offset diagonals are scaled by -(N-1)^2
  9. Applied -diagonal to convert these three vectors to diagonal matrices. Though disassembled, and of different sizes, The data for the upper diagonal of the Hamiltonian is in hand. It is necessary to duplicate, pad and shift the two offset diagonals so that, later on, they can be added to the main diagonal.
  10. There follows finicky bits of matrix copying, expanding by xy and cropping to position the off-diagonal matrices to be in their appropriate places, adding the pipeline together, consolidating to a single image, the Hamiltonian, which I wrote out as a float .cimag

@David_Tschumperle’s brand new toys (!!!) notwithstanding, I harnessed the Python side to find select eigenvectors, to minimize testing to just the diagonalizer. I asked for five solution vectors, exporting the solution eigen_vectors to output .cimg files for post-processing. Runs for N=130 was about thirty seconds.

Using this seed image:
quantum_torus
I obtained these select images (filtered by post-processing, given below)
hamvecm_0
vector_0, N=130, scaled up to 512 and colorized via -map rainbow.
hamvecm_1
vector_1, the next door neighbor..
hamvecs_0
vector from a smaller seed image of the torus, N=75, scaled up and colorized as the others.

This is the diagonalizer:

gmic                                            \
   -input quantum_torus.png                     \
   -luminance.                                  \
   -threshold. 50%                              \
   -unroll. x                                   \
   hy='{(1+(sqrt(1+4*w)))/2}'                   \
   n='{round($hy/2,1,1)*2}'                     \
   nn='{($n-1)^2}'                              \
   iv='{-$nn}'                                  \
   zv='{4*$nn}'                                 \
   -resize. '{$n*($n-1)}',1,1,1,0,2             \
   -mul. '{$iv}'                                \
   +resize. '{$n^2-1}',1,1,1,0,2                \
   -reverse                                     \
   -input '{$n^2}',1,1,1,'{$zv}'                \
   -name. diag0                                 \
   -move.  0                                    \
   -diagonal                                    \
   -expand_xy. '{$n}',0                         \
   +crop.   '{$n}',0,'{w-1}','{h-$n-1}',0       \
   -name. diagmN                                \
   -move. 0                                     \
   -crop. 0,'{$n}','{$n^2-1}','{h-1}',0         \
   -name. diagpN                                \
   -expand_xy.. 1,0                             \
   +crop..   1,0,'{w}','{h-1}',0                \
   -name. diagm1                                \
   -move. 1                                     \
   -crop.. 0,1,'{w-1}','{h}',0                  \
   -name.. diagp1                               \
   -add                                         \
   -output. hamilton_test_'{$n}'.cimg,float     \

This is the post processor:

gmic                                            \
   -input hamilton_test_130_out_0.cimg          \
   '{sqrt(h)}','{sqrt(h)}',1,1                  \
   -fill. [-2]                                  \
   -sqr.                                        \
   -normalize. 0,1                              \
   -pow. 0.75                                   \
   -r2dx. 512,5                                 \
   -normalize. 0,255                            \
   -map. rainbow                                \
   -display                                     \
   -output. hamvecm_0.png

I find the shapes eerie, compelling and interesting. Even with a known seed map, it is not quite certain what the solution vectors will look like.
Next step is to disconnect the Python bit and run with @David_Tschumperle’s new toys. Then we have an end-to-end G’MIC pipeline. Doubt that the diagonalizer is optimal; certainly could use a fresh pair of eyes. Memory usage balloons at one point to 16GB, for N>=150, so it won’t run on Granny’s Tandy TRS-80, probably.

That’s it for now. Everybody have fun.

3 Likes