When it comes to your question: As I understand it $node.data_map.masthead_images is an attribute of a related object. When you are using the attribute_view_gui you are then trying to view a link to an object, while what you really want to do is to view the image in the object that masterhead_images is pointing to. The correct code would be something like this:
actualy the tpl used for attribute_view_gui ( http://pubsvn.ez.no/websvn2/filedetails.php?repname=nextgen&path=%2Fstable%2F4.2%2Fdesign%2Fstandard%2Ftemplates%2Fcontent%2Fdatatype%2Fview%2Fezimage.tpl ) also check if image is empty or not, so you can remove the {if} too
@ezp core developper the tpl used /design/standard/templates/content/datatype/view/ezpimage.tpl could benefit a param to link image to node.
@akhi you should also enable debug / display used template list and check what template is used for your attribute_view_gui, it may happen that you have a override that use another tpl than the standard