# Simple blink comparator for two images

I tried to build a simple 'blink comparator' - where you can click on an image repeatedly to switch between two similar images. (An old-fashioned notion in the days of powerful image processing software, it's true.) I think the problem with what I've done so far is the behaviour of the symbols inside a DynamicModule:

image1 = Thumbnail[ExampleData[{"TestImage", "Mandrill"}], 300];
image2 = Thumbnail[
ColorNegate[ExampleData[{"TestImage", "Mandrill"}]], 300];
DynamicModule[{imageList = {image1, image2}},
EventHandler[
Show[
First[imageList],
Graphics[
{
Text[
Style[
"name of First[imageList]]?",
14, White],
ImageDimensions[First[imageList]]/2]
}
]],
{"MouseDown" :>
{
RotateLeft[imageList],
Beep[]
}
}]]


The Beep confirms the EventHandler action, but the image doesn't change.

-
RotateLeft doesn't change the list inplace rather it creates a new one, so your imageList is never updated –  ssch Dec 10 '12 at 11:21
Good point - but imageList = RotateLeft[imageList], doesn't seem to work... –  cormullion Dec 10 '12 at 11:24
FlipView[{image1, image2}]? –  Rojo Dec 10 '12 at 12:05
@rojo :) why didn't I search for 'flip'!? Looks like a much easier way than mine. Still, learning about Dynamic is always a good thing... :) –  cormullion Dec 10 '12 at 13:22

You need to assign imageList for it to actually update, also you need to make the graphics dynamic for it to update when the list is changed. Code changes are:

... imageList = RotateLeft[imageList] ...
... EventHandler[Dynamic@Show[First[  ...


So it's :

image1 = Thumbnail[ExampleData[{"TestImage", "Mandrill"}], 300];
image2 = Thumbnail[
ColorNegate[ExampleData[{"TestImage", "Mandrill"}]], 300];
DynamicModule[{imageList = {image1, image2}},
EventHandler[
Dynamic@Show[First[imageList],
Graphics[{Text[Style["name of First[imageList]]?", 14, White],
ImageDimensions[First[imageList]]/
2]}]], {"MouseDown" :> {imageList = RotateLeft[imageList],
Beep[]}}]]

-
@NasserM.Abbasi, @jVincent, Don't forget to wrap Show in Dynamic. –  ssch Dec 10 '12 at 11:34
@jVincent Thanks - works well. Any idea how to get the name of the currently displayed image (eg "image1") into the Text expression? –  cormullion Dec 10 '12 at 13:24
@cormullion You could simply define names={"name1","name2"}; and also rotate it when you rotate the other list; names = RotateLeft[names]. Then ofcause switch out the string you use now with First@names. –  jVincent Dec 10 '12 at 13:32
OK. I'd been fiddling with something else - yours is easier. –  cormullion Dec 10 '12 at 13:32

You can use FlipView

FlipView[{image1, image2}]

-
That's cool Rojo, I never noticed FlipView before. Thanks for the tip. –  bill s Dec 10 '12 at 19:34
Yes, good find, @rojo! –  cormullion Dec 10 '12 at 23:29

Here's a somewhat simpler approach using the Manipulate[] function:

 image1 = Thumbnail[ExampleData[{"TestImage", "Mandrill"}], 300];
image2 = Thumbnail[ColorNegate[ExampleData[{"TestImage", "Mandrill"}]], 300];
Manipulate[If[t == 1, image1, image2], {t, {0, 1}}]


Each time you click on the checkbox, it alternates between the two images.

-