Selecting the region of interest of an image

Let's try to select the tree in the preceding screenshot. Looking at the image with axis labels, it is evident that vertical bounds of the tree are within 50 to 155 pixels while horizontal bounds are within 95 to 190 pixels. Let's try to subset this region with all the channels:

img_tree=img[50:155,95:190,:]
plt.imshow(img_tree)

The following image shows us the region of interest (ROI) that is selected therein:

Selecting an ROI in an image

This operation is akin to cropping an image.

The pixel values of a certain ROI or a channel can be assigned some different values. This can be used to do the following:

  • Remove certain channels (if we replace the values in that channel with 0)
  • Copy and paste a certain ROI to another part of the image

The following code shows an example of the latter case:

img3=img
img3[50:155,1:96,:]=img_tree
plt.imshow(img3)

The following image shows the selected ROI that is being pasted to another image area:

Pasting a selected ROI to another image area

In this example, we have copied the tree ROI and pasted it to an area to the left of the selected ROI. This has been obtained by assigning the pixels of the pasting destination values equal to the pixel value of the copy source.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset