Example #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)
Example #2
0
    def test_imagevector_integrity(self):
        print(
            "Testing imagevector integrity over storing in model and storing in file..."
        )
        cap = utils.camopen()
        ret, campic = cap.read()

        R = Retina()
        R.info()
        R.loadLoc(os.path.join(datadir, "retinas", "ret50k_loc.pkl"))
        R.loadCoeff(os.path.join(datadir, "retinas", "ret50k_coeff.pkl"))

        x = campic.shape[1] / 2
        y = campic.shape[0] / 2
        fixation = (y, x)
        R.prepare(campic.shape, fixation)

        ret, img = cap.read()
        if ret:
            V = R.sample(img, fixation)

        originalvector = ImageVector(V,
                                     framenum=1,
                                     timestamp="HH:MM:SS.SS",
                                     label="dummy",
                                     fixationy=y,
                                     fixationx=x,
                                     retinatype="50k")
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in model')

        vectors = [originalvector]
        ip.saveHDF5(os.path.join("testdata", "integritytest.h5"), vectors)
        newvectors = ip.loadhdf5(os.path.join("testdata", "integritytest.h5"),
                                 None)
        newvector = newvectors[0]
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in HDF5')

        ip.saveCSV(os.path.join("testdata", "integritytest.csv"), vectors)
        newvectors = ip.loadCsv(os.path.join("testdata", "integritytest.csv"),
                                None)
        newvector = newvectors[0]
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in CSV')

        print("Vector has not been modified by the system")
Example #3
0
#Open webcam
cap = utils.camopen()  #cap is the capture object (global)
ret, campic = cap.read()

#Create and load retina
R = Retina()
R.info()
R.loadLoc(join(datadir, "retinas", "ret50k_loc.pkl"))
R.loadCoeff(join(datadir, "retinas", "ret50k_coeff.pkl"))

#Prepare retina
x = campic.shape[1] / 2
y = campic.shape[0] / 2
fixation = (y, x)
R.prepare(campic.shape, fixation)

#Prepare pyramid
pyr_path = join(datadir, "pyramid")
L = utils.loadPickle(join(pyr_path, "50K_pyr_narrow_tessellations.pkl"))
L2 = utils.loadPickle(join(pyr_path, "50K_pyr_wide_tessellations.pkl"))
N = utils.loadPickle(join(pyr_path, "50K_pyr_narrow_normmaps.pkl"))
N2 = utils.loadPickle(join(pyr_path, "50K_pyr_wide_normmaps.pkl"))
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