How to get Image roles types from product programmatically Magento 2?

To Retrieve Media Images Roles type from the Product in Magento 2 is useful to know each image role whether its small_image, thumbnail, or swatch image.

When you create a product, you need to assigned roles based on its display position.

The Base Role will be displayed on the product detail page.
A small Role will be displayed on the category listing page.
The ThumbnailRole will be displayed on the Shopping Cart page.
Swatch imageRole will be displayed on the product swatches.

Call method with from the template file,

An Output look likes,

When you explore Product with SKU 24-MB04, two images are assigned to this item in Magento Open source Sample data, Based on the roles assigned to each item, you can get results for the above code.

The first Image has assigned three roles and the second image has none of the Roles assigned.