Esempio n. 1
0
class CorticalMapping:
    def __init__(self):
        self.R = None
        self.C = None
        self.fixation = None

    def setup_cortex(self, cortex_left, cortex_right):
        #Create and prepare cortex
        self.C = Cortex()
        lp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_left))
        rp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_right))
        self.C.loadLocs(lp, rp)
        self.C.loadCoeffs(
            join(datadir, "cortices", "{0}coeff.pkl".format(cortex_left)),
            join(datadir, "cortices", "{0}coeff.pkl".format(cortex_right)))

    def setup_retina(self, retina_resolution):
        #Create and load retina
        self.R = Retina()
        self.R.info()
        self.R.loadLoc(
            join(datadir, "retinas", "{0}_loc.pkl".format(retina_resolution)))
        self.R.loadCoeff(
            join(datadir, "retinas",
                 "{0}_coeff.pkl".format(retina_resolution)))

        # img = cv2.imread("{}/examples/mario.png".format(os.getcwd()), cv2.IMREAD_COLOR)
        # print(os.getcwd())
        # print(type(img))

        #Prepare retina
        # x = img.shape[1]/2
        # y = img.shape[0]/2
        # print("X: ", x)
        # print("Y: ", y)
        # print("Retina shape: ", img.shape)
        x = 120.0
        y = 112.0
        self.fixation = (y, x)
        self.R.prepare((224, 240, 3), self.fixation)

    def cortical_transform(self, im_array):
        V = self.R.sample(im_array, self.fixation)
        cimg = self.C.cort_img(V)
        # print("Cimg type: ", type(cimg))
        return cimg

    def backproject_transform(self, im_array):
        V = self.R.sample(im_array, self.fixation)
        tight = self.R.backproject_tight_last()
        # print("Cimg type: ", type(cimg))
        return tight

    def arr_to_img(self, img_arr, index):
        cv2.imwrite(
            "{}/test_images/test_image_{}.jpg".format(os.getcwd(), index),
            img_arr)
Esempio n. 2
0
C = utils.loadPickle(join(pyr_path, "50K_pyr_narrow_coeffs.pkl"))
C2 = utils.loadPickle(join(pyr_path, "50K_pyr_wide_coeffs.pkl"))

narrow = Pyramid(tess=L, coeffs=C, N=N, R=R)
wide = Pyramid(tess=L2, coeffs=C2, N=N2, R=R)

donarrow = False
dowide = False
dodog = True

while True:
    ret, img = cap.read()
    if ret is True:
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        V = R.sample(img, fixation)
        tight = R.backproject_tight_last()

        narrow_PV = narrow.sample(V)
        wide_PV = wide.sample(V)
        DoG = wide_PV - narrow_PV

        cv2.namedWindow("inverted", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("inverted", tight)

        cv2.namedWindow("input", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("input", img)

        if donarrow: narrow_vis = narrow.backproject_last()
        if dowide: wide_vis = wide.backproject_last()
        if dodog:
            DoG_vis = narrow.backproject(DoG, R._imsize, fixation, n=False)