UPDATE: Code from this post was used for video generation here: Cinematically moving a lens over images: magnifying glass effect in videos
I am trying to create a magnifying glass effect for images with small text and other features similar to realistic one you can see above. My basic solution is based on an example I saw in docs on ImageTransformation - see Fish Eye effect in Neat Examples section.
MG[img_, radius_, pos_, strength_] := Module[
{transform},
transform[pt_] := With[
{
r = Norm[pt - pos], (* Distance from the center of the magnifying glass *)
a = ArcTan @@ (pt - pos) (* Angle with respect to the center *)
},
If[
r < radius, (* If the point is inside the magnifying glass *)
pos + (r/strength) {Cos[a], Sin[a]}, (* Apply the magnifying effect *)
pt (* Otherwise, keep the point unchanged *)
]
];
(* Highlight the boundary of the magnifying glass using a black circle *)
HighlightImage[ImageTransformation[img, transform,
DataRange -> Full, Padding -> White], {Gray, Circle[pos, radius]}]
];
Lets get some test image:
testIMG=ImageResize[Rasterize[StringTake[
ExampleData[{"Text","DeclarationOfIndependence"}],5000]],800]
And test:
MG[testIMG, 150, {200, 200}, 2]
But it is far from good imitation of realistic optical effect. Specifically, nice "flow" features from the page and into the glass at tis edges is not recreated. Please post your versions, that can be totally different or improvements - the goal is to get best effect close to optical one. No need to imitate reflectional glaring. The arguments of the function should be at least those I used taking image and lens position, size, and magnification strength.





