Zend certified PHP/Magento developer

Magento 2.2 display swatch image on fProduct Page

Magento 2.2.2
I have in my view.phtml the following code

/app/design/frontend/mytheme/shop/Magento_Catalog/templates/product
view.phtml


$img1 = $products->getResource()->getAttribute('icon_image_1')->getFrontend()->getValue($_product);

     $label1 = $products->getResource()->getAttribute('icon_image_label_1')->getFrontend()->getValue($_product);

$img11 = $url . "/catalog/product/" . $img1;
Magento 2.2.2
< ?php if ($img1 != 'no_selection' && $img1 != ''): ?>
< ?php echo $label1; ?>

This is used to display on the product page small icon images at the moment the attribute has been created with Catalog Input Type for Store Owner, Media Image

I also have a piece of text attribute called icon_image_label_1 which is displayed next to the icon – which explains what the icon is showing.

Both attributes are imported during product import stage via a csv file which has the separate column for icon_image_1 and icon_image_label_1

Although it is working fine and displaying on front end I am getting an issue – It is displaying an icon image and icon image label on products which dont have this attribute – I have checked and both attributes dont have any default setting – so I can’t work out how it is getting this value – I have checked the products in Admin and can not see the icon image in the media section – (which is correct) so how is it being displayed on frontend?

Secondly – I wanted to change the icon_image_1 attribute from Media image to visual_swatch instead so I can import these separately using a different csv import file –

To try I have changed in the database table eav_attribute and edited it for icon_image_1 media_image to select – then in Admin I selected for Catalog Input Type for Store Owner Visual Swatch

please can someone explain how to call a swatch image in the view.phtml file
and show nothing if no value has been selected for icon_image_1

I have also uploaded my icon images .png files onto my server under pub/media/icon_images