The problem in your example code is the second example uses single quote around the first paramater with the php variable inside. It should be:
<?php echo anchor('masterdata/delete_customer/'.$row->id, img(array('src'=>'images/delete_icon.png','border'=>'0','alt'=>'Delete'))); ?>
Or swapped to the double quotes.