Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate such an image in Mathematica

I am thinking of process an image to generate the following effect in Mathematica given its powerful image processing capabilities. Could anyone give some idea as to how to do this?

Thanks a lot.

like image 663
Qiang Li Avatar asked Jun 07 '11 22:06

Qiang Li


People also ask

How do you insert a picture in Mathematica?

From within the Wolfram System, you can choose Insert ▶ Picture ▶ From File and then choose a picture to insert, using your operating system's file browser: If you know the file path of the image on your computer, you can use Import to get the image into the Wolfram System: Copy to clipboard.


2 Answers

Here's one version, using a textures. It of course doesn't act as a real lens, just repeats portions of the image in an overlapping fashion.

t = CurrentImage[];

(* square off the image to avoid distortion *)
t = ImageCrop[t, {240,240}];

n = 20; 
Graphics[{Texture[t], 
   Table[
     Polygon[
       Table[h*{Sqrt[3]/2, 0} + (g - h)*{Sqrt[3]/4, 3/4} + {Sin[t], Cos[t]}, 
         {t, 0., 2*Pi - Pi/3, Pi/3}
         ], 
       VertexTextureCoordinates -> Transpose[{
         Rescale[
           (1/4)*Sqrt[3]*(g - h) + (Sqrt[3]*h)/2., 
           {-n/2, n/2}, 
           {0, 1}
           ] + {0, Sqrt[3]/2, Sqrt[3]/2, 0, -(Sqrt[3]/2), -(Sqrt[3]/2)}/(n/2), 
         Rescale[
           (3.*(g - h))/4, 
           {-n/2, n/2}, 
           {0, 1}
           ] + {1, 1/2, -(1/2), -1, -(1/2), 1/2}/(n/2)
         }]
      ], 
      {h, -n, n, 2}, 
      {g, -n, n, 2}
    ]
  }, 
  PlotRange -> n/2 - 1
]

Here's the above code applied to the standard image test (Lena)

enter image description here

like image 61
Brett Champion Avatar answered Oct 04 '22 22:10

Brett Champion


"I think this could be well approximated with a calculated offset for the image in each cell" - Mr.Wizard

Exactly! As you can see from reconstructed image there is no lens effect and tiles are just displacements.

enter image description here

What you need is a Hexagonal_tessellation and a simple algorithm to calculate displacement for each hexagon from some chosen central point (weight/2, height/2).

like image 33
Ross Avatar answered Oct 04 '22 22:10

Ross