Example #1
0
def showBPImg(pV, nV, t):
    """Summary
    This function encapsulates the routine to generate rectified backprojected views of 
    one opponent retinal ganglion cell
    Args:
        pV (vector): Positive rectified imagevector
        nV (vector): Negative rectified imagevector
        t (int): Index position of opponent cell species
    Returns:
        merge: Return a merged image of all backprojected opponent cells as a numpy image array
    """

    inverse = ret0.inverse(
        retina_cuda.convert_from_Piotr(pV[:, t, :].astype(float)))
    inv_crop = retina.crop(inverse, int(img.shape[1] / 2),
                           int(img.shape[0] / 2), loc[0])

    inverse2 = ret1.inverse(
        retina_cuda.convert_from_Piotr(nV[:, t, :].astype(float)))
    inv_crop2 = retina.crop(inverse2, int(img.shape[1] / 2),
                            int(img.shape[0] / 2), dloc[0])
    cv2.putText(inv_crop, types[t] + " + ", (1, 270), font, 1, (0, 255, 255),
                2)
    cv2.putText(inv_crop2, types[t] + " - ", (1, 270), font, 1, (0, 255, 255),
                2)

    merge = np.concatenate((inv_crop, inv_crop2), axis=1)
    return merge
Example #2
0
def showNonOpponency(C, theta):
    """Summary
    This function encapsulates the routine to generate backprojected and cortical views for 
    the magnocellular pathway retinal ganglion cells
    Args:
        C (vector): The sharp retina is passed to the function
        theta (float): A threshold value is passed to the function
    
    Returns:
        merged: Return a merged image of the backprojected view as a numpy image array
        mergecort: Return a merged image of the cortical view as a numpy image array
    """
    GI = retina.gauss_norm_img(x,
                               y,
                               dcoeff[i],
                               dloc[i],
                               imsize=imgsize,
                               rgb=False)
    # Sample using the other recepetive field, note there is no temporal response with still images
    S = retina.sample(img, x, y, dcoeff[i], dloc[i], rgb=True)
    #backproject the imagevectors
    ncentreV, nsurrV = rgc.nonopponency(C, S, theta)
    ninverse = retina.inverse(ncentreV,
                              x,
                              y,
                              dcoeff[i],
                              dloc[i],
                              GI,
                              imsize=imgsize,
                              rgb=True)
    ninv_crop = retina.crop(ninverse, x, y, dloc[i])
    ninverse2 = retina.inverse(nsurrV,
                               x,
                               y,
                               dcoeff[i],
                               dloc[i],
                               GI,
                               imsize=imgsize,
                               rgb=True)
    ninv_crop2 = retina.crop(ninverse2, x, y, dloc[i])
    # place descriptive text onto generated images
    cv2.putText(ninv_crop, "R+G + ", (xx, yy), font, 1, (255, 255, 255), 2)
    cv2.putText(ninv_crop2, "R+G - ", (xx, yy), font, 1, (255, 255, 255), 2)
    merged = np.concatenate((ninv_crop, ninv_crop2), axis=1)

    # create cortical maps of the imagevectors
    lposnon, rposnon = cortex.cort_img(ncentreV, L, L_loc, R, R_loc, cort_size,
                                       G)
    lnegnon, rnegnon = cortex.cort_img(nsurrV, L, L_loc, R, R_loc, cort_size,
                                       G)
    pos_cort_img = np.concatenate((np.rot90(lposnon), np.rot90(rposnon, k=3)),
                                  axis=1)
    neg_cort_img = np.concatenate((np.rot90(lnegnon), np.rot90(rnegnon, k=3)),
                                  axis=1)
    mergecort = np.concatenate((pos_cort_img, neg_cort_img), axis=1)
    return merged, mergecort
Example #3
0
def showNonOpponency(C, theta):
    """Summary
    This function encapsulates the routine to generate backprojected and cortical views for 
    the magnocellular pathway retinal ganglion cells
    Args:
        C (vector): The sharp retina is passed to the function
        theta (float): A threshold value is passed to the function
    
    Returns:
        merged: Return a merged image of the backprojected view as a numpy image array
        mergecort: Return a merged image of the cortical view as a numpy image array
    """
    # Sample using accelerated retina function
    S = ret1.sample(lateimg)  # SURROUND
    S = retina_cuda.convert_to_Piotr(S)
    #showretina:
    #return the modified,rectified imagevectors
    ncentreV, nsurrV = rgc.nonopponency(C, S, theta)
    # generate packprojected images
    ninverse = ret0.inverse(
        retina_cuda.convert_from_Piotr(ncentreV.astype(float)))
    ninv_crop = retina.crop(ninverse, int(img.shape[1] / 2),
                            int(img.shape[0] / 2), loc[0])

    ninverse2 = ret1.inverse(
        retina_cuda.convert_from_Piotr(nsurrV.astype(float)))
    ninv_crop2 = retina.crop(ninverse2, int(img.shape[1] / 2),
                             int(img.shape[0] / 2), dloc[0])
    # place descriptive text onto generated images
    cv2.putText(ninv_crop, "R+G + ", (1, 270), font, 1, (0, 255, 255), 2)
    cv2.putText(ninv_crop2, "R+G - ", (1, 270), font, 1, (0, 255, 255), 2)

    merged = np.concatenate((ninv_crop, ninv_crop2), axis=1)

    #showcortex
    ## create cortical maps of the imagevectors using accelerated functions
    lposnon = cort0.cort_image_left(
        retina_cuda.convert_from_Piotr(ncentreV.astype(float)))
    rposnon = cort0.cort_image_right(
        retina_cuda.convert_from_Piotr(ncentreV.astype(float)))
    lnegnon = cort1.cort_image_left(
        retina_cuda.convert_from_Piotr(nsurrV.astype(float)))
    rnegnon = cort1.cort_image_right(
        retina_cuda.convert_from_Piotr(nsurrV.astype(float)))
    pos_cort_img_non = np.concatenate(
        (np.rot90(lposnon), np.rot90(rposnon, k=3)), axis=1)
    neg_cort_img_non = np.concatenate(
        (np.rot90(lnegnon), np.rot90(rnegnon, k=3)), axis=1)
    # merge left and right hemispheres
    mergedcortex = np.concatenate((pos_cort_img_non, neg_cort_img_non), axis=1)
    return merged, mergedcortex
Example #4
0
def showBPImg(pV, nV):
    """Summary
    This function encapsulates the routine to generate rectified backprojected views of 
    all opponent retinal ganglion cells
    Args:
        pV (vector): Positive rectified imagevector
        nV (vector): Negative rectified imagevector
    
    Returns:
        merge: Return a merged image of all backprojected opponent cells as a numpy image array
    """
    # object arrays of the positive and negative images
    inv_crop = np.empty(8, dtype=object)
    inv_crop2 = np.empty(8, dtype=object)
    for t in range(8):
        # backprojection functions
        inverse = retina.inverse(pV[:, t, :],
                                 x,
                                 y,
                                 dcoeff[i],
                                 dloc[i],
                                 GI,
                                 imsize=imgsize,
                                 rgb=True)
        inv_crop[t] = retina.crop(inverse, x, y, dloc[i])

        inverse2 = retina.inverse(nV[:, t, :],
                                  x,
                                  y,
                                  dcoeff[i],
                                  dloc[i],
                                  GI,
                                  imsize=imgsize,
                                  rgb=True)
        inv_crop2[t] = retina.crop(inverse2, x, y, dloc[i])
        # place descriptions
        cv2.putText(inv_crop[t], types[t] + " + ", (1, 270), font, 1,
                    (0, 255, 255), 2)
        cv2.putText(inv_crop2[t], types[t] + " - ", (1, 270), font, 1,
                    (0, 255, 255), 2)
    # stack all images into a grid
    posRG = np.vstack((inv_crop[:4]))
    negRG = np.vstack((inv_crop2[:4]))
    posYB = np.vstack((inv_crop[4:]))
    negYB = np.vstack((inv_crop2[4:]))
    merge = np.concatenate((posRG, negRG, posYB, negYB), axis=1)
    return merge
Example #5
0
def showNonOpponency(C, theta):
    """Summary
    This function encapsulates the routine to generate backprojected and cortical views for 
    the magnocellular pathway retinal ganglion cells
    Args:
        C (vector): The sharp retina is passed to the function
        theta (float): A threshold value is passed to the function
    
    Returns:
        merged: Return a merged image of the backprojected view as a numpy image array
        mergecort: Return a merged image of the cortical view as a numpy image array
    """
    # Sample using the other recepetive field, but with a temporally different image, lateimg
    S = retina.sample(lateimg, x, y, dcoeff[i], dloc[i], rgb=True)

    ncentreV, nsurrV = rgc.nonopponency(C, S, theta)
    ninverse = retina.inverse(ncentreV,
                              x,
                              y,
                              dcoeff[i],
                              dloc[i],
                              GI,
                              imsize=imgsize,
                              rgb=False)
    ninv_crop = retina.crop(ninverse, x, y, dloc[i])
    ninverse2 = retina.inverse(nsurrV,
                               x,
                               y,
                               dcoeff[i],
                               dloc[i],
                               GI,
                               imsize=imgsize,
                               rgb=False)
    ninv_crop2 = retina.crop(ninverse2, x, y, dloc[i])
    merged = np.concatenate((ninv_crop, ninv_crop2), axis=1)

    lposnon, rposnon = cortex.cort_img(ncentreV, L, L_loc, R, R_loc, cort_size,
                                       G)
    lnegnon, rnegnon = cortex.cort_img(nsurrV, L, L_loc, R, R_loc, cort_size,
                                       G)
    pos_cort_img = np.concatenate((np.rot90(lposnon), np.rot90(rposnon, k=3)),
                                  axis=1)
    neg_cort_img = np.concatenate((np.rot90(lnegnon), np.rot90(rnegnon, k=3)),
                                  axis=1)
    mergecort = np.concatenate((pos_cort_img, neg_cort_img), axis=1)

    return merged, mergecort
Example #6
0
def showBPImg(pV, nV, t):
    """Summary
    This function encapsulates the routine to generate rectified backprojected views of 
    one opponent retinal ganglion cell
    Args:
        pV (vector): Positive rectified imagevector
        nV (vector): Negative rectified imagevector
        t (int): Index position of opponent cell species
    Returns:
        merge: Return a merged image of all backprojected opponent cells as a numpy image array
    """
    # backprojection functions
    inverse = retina.inverse(pV[:, t, :],
                             x,
                             y,
                             dcoeff[i],
                             dloc[i],
                             GI,
                             imsize=imgsize,
                             rgb=True)
    inv_crop = retina.crop(inverse, x, y, dloc[i])

    inverse2 = retina.inverse(nV[:, t, :],
                              x,
                              y,
                              dcoeff[i],
                              dloc[i],
                              GI,
                              imsize=imgsize,
                              rgb=True)
    inv_crop2 = retina.crop(inverse2, x, y, dloc[i])
    # place descriptions
    cv2.putText(inv_crop, types[t] + " + ", (1, 270), font, 1, (0, 255, 255),
                2)
    cv2.putText(inv_crop2, types[t] + " - ", (1, 270), font, 1, (0, 255, 255),
                2)

    merge = np.concatenate((inv_crop, inv_crop2), axis=1)
    return merge
Example #7
0
def preview():
    stdimg_dir = os.getcwd() + os.sep + 'testimage\\'
    print "Using " + os.listdir(stdimg_dir)[0]

    name = os.listdir(stdimg_dir)[0]

    standard_image = cv2.imread(stdimg_dir + name, )
    img = cv2.normalize(standard_image.astype('float'), None, 0.0, 1.0,
                        cv2.NORM_MINMAX)
    img = cv2.cvtColor(standard_image, cv2.COLOR_BGR2GRAY)
    x, y = img.shape[1] / 2, img.shape[0] / 2
    size = img.shape

    oz_V = retina.sample(img, x, y, ozimek_coeff, ozimek_loc, rgb=False)
    oz_GI = retina.gauss_norm_img(x, y, ozimek_coeff, ozimek_loc, imsize=size)
    oz_I = retina.inverse(oz_V,
                          x,
                          y,
                          ozimek_coeff,
                          ozimek_loc,
                          oz_GI,
                          imsize=size,
                          rgb=False)
    oz_I_crop = retina.crop(oz_I, x, y, ozimek_loc)
    oz_GI_crop = retina.crop(oz_GI, x, y, ozimek_loc)

    # test application of retinal receptive field
    plt.figure(figsize=(6, 6), num="Test application of retinal field")
    plt.axis('off')
    plt.imshow(oz_I_crop, cmap='gray')
    plt.show()

    #heatmap of retinal receptive field
    plt.figure(figsize=(6, 6), num="Heatmap of retina")
    plt.axis('off')
    plt.imshow(oz_GI_crop, cmap='RdBu')
    plt.show()
Example #8
0
def showBPImg(pV, nV):
    """Summary
    This function encapsulates the routine to generate rectified backprojected views of 
    all opponent retinal ganglion cells
    Args:
        pV (vector): Positive rectified imagevector
        nV (vector): Negative rectified imagevector
    
    Returns:
        merge: Return a merged image of all backprojected opponent cells as a numpy image array
    """
    # object arrays of the positive and negative images
    inv_crop = np.empty(8, dtype=object)
    inv_crop2 = np.empty(8, dtype=object)
    for i in range(8):
        # backprojection functions
        inverse = ret0.inverse(
            retina_cuda.convert_from_Piotr(pV[:, i, :].astype(float)))
        inv_crop[i] = retina.crop(inverse, int(img.shape[1] / 2),
                                  int(img.shape[0] / 2), loc[0])

        inverse2 = ret1.inverse(
            retina_cuda.convert_from_Piotr(nV[:, i, :].astype(float)))
        inv_crop2[i] = retina.crop(inverse2, int(img.shape[1] / 2),
                                   int(img.shape[0] / 2), dloc[0])
        cv2.putText(inv_crop[i], types[i] + " + ", (1, 270), font, 1,
                    (0, 255, 255), 2)
        cv2.putText(inv_crop2[i], types[i] + " - ", (1, 270), font, 1,
                    (0, 255, 255), 2)
    # stack all images into a grid
    posRG = np.vstack((inv_crop[:4]))
    negRG = np.vstack((inv_crop2[:4]))
    posYB = np.vstack((inv_crop[4:]))
    negYB = np.vstack((inv_crop2[4:]))
    merge = np.concatenate((posRG, negRG, posYB, negYB), axis=1)
    return merge