{"id":917,"date":"2018-10-03T01:24:56","date_gmt":"2018-10-03T01:24:56","guid":{"rendered":"http:\/\/muthu.co\/?p=917"},"modified":"2021-05-24T02:59:35","modified_gmt":"2021-05-24T02:59:35","slug":"draw-bounding-box-around-contours-skimage","status":"publish","type":"post","link":"http:\/\/write.muthu.co\/draw-bounding-box-around-contours-skimage\/","title":{"rendered":"Draw bounding box around contours – skimage"},"content":{"rendered":"\n
The basic idea is to find the Xmin, Xmax, Ymin, Ymax of each identified coordinates of the contour and then create a rectangle using it. Lets understand this with an example:<\/p>\n\n\n\n
Import the necessary libraries, read the input file, convert it to grayscale and plot it.<\/p>\n\n\n\n
from skimage.measure import find_contours\nfrom skimage.io import imread\nimport matplotlib.pyplot as plt\nfrom skimage.color import rgb2gray\n\norig_img = imread('resources\/stars.jpg')\ngray_img = rgb2gray(orig_img)\nplt.imshow(gray_img,interpolation='nearest', cmap=plt.cm.gray)\n\n<\/code><\/pre>\n\n\n\n