Updated Below
I hope the title gets at what I'm trying to do. I have a large image for a thesis on an image processing topic, and I want show the large image, with zoomed in boxes (typically with the same aspect ratio). I also want colored frames overlaid on the large image to show what portions I'm magnifying. Here's an example:
I am currently accomplishing this by taking the large image and copying the desired zoomed areas into seperate images, and creating the overlaid frames, all in MATLAB. I then use the technique discussed in this previous question of mine to align all the images nicely.
My new question is, can a similar end product be created entirely within LaTeX so that the only external file I need is the original large image, and some LaTeX component (I'm thinking Tikz, but open to suggestions) creates the overlaid frames and cropped/ zoomed copies of it, then either arranges them as shown in my example, or uses the technique here to align them nicely.
Also, the example I showed is just a sample layout; ideally any solution would be flexible enough to allow rearrangement to some other reasonable arrangement, such as large image on top (full linewidth) with two or three zoom boxes in a horizontal line under it.
Thanks.
The image I'm working with is here:
Update
Please see Jake's response below for current best/ complete version of code. The only outstanding item is that, while subcaptions work and can be referenced with \subref{}
, the spy library processes the labels multiple times, resulting in a warning about multiply defined labels.
As such, I have elected to not use subcaptions/ labels for now since the color-coding makes pretty clear the relationship between the zoomed images and the large one. The subcaptions can be removed by replacing the line
\newcommand\phantomimage{\subcaptionbox{\label{\pgfkeysvalueof{/tikz/subfigurename}}}{\phantom{\rule{\imagewidth}{\imageheight}}}}
with
\newcommand\phantomimage{\phantom{\rule{\imagewidth}{\imageheight}}}
I've started a separate question here about the multiply-defined labels with spy
problem. I'll update this post again if any solution comes out of the new question.
Final Update
The subcaption issue has been resolved. Please see Jake's response below for final code and usage.
Best Answer
Here's an example of using the
spy
library that Martin mentioned. I've written a couple of styles that can be used to create an array of magnficiations, with an arbitrary number of rows and columns, placed on any side of the original image, with specifiable gaps. The magnifications will take up the same space as the original image.The image itself and the magnifications are
subcaptionbox
es, which requires thesubcaption
package. They are assigned labels of the form<figurename>-image
and<figurename>-zoom
, and can be referenced using\ref
and\subref
. If nofigurename
is supplied as an option to thetikzpicture
, a default name ofzoombox
will be assumed.The center points of the magnifications are specified in relative coordinates:
\zoombox{0,0}
would zoom in on the lower left corner,\zoombox{1,1}
on the upper right.You can specify the zoom factor for the individual zoomboxes using the optional argument:
\zoombox[magnification=5]{0.5,0.5}
would zoom in on the middle of the image, magnifiying 5x.Boxes and magnifications can be drawn with a coloured frame using the optional argument
[color code=<color>]
.To display a grid over the original image to aid in placing the zoom points, use the option
help grid
in the image node.Instead of using colors, black and white dash patterns can be used with the option
black and white
. This overridescolor code
options. To automatically use a different dash pattern for every box, useblack and white=cycle
.Update Fixed an issue with the black and white pattern not being correctly initialised. Thanks, SSilk.
you would use
The same example with colored outlines
Displaying a grid over the original image:
To get three magnifications in a horizontal row below the original image, like this
you would use
Using
connect zoomboxes
to draw connecting lines to link the zoomboxes to the point in the image, and also changing the line color and thickness using thezoombox paths
style:Using
black and white
to draw the boxes as black and white dashed lines:Using
black and white=cycle
to draw each box with a different black and white dash pattern:Here's the complete code: