Example #1
0
 def _get_grid_img(self, crop_img, elem_contour):
     cnt = Contour(elem_contour)
     halfbox = cnt.shrinkbox(100).astype("f")
     square = self._square_coordinates(cnt.side)
     trans = cv2.getPerspectiveTransform(halfbox, square)
     box = cv2.warpPerspective(crop_img, trans, (cnt.side, cnt.side))
     _, thresh = cv2.threshold(box, 127, 255, 0)
     binary = pm.binary(thresh)
     box = binary.astype(int) * 255
     box = pm.edgeoff(box)
     box = mh.croptobbox(box)
     return box
def GradBasedSegmentation(im):
    blur = nd.gaussian_filter(im, 16)
    rmax = pymorph.regmax(blur)
    T = mahotas.thresholding.otsu(blur)
    bImg0 = im > T
    # bImg01=nd.binary_closing(bImg0,iterations=2)
    bImg01 = pymorph.close(bImg0, pymorph.sedisk(3))
    bImg = pymorph.open(bImg01, pymorph.sedisk(4))
    # bImg=nd.binary_opening(bImg01,iterations=3)
    b = pymorph.edgeoff(bImg)
    d = distanceTranform(b)
    seeds, nr_nuclei = nd.label(rmax)
    lab = mahotas.cwatershed(d, seeds)
    return lab
Example #3
0
def GradBasedSegmentation(im):
    blur=nd.gaussian_filter(im, 16)
    rmax = pymorph.regmax(blur)
    T = mahotas.thresholding.otsu(blur)
    bImg0=im>T
    #bImg01=nd.binary_closing(bImg0,iterations=2)
    bImg01=pymorph.close(bImg0, pymorph.sedisk(3))
    bImg=pymorph.open(bImg01, pymorph.sedisk(4))
    #bImg=nd.binary_opening(bImg01,iterations=3)
    b=pymorph.edgeoff(bImg)
    d=distanceTranform(b)
    seeds,nr_nuclei = nd.label(rmax)
    lab=mahotas.cwatershed(d,seeds)
    return lab