Message Boards Message Boards

Creating composite ambigrams from Chinese characters in Voxelverse

Posted 3 years ago

enter image description here

If we were to develop three dimensional voxel shanshui (山水) art, then we would definitely need three dimensional voxelized creator and collector stamps when processing transactions. I almost didn't say anything, but Erik Mahieu and Frederick Wu brought up ambigrams in another recent successful team effort. The purpose of this memo (at min) is to uncover a new mathematical conjecture, which occurs when creating composite ambigrams from Chinese characters in the voxelverse.

Here's the scenario.

An exercise involving a $3 \times 3$ matrix.

九gram = "道江湖金水木山自然";
dat = Rasterize[#] & /@ Characters[九gram];
RastToBitmap[im_, trim_] := With[{
   rect = Map[Mod[Mean[#] + 1, 2] &,
     Round[ImageData[im]], {2}]},
  Map[Join[{0, 0, 0}, #, {0, 0, 0}] &,
    rect][[1 + trim ;; -1 - trim, 1 + trim ;; -1 - trim]]]
bitmaps = RastToBitmap[#, 2] & /@ dat;
bitmapIms = Image[Mod[# + 1, 2]] & /@ bitmaps;
Partition[bitmapIms, 3] // Grid  

nine gram

The mission objective that shows up on the teleprompter is to encipher this matrix into the form of $8$ & an extra perfectly decodable voxel ambigrams. The problem (as mentioned by Fredrick) is that the symbols are too high genus for monotonic data to suffice.

Here's the solution I came up with, using the chosen topology of rows + columns + diagonals + knight moves from Square $1$. The lexicon is over three symbols $\{R,G,B\}$ plus another for clear space. After encoding, we can check partial projections:

Partials[gram1_, gram2_, gram3_] := With[{
   dat123 = Position[Outer[
      gram1[[#1, #2]] gram2[[#2, #3]] gram3[[#3, #1]] & ,
      Range[14], Range[14], Range[14], 1], 1]},
  MapIndexed[Function[{grams, ind},
      Complement[RotateRight[#, ind] & /@ Position[
         Outer[grams[[1, #1, #2]] grams[[2, #2, #3]] & ,
          Range[14], Range[14], Range[14], 1], 1], dat123]
      ][#1, #2[[1]] - 1] &, Partition[{gram1, gram2, gram3}, 2, 1, 1]]]

imDat[partials_] := Outer[Image[ReplacePart[
     Table[1, {i, 1, 14}, {j, 1, 14}],
     # -> 0 & /@ #1[[All, #2]]]] &,
  partials[[{2, 3, 1}]], {{1, 2}, {2, 3}, {3, 1}}, 1]

rowDat = Partition[bitmaps, 3];
colDat = Transpose[Partition[bitmaps, 3]];
xDat = {bitmaps[[{1, 5, 9}]], bitmaps[[{3, 5, 7}]], 
   bitmaps[[{1, 6, 8}]]};

rows = Map[imDat[Partials[Sequence @@ #]] &, rowDat];
cols = Map[imDat[Partials[Sequence @@ #]] &, colDat];
diags = Map[imDat[Partials[Sequence @@ #]] &, xDat];

TableForm /@ rows
TableForm /@ cols
TableForm /@ diags

partials

These matrices in themselves have some interesting structure and are worth more detailed analysis, but for now, we need only one superposition function

Superpose[mat_] :=  Map[ImageMultiply@mat[[Complement[Range[3], {#}], #]] &, Range[3]]
TableForm[Superpose /@ #] & /@ {rows, cols, diags}

valid outs

These look correct, but for sake of rigor ++ QA +

MapThread[ImageSubtract[#1, #2] &,
 {Flatten[Superpose /@ rows], bitmapIms}]

MapThread[ImageSubtract[#1, #2] &,
 {Flatten[Superpose /@ cols],
  Flatten[Transpose[Partition[bitmapIms, 3]]]}]

MapThread[ImageSubtract[#1, #2] &,
 {Flatten[Superpose /@ diags],
  bitmapIms[[{1, 5, 9, 3, 5, 7, 1, 6, 8}]]}]

blackbox1 blackbox2 blackbox3

These $9 \times 3$ black boxes mean proof complete, and it may even be possible to recover the secret extra data "knight's move" by comparing regular first two prints, with odd third (proof unknown). More importantly, since this experiment was successful on 9 varied attempts, we have a new mission objective to prove the conjecture that the same process produces perfectly decodable data for any possible bitmap input.

We can also formulate another similar conjecture for fully layered projections. Using the following functions, we obtain new results in three colors:

Ambigram[TriadData_] := With[
{partials = Partials[Sequence @@ #] &@TriadData},
  Graphics3D[ Transpose[{{Blue, Red, Green}, Map[Cuboid, partials, {2}]}]]]

OrthoProj[Ambigram_] :=  GraphicsGrid[
Transpose[Partition[MapThread[Show[Ambigram,
       Boxed -> False, ViewProjection -> "Orthographic", 
       ViewPoint -> #1, ViewVertical -> #2] &,
     {{{0, 0, 1}, {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}},
      {{-1, 0, 0}, {-1, 0, 0}, {0, -1, 0}, {0, -1, 0}, {0, 0, -1}, {0, 0, -1}}}], 2]]]

RGBResults[TriadData_] := With[{amb = Ambigram[TriadData]},
  GraphicsRow[Show[#, ImageSize -> 400] & /@ {
     Show[amb, ViewProjection -> "Orthographic",
      ViewPoint -> {1, 1, 1}, Boxed -> False], OrthoProj[amb]}]]

amb1

amb2

amb3

amb4

amb5

amb6

amb7

amb8

amb9

Face first projections appear to be correct, but is this always the case? Does correctness of Black and White projections imply correctness of RGB projections? These questions must be answered, and theorems proven before we can even begin to think about making voxel NFTs for certain choices of three ASCII characters (or about 玄学X).

POSTED BY: Brad Klee
12 Replies
Posted 3 years ago

Hi Brad,

I still can not run through your code, different Mathematica version ( I use 12.3 Chinese Version), but understand your RGB voxel puzzle better.

I assume, you want to find the minimal space for all 2D topology shape projection. Or we can raise questions like this, "What is the minimal space / rank of 3D cubic for all 2D topology shape projection. Does it exist? always exist? or depends on some conditions?"

I usually think from the simplest case, let's say 1X1X1 cubic, firstly. In our case (Black/White = voxel is True/False), if two faces/projections need Black, but the other face needs White, 1X1X1 cubic will fail. ​if three faces need all Black or White, 1X1X1 cubic will works.

In your case (RGB), if three faces needs is individually different RGB, 1X1X1 cubic will fail. if three faces needs is compatible,......., 1X1X1 cubic will works. I don't know exactly, how you define the relation between RGB with voxel True/False.

Then you think 2X2X2 cubic, it maybe rely on some conditions, like pixel position or topology shape, or some logical operations. Or you may apply previous 1X1X1 conclusion on 2X2X2 cubic case. then 3X3X3..etc.

Anther approach, you can shrink your cubic size, so far it is 14X14X14, you shrink it into 13X13X13 or even smaller, and see if you can still find a solution.

My feeling is the connection of 2D pixel image is key, if one face Black pixel is connected and its connection can be projected on its 1 dimension line boundary and cover the whole boundary, then 2 direction projections can certainly works. If two faces has this property, then 3 direction projection must work.

Anyway, I just talk some feeling to help, that is easy. If you want to make a mathematics proof, that is hard, and still a lot of work need to do. Good luck !

POSTED BY: Frederick Wu
Posted 3 years ago

Hi Frederick, thanks for the thoughtful response.

I still can not run through your code, different Mathematica version ( I use 12.3 Chinese Version), but understand your RGB voxel puzzle better.

Curious if the problem is with rasterize or system fonts or something else. I double checked on the cloud and got a totally wacky output:

enter image description here

Magnified $10\times$ and "Antialiasing" is not an option for rasterize: "returns a rasterized version of the displayed form of expr". Suspicious behavior. Apple Safari seems to have the best display functions for CJK Unified Ideographs, see for example 道.

Otherwise, I think the code is okay when the input to function Partials is a set of $14 \times 14$ binary matrices. You suggest going smaller, but I would even consider going to $16 \times 16$ just to get a round power of two. The size of the space doesn't matter, only the size of the subspace containing non-zero values. For now leaving dimesnions as is, but later (especially when working with higher precision characters) it would be better to have adaptive sizing.

Your intuition is correct that the final theorem will involve conditionals, and I will now give a few counterexamples to show that dimensions of bounding box of non-zero subspace is an important concept in predicting output quality.

First, let me explain the math logic behind Partials, because it is kind of difficult to read in compact form. Say that we have three plane arrays of some square size, call them $Z,X,Y$, with letter indicating normal vector direction in a Cartesian $(x,y,z)$ system. Let each array contain a character pattern with binary values only, $1$ for presence (有), $0$ for absence (). The way to create a positive 3D ambigram is simply to multiply values and find a set, call it

$$A = \langle (i,j,k) \in \mathbb{Z}^3 : Z(i,j)X(j,k)Y(k,i) = 1 \rangle . $$

This would be good enough to calculate the monotone ABC ambigram from wikipedia. Indeed, the function Partials calculates $A$ first, but also calculates three supersets, which possibly intersect on $A$:

$$A_z = \langle (i,j,k) \in \mathbb{Z}^3 : X(j,k)Y(k,i) = 1 \rangle , \\ A_x = \langle (i,j,k) \in \mathbb{Z}^3 : Y(k,i)Z(i,j) = 1 \rangle , \\ A_y = \langle (i,j,k) \in \mathbb{Z}^3 : Z(i,j)X(j,k) = 1 \rangle . $$

Then it returns $A_z/A$, $A_x/A$, and $A_y/A$ as separate sets. In view outputs, elements of these sets get written to voxels in a simple $\{R,G,B\}$ color space. The complement action is important because, depending on how Graphics3D stacks coincident blocks, a wrong color could possibly occur (example follows).

To simplify the situation, we can set say $Y$ to monotone by choosing either $Y(k,i)=0$ or $Y(k,i)=1$ (over the entire domain) and see what happens.

xuanxue = "玄学";
bitmapBlank = Table[0, {i, 1, 14}, {j, 1, 14}];
bitmaps2 = With[{two = 
     RastToBitmap[Rasterize[#], 2] & /@ Characters[xuanxue]},
   Join[Flatten[Append[two, #] & /@ {bitmapBlank, bitmapBlank + 1}, 1],
    Flatten[Append[Reverse@two, #] & /@ {bitmapBlank, bitmapBlank + 1}, 1]]];
bitmaps2Ims = Image[Mod[# + 1, 2]] & /@ bitmaps2

chars

BWTest = imDat[Partials[Sequence @@ #]] & /@ Partition[bitmaps2, 3];
TableForm /@ BWTest
Flatten[Superpose /@ BWTest]
CheckVals = MapThread[ImageSubtract, 
{bitmaps2Ims, Flatten[Superpose /@ BWTest]}]

failed out

Great It worked! Except, oh wait a second, oh no!! The black check squares are hiding negative values that prove False results:

Partition[Mod[CheckVals, 2], 3]

corrected

So what happened? The bounding boxes of non-zero content do not match dimension from row to column, and this matters because they share an index diagonally. Notice that order of symbols matters, and for light on $Y$, the second character turns out wrong, while for dark on $Y$, both characters turn out fine.

Subtract @@ Reverse[MinMax[#]] & /@ 
 Transpose[Position[bitmaps2[[1]], 1]]
Subtract @@ Reverse[MinMax[#]] & /@ 
 MinMax /@ Transpose[Position[bitmaps2[[2]], 1]]
Out[] = {11,10}
Out[] = {11,10}        

The clipping actually isn't that bad, and we still get relatively readable outputs, even in three dimesions. It's interesting to see what happens choosing light or dark:

Column[RGBResults[#] & /@ Partition[bitmaps2, 3]]

test 1

test 2

test 3

test 4

To reiterate, monotone Blue voxelgrams are almost readable, while Dark Red / Green voxelgrams totally readable. Anyone can explain why one graph is all Blue, while the other no Blue?

Anyways, no we know the secret, so it leads to an exploit and "further testing". If we make the bounding box very small, then we can slice out tiny segments and make the crypto (ha ha, joke) more difficult to read.

bitmapX =   ReplacePart[
   bitmapBlank, {{7, 7} -> 1, {8, 8} -> 1, {8, 7} -> 1, {7, 8} -> 1,
    {6, 9} -> 1, {9, 6} -> 1, {6, 6} -> 1, {9, 9} -> 1}];
Exploit = {bitmaps2[[2]], bitmapX, bitmapBlank, bitmaps2[[2]], 
   bitmapBlank, bitmapX};
ExploitIm = Mod[Image[#] + 1, 2] & /@ Exploit

exploit test in

BWTest = imDat[Partials[Sequence @@ #]] & /@ Partition[Exploit, 3];
TableForm /@ BWTest;
Flatten[Superpose /@ BWTest]
Mod[MapThread[ImageSubtract, {ExploitIm, Flatten[Superpose /@ BWTest]}], 2]

exploit out

And in 3D:

test 5

test 6

These error cases are pretty convincing as to how a conditional could be written to gaurantee correct output. We need that sort of rigor before scheming about multi-million dollar autoglyph-style NFT business, possibly using some extra haskell programs. We definitely don't want multi-million dollar rounding errors!

Now the question of whether RGB face-first projection is equivalent to looking at Black and White Parts, Answer, seems yes, but maybe no. Say that we look along $z$ at either $Z(i,j)X(j,k)$ or $Y(k,i)Z(i,j)$. Chose constant $(i,j)=(a,b)$, if $Z(a,b)$ is set, then we should scan along variable $k$ and find some $Y(k,a)=1$ with $X(b,k)=0$ or some $X(b,k)=1$ with $Y(k,a)=0$, usually. A problem is if $X$ and $Y$ are transpose? Let's try one more test:

(at this point, functionalized test code needed?? )

bitmapSlash =   ReplacePart[
   Total[RotateRight[IdentityMatrix[14], #] & /@ {-1, 0, 1}], {{14, 
      1} -> 0, {1, 14} -> 0}];
Exploit2 = {Exploit[[1]], bitmapSlash, bitmapSlash};
Exploit2Im = Mod[Image[#] + 1, 2] & /@ Exploit2
BWTest = imDat[Partials[Sequence @@ #]] & /@ {Exploit2};
TableForm /@ BWTest
Flatten[Superpose /@ BWTest]
Mod[MapThread[ ImageSubtract, {Exploit2Im, Flatten[Superpose /@ BWTest]}], 2]
RGBResults[Exploit2]

slash learning

slash learning 3d

But ah ha! We also need $a=b$ chosen on diagonal, then the slash cut shows up, but it is in the Black / White data as desired. Whew, close call! Similarly if there is a natural absence, it should also occur in the Black / White data before RGB. What we can't predict easily is which correct color will show up where.

A few more counter cases, and the theorem will probably turn out clear as space.

POSTED BY: Brad Klee
Posted 3 years ago

Hi Brad,

Thanks for your kindly explanation.

My version still runs with some warnings, so I check it on Wolfram Cloud, It's same warning. I uploaded my notebook and Wolfram Cloud images. enter image description here

The diagonal finding is absolutely big progress for this puzzle. Congratulation! Character pixel like "---"," | “, works only in one direction, but fails in another. Projection to row and column must be full.So," / "or " \ " can works in both directions, then "C" or "S" that might be also works.

In my opinion, your project is 牛B (Super-cool) !

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract

Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use