Beispiel #1
0
def _mdsplot(x, y, icons=None, zoom=None, **kwargs):
    ax = sns.plt.gca()
    x_inches = sns.plt.gcf().get_size_inches()[0]
    x_range = np.ptp(x)

    for imname, xi, yi in zip(icons, x, y):
        if isinstance(imname, (str, unicode)):
            im = utils.load_image(imname, flatten=False, keep_alpha=True)
        else:
            im = imname
        if zoom is None:
            zoom = max(im.shape[:2]) / 2000.
        # zoom = .1 #max(im.shape[:2]) / 3000. * x_inches/3.

        imagebox = OffsetImage(im, zoom=zoom)
        ab = AnnotationBbox(
            imagebox,
            (xi, yi),
            xybox=(0, 0),  #(20., -20.),
            xycoords='data',
            boxcoords="offset points",
            frameon=False)
        ax.add_artist(ab)

    ax.scatter(x, y, **kwargs)
    ax.axis('off')
Beispiel #2
0
def _mdsplot(x, y, icons=None, zoom=None, **kwargs):
    ax = sns.plt.gca()
    x_inches = sns.plt.gcf().get_size_inches()[0]
    x_range = np.ptp(x)

    for imname, xi, yi in zip(icons, x, y):
        if isinstance(imname, (str, unicode)):
            im = utils.load_image(imname, flatten=False, keep_alpha=True)
        else:
            im = imname
        if zoom is None:
            zoom = max(im.shape[:2]) / 2000.
        # zoom = .1 #max(im.shape[:2]) / 3000. * x_inches/3.

        imagebox = OffsetImage(im, zoom=zoom)
        ab = AnnotationBbox(imagebox, (xi, yi),
                            xybox=(0,0), #(20., -20.),
                            xycoords='data',
                            boxcoords="offset points",
                            frameon=False
                            )
        ax.add_artist(ab)

    ax.scatter(x, y, **kwargs)
    ax.axis('off')
Beispiel #3
0
 def test_gaborjet_mag(self):
     stim = utils.load_image('psychopy_ext/tests/cat-gray.png')
     im = np.array([skimage.img_as_ubyte(stim)]).astype(float)
     self.run_model('gaborjet',
                    im,
                    layers='phases',
                    flatten=True,
                    suffix='-phase-matlab')
Beispiel #4
0
 def mds(self):
     p = sns.color_palette('Set2', 8)
     colors = [p[1], p[5], p[6], p[2], p[3], p[7]]
     icons = []
     ims = sorted(glob.glob('fonts/img/alpha/*.png'))
     for i,c in enumerate(self.dims['shape']):
         icon = utils.load_image(ims[i], keep_alpha=True)
         icon[:,:,:3][icon[:,:,3]>0] = colors[c][0], colors[c][1], colors[c][2]
         icons.append(icon)
     super(Fonts, self).mds(icons=icons, seed=0, zoom=.2)
Beispiel #5
0
 def mds(self):
     p = sns.color_palette('Set2', 8)
     colors = [p[1], p[5], p[6], p[2], p[3], p[7]]
     icons = []
     ims = sorted(glob.glob('fonts/img/alpha/*.png'))
     for i, c in enumerate(self.dims['shape']):
         icon = utils.load_image(ims[i], keep_alpha=True)
         icon[:, :, :3][
             icon[:, :, 3] > 0] = colors[c][0], colors[c][1], colors[c][2]
         icons.append(icon)
     super(Fonts, self).mds(icons=icons, seed=0, zoom=.2)
Beispiel #6
0
 def mds(self):
     p = sns.color_palette('Set2', 8)
     colors = [p[1], p[5], p[6], p[2], p[3], p[7]]
     icons = []
     ims = sorted(glob.glob('stefania/img/alpha/*.png'))
     if len(ims) == 0:
         self.get_images()
     for imno,c in enumerate(self.dims['category']):
         im = utils.load_image(ims[imno], keep_alpha=True)
         mask = im[:,:,3]>0
         im[:,:,:3][mask] = colors[c][0], colors[c][1], colors[c][2]
         icons.append(im)
     super(Stefania, self).mds(icons=icons, seed=0, zoom=.15)
Beispiel #7
0
 def mds_outlines(self):
     p = sns.color_palette('Set2', 8)
     colors = [p[1], p[5], p[6], p[2], p[3], p[7]]
     icons = []
     ims = sorted(glob.glob('stefania/img/alpha/*.png'))
     for imno,c in enumerate(self.dims['category']):
         im = utils.load_image(ims[imno], keep_alpha=True)
         # generate outlines
         mask = im[:,:,3]>0
         icon = scipy.ndimage.binary_dilation(mask, structure=np.ones((50,50)))
         icon = np.dstack([icon*colors[c][i] for i in range(3)] + [(icon>0).astype(float)])
         icon[mask] = im[mask]
         icons.append(icon)
     super(Stefania, self).mds(icons=icons, seed=0, zoom=.15)
Beispiel #8
0
    def _gen_alpha(self):
        path = 'hop2008/img/alpha'
        if not os.path.isdir(path): os.makedirs(path)
        for f in sorted(glob.glob('hop2008/img/*.tif')):
            fname = os.path.basename(f)
            newname = fname.split('.')[0] + '.png'
            newname = os.path.join(path, newname)
            # and now some ridiculousness just because ImageMagick can't make
            # alpha channel for no reason
            alphaname = fname.split('.')[0] + '_alpha.png'
            alphaname = os.path.join(path, alphaname)

            subprocess.call('convert {} -alpha set -channel RGBA '
                            '-fuzz 10% -fill none '
                            '-floodfill +0+0 rgba(100,100,100,0) '
                            '{}'.format(f, newname).split())
            subprocess.call('convert {} -alpha set -channel RGBA '
                            '-fuzz 10% -fill none '
                            '-floodfill +0+0 rgb(100,100,100) '
                            '-alpha extract {}'.format(f, alphaname).split())
            im = utils.load_image(newname)
            alpha = utils.load_image(alphaname)
            scipy.misc.imsave(newname, np.dstack([im,im,im,alpha]))
            os.remove(alphaname)
Beispiel #9
0
    def _gen_alpha(self):
        path = 'hop2008/img/alpha'
        if not os.path.isdir(path): os.makedirs(path)
        for f in sorted(glob.glob('hop2008/img/*.tif')):
            fname = os.path.basename(f)
            newname = fname.split('.')[0] + '.png'
            newname = os.path.join(path, newname)
            # and now some ridiculousness just because ImageMagick can't make
            # alpha channel for no reason
            alphaname = fname.split('.')[0] + '_alpha.png'
            alphaname = os.path.join(path, alphaname)

            subprocess.call('convert {} -alpha set -channel RGBA '
                            '-fuzz 10% -fill none '
                            '-floodfill +0+0 rgba(100,100,100,0) '
                            '{}'.format(f, newname).split())
            subprocess.call('convert {} -alpha set -channel RGBA '
                            '-fuzz 10% -fill none '
                            '-floodfill +0+0 rgb(100,100,100) '
                            '-alpha extract {}'.format(f, alphaname).split())
            im = utils.load_image(newname)
            alpha = utils.load_image(alphaname)
            scipy.misc.imsave(newname, np.dstack([im, im, im, alpha]))
            os.remove(alphaname)
Beispiel #10
0
def load_image(im, resize=None, *args, **kwargs):
    return utils.load_image(im, resize=(256, 256), *args, **kwargs)
Beispiel #11
0
def load_image(im, resize=None, *args, **kwargs):
    return utils.load_image(im, resize=(256, 256), *args, **kwargs)
Beispiel #12
0
 def test_hmax99_gabor(self):
     stim = utils.load_image('psychopy_ext/tests/cat-gray.png')
     im = np.array([skimage.img_as_ubyte(stim)]).astype(float)
     m = models.HMAX99(matlab=True, filter_type='gabor')
     self.run_model(m, im, flatten=True, suffix='-gabor-matlab')
 def test_hmax99_gabor(self):
     stim = utils.load_image('psychopy_ext/tests/cat-gray.png')
     im = np.array([skimage.img_as_ubyte(stim)]).astype(float)
     m = models.HMAX99(matlab=True, filter_type='gabor')
     self.run_model(m, im, flatten=True, suffix='-gabor-matlab')
 def test_gaborjet_mag(self):
     stim = utils.load_image('psychopy_ext/tests/cat-gray.png')
     im = np.array([skimage.img_as_ubyte(stim)]).astype(float)
     self.run_model('gaborjet', im, layers='phases', flatten=True, suffix='-phase-matlab')