Home > Blockchain >  OpenCV Annulus region of interest
OpenCV Annulus region of interest

Time:08-08

I defined annulus ROI selection function and i would like to find contours in this area. But contours pixel values are neighbors to the zero and out of masked areas equal to zero. Therefore contours couldn't be catch thresholded image.

How can i define annulus ROI or find the contours if function is ok

    def annulusROI(img, center, innerR, outerR):
        """
        img: Image matrix
        center: ROI center point [px] (x,y tuple)
        innerR: ROI inner radius [px]
        outerR: ROI outer radius [px]
        mode: Mask selection for white (255, 255, 255), for black (0, 0, 0) [BGR tuple]
    
        return roi matrix and left-top start point coordinate
        """
        outRoi, rectC = rectangleROI(img, center, outerR*2, outerR*2)
        mask1 = np.zeros_like(outRoi)
        mask2 = np.zeros_like(outRoi)
        mask1 = cv2.circle(mask1, (round(outerR),round(outerR)), innerR, (255, 255, 255), -1)
        mask2 = cv2.circle(mask2, (round(outerR),round(outerR)), outerR, (255, 255, 255), -1)
        mask = cv2.subtract(mask2, mask1)
        roi = cv2.bitwise_and(outRoi, mask)
    
        return roi, (center[0]-outerR, center[1]-innerR)

output

  • Related