# Why does SameQ act inconsistently with Images wrapped in {} versus not?

Take an Image that is displayed in a GraphicsBox, e.g. the result of Import["ExampleData/rose.gif"], and place a copy of it next to it, separated by ===.

Evaluating this will give True. If you resize one of the images, you still get True.

This makes some sense conceptually, because data-wise, the images are the same. The underlying expression however changed (look at the FullForm or BoxForm of the two) and I thought SameQ is supposed to test structural expression equivalence.

Irritatingly, this seems to be what is reported once you put these expressions into braces:

{-put the first image here-} === {-put it's resized copy here-}

gives False. Only if you put an exact copy of either one of them you get True again.

Equal is much more consistent: It gives True in all of the above cases.

One has to be aware of this if one develops tests in Testing Notebooks: The default SameTest is SameQ, which works because of the above with single-Image output but can start to fail once you put images together with other results into lists.

I strongly suspect that this is special overloading of SameQ for Image objects, and that this overloading was only made for elements at level one, possibly via internal UpValues. Here is a mockup using neither SameQ nor Equal:

mySameQ[a___, i_Image, b___] := mySameQ[a, ImageData @ i, b]

mySameQ[a_, a_, x___] := mySameQ[a, x]
mySameQ[_] := True
mySameQ[else__] := False


This replicates the behavior of SameQ in the cases you describe.

• +1 - I'd venture the fact an image is an atom, and that is lost when enclosed in braces, is the trigger... – ciao Aug 16 '16 at 5:03
• @ciao That almost seems like a restatement of what I wrote, or at least intended. Are you agreeing with me, or suggesting that a method different from what I described and demonstrated is the cause? – Mr.Wizard Aug 16 '16 at 6:06
• I am absolutely agreeing. Have I ever not agreed with you? ;=} – ciao Aug 16 '16 at 8:04