예제 #1
0
 def find_hand_center(self, thresh):
     """
     """
     thresh[thresh > 0] = 1
     th, tw = thresh.shape
     dist = dte(thresh).flatten()  # find dist between hand pts and hand contour (can speed up)
     distidx = dist.argmax()
     return (np.mod(distidx, tw), distidx//tw)
예제 #2
0
 def voronoi(self):
     if self.verbose:
         i = [i for i in tqdm([], desc='Voronoi Segment')]
     inverted_binary_mask_stk = self.mask_stack == 0
     distance_mask_stk = dte(
         inverted_binary_mask_stk,
         sampling=[self.pixel_size, self.pixel_size, self.z_step_size])
     max_mask_stk = distance_mask_stk < self.distance_thresh
     labels = watershed(image=distance_mask_stk,
                        markers=self.mask_stack,
                        mask=max_mask_stk)
     self.voronoi_stack = labels
     self.voronoi_images = self.stack_to_images(labels)
예제 #3
0
cY = d[cidx]['y']
cdepth = d[cidx]['d']
cinside = d[cidx]['i']
ctacking = d[cidx]['s']
cjdepth = d[cidx]['rd']

coldx = []
coldy = []

oridepth = 2000
error = 0
sr = 2  # search region
from scipy.ndimage.morphology import distance_transform_edt as dte
dismtx = np.ones((sr * 2 + 1, sr * 2 + 1))
dismtx[sr, sr] = 0
dismtx = dte(dismtx)

for i in xrange(len(X)):
    print i
    if i == 0:
        oldx.append(X[i])
        oldy.append(Y[i])
        coldx.append(cX[i])
        coldy.append(cY[i])

        pass
    else:
        dist = ((X[i] - oldx[-1])**2 + (Y[i] - oldy[-1])**2)**0.5
        vx = X[i] - oldx[-1]
        vy = Y[i] - oldy[-1]
        cvx = (cX[i] - coldx[-1]) * 1
def poolCore(inAr):
    ip = imageProcessor()
    imgSub = inAr[0]

    mcdp = inAr[1]
    mcs = inAr[2]
    ct = inAr[3]

    lav = inAr[4]
    mcdp2 = inAr[5]
    mosrr = inAr[6]

    pf1 = inAr[7][0]
    pf2 = inAr[7][1]
    pf3 = inAr[7][2]

    ppbfr = inAr[8][0]
    ppbfd = inAr[8][1]

    ppbd = inAr[9][0]
    ppdr = inAr[9][1]

    pped = inAr[10][0]
    pper = inAr[10][1]

    atw = inAr[11]
    mcdp3 = inAr[12]

    y0, y1, x0, x1, yES, xES = inAr[13][0], inAr[13][1], inAr[13][2], inAr[13][
        3], inAr[13][4], inAr[13][5]
    sys.stdout.write("\r" + str(ct) + "       ")
    sys.stdout.flush()
    # print np.mean(imgSub)

    imggrab = imgSub

    imgSub = ip.floorBackgroundSubtraction(imgSub, minVal=lav)
    openingKern = np.ones((mcdp2, mcdp2), np.uint8)
    imgSub = cv2.morphologyEx(imgSub, cv2.MORPH_OPEN, openingKern)
    imgSub = ip.floorBackgroundSubtraction(imgSub,
                                           minVal=np.mean(imgSub) * mosrr)

    # fig = plt.subplot2grid((2, 2), (0, 0))
    # plt.imshow(imgSub,cmap='gray')

    if pf1:
        imgSub = cv2.bilateralFilter(np.float32(imgSub), ppbfr, ppbfd, ppbfd)
    if pf2: imgSub = ip.morphBluring(imgSub, kernelSize=ppbd, repeats=ppdr)
    if pf3: imgSub = ip.morphErode(imgSub, kernelSize=pped, repeats=pper)

    imgSub = np.array(imgSub.astype(int), dtype=np.uint8)
    imgSub = cv2.adaptiveThreshold(imgSub, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                   cv2.THRESH_BINARY, atw, 0)
    imgSub = cv2.morphologyEx(imgSub, cv2.MORPH_CLOSE, np.ones((7, 7),
                                                               np.uint8))

    # plt.subplot2grid((2, 2), (0, 1),sharex=fig,sharey=fig)
    # plt.imshow(imgSub,cmap='gray')

    imgSub = dte(imgSub != 0)
    imgSub = dte((imgSub <= mcdp3) * (imgSub != 0))

    peakList = []
    for mcd in mcdp:
        peakList = peakList + ip.xyLocalMaxFinder(
            imgSub, minpeakSpacing=mcs, minPeakVal=mcd, negationList=peakList)

    # plt.subplot2grid((2, 2), (1, 0),sharex=fig,sharey=fig)
    # plt.imshow(imgSub,cmap='jet')
    # plt.plot([c[1] for c in peakList],[c[0] for c in peakList],'mo',ms=4)

    # plt.subplot2grid((2, 2), (1, 1),sharex=fig,sharey=fig)
    # plt.imshow(imggrab,cmap='gray')
    # plt.plot([c[1] for c in peakList],[c[0] for c in peakList],'ro',ms=4)

    # plt.show()

    # plt.pause(2.0)
    # plt.clf()

    y0R, y1R = y0 + yES, y1 - yES
    x0R, x1R = x0 + xES, x1 - xES
    peakList = [(y + y0, x + x0) for (y, x) in peakList if (
        y + y0 >= y0R and y + y0 <= y1R and x + x0 >= x0R and x + x0 <= x1R)]

    return peakList