示例#1
0
def showIm(ims, fig=1, title='', showz=False):
    """ Show image with nearest neighbor interpolation and axis scaling """
    plt.figure(fig)
    plt.clf()
    if showz:
        pmatlab.imshowz(ims, interpolation='nearest')
    else:
        plt.imshow(ims, interpolation='nearest')
    plt.axis('image')
    plt.title(title)
示例#2
0
def _onedotGetBlobs(fimg, fig=None):
    """ Extract blobs for a 2D scan of a one-dot """
    # thr=otsu(fimg)
    thr = np.median(fimg)
    x = np.percentile(fimg, 99.5)
    thr = thr + (x - thr) * .5
    bim = 30 * (fimg > thr).astype(np.uint8)

    xx = detect_blobs_binary(bim)

    if int(cv2.__version__[0]) >= 3:
        # opencv 3
        ww, contours, tmp = cv2.findContours(bim.copy(), cv2.RETR_EXTERNAL,
                                             cv2.CHAIN_APPROX_SIMPLE)
    else:
        contours, tmp = cv2.findContours(bim.copy(), cv2.RETR_EXTERNAL,
                                         cv2.CHAIN_APPROX_SIMPLE)

    qq = []
    for ii in range(len(contours)):
        qq += [weightedCentroid(fimg, contours, contourIdx=ii, fig=None)]
    xxw = np.array(qq)
    if fig is not None:
        plt.figure(fig)
        plt.clf()
        pgeometry.imshowz(fimg, interpolation='nearest')
        plt.axis('image')
        plt.colorbar()
        # ax = plt.gca()
        pgeometry.plotPoints(xx.T, '.g', markersize=16, label='blob centres')
        plt.title('Reponse image with detected blobs')

        plt.figure(fig + 1)
        plt.clf()
        pgeometry.imshowz(bim, interpolation='nearest')
        plt.axis('image')
        plt.colorbar()
        # ax = plt.gca()
        pgeometry.plotPoints(xxw.T, '.g', markersize=16, label='blob centres')
        pgeometry.plotPoints(xx.T,
                             '.m',
                             markersize=12,
                             label='blob centres (alternative)')
        plt.title('Binary blobs')

        pgeometry.tilefigs([fig, fig + 1], [2, 2])

    return xxw, (xx, contours)