LogGabor/LogGabor.py
def golden_pyramid(self, z, mask=False, spiral=True, fig_width=13):
        """
        The Golden Laplacian Pyramid.
        To represent the edges of the image at different levels, we may use a simple recursive approach constructing progressively a set of images of decreasing sizes, from a base to the summit of a pyramid. Using simple down-scaling and up-scaling operators we may approximate well a Laplacian operator. This is represented here by stacking images on a Golden Rectangle, that is where the aspect ratio is the golden section $\phi \eqdef \frac{1+\sqrt{5}}{2}$. We present here the base image on the left and the successive levels of the pyramid in a clockwise fashion (for clarity, we stopped at level $8$). Note that here we also use $\phi^2$ (that is $\phi+1$) as the down-scaling factor so that the resolution of the pyramid images correspond across scales. Note at last that coefficient are very kurtotic: most are near zero, the distribution of coefficients has long tails.

        """
        import matplotlib.pyplot as plt

        opts= {'vmin':0., 'vmax':1., 'interpolation':'nearest', 'origin':'upper'}

        N_X, N_Y = z.shape[0], z.shape[1]
        if spiral:
            phi = (np.sqrt(5)+1.)/2. # golden ratio
            fig = plt.figure(figsize=(fig_width, N_X/N_Y*fig_width/phi), frameon=True)
            xmin, ymin, size = 0, 0, 1.
        else:
            fig = plt.figure(figsize=(fig_width, N_X/N_Y*fig_width*self.n_levels), frameon=True)

        axs = []
        for i_sf_0 in range(len(self.sf_0)):
            if spiral:
                # https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.add_axes says:
                # Add an axes at position rect [left, bottom, width, height] where all quantities are in fractions of figure width and height.
                ax = fig.add_axes((xmin/phi, ymin, size/phi, size), facecolor='w')
            else:
                ax = fig.add_axes((0, i_sf_0/self.n_levels, 1, 1/self.n_levels), facecolor='w')
            ax.axis(c='r', lw=1)
            plt.setp(ax, xticks=[], yticks=[])
            im_RGB = np.zeros((self.pe.N_X, self.pe.N_Y, 3))
            for i_theta, theta_ in enumerate(self.theta):
                im_abs = np.absolute(z[:, :, i_theta, i_sf_0])
                RGB = np.array([.5*np.sin(2*theta_ + 2*i*np.pi/3)+.5 for i in range(3)])
                im_RGB += im_abs[:,:, np.newaxis] * RGB[np.newaxis, np.newaxis, :]

            im_RGB /= im_RGB.max()
            ax.imshow(1-im_RGB, **opts)
            #ax.grid(b=False, which="both")
            if mask:
                linewidth_mask = 1 #
                from matplotlib.patches import Ellipse
                circ = Ellipse((.5*self.pe.N_Y, .5*self.pe.N_X),
                                self.pe.N_Y-linewidth_mask, self.pe.N_X-linewidth_mask,
                                fill=False, facecolor='none', edgecolor = 'black', alpha = 0.5, ls='dashed', lw=linewidth_mask)
                ax.add_patch(circ)
            if spiral:
                i_orientation = np.mod(i_sf_0, 4)
                if i_orientation==0:
                    xmin += size
                    ymin += size/phi**2
                elif i_orientation==1:
                    xmin += size/phi**2
                    ymin += -size/phi
                elif i_orientation==2:
                    xmin += -size/phi
                elif i_orientation==3:
                    ymin += size
                size /= phi
            axs.append(ax)

        return fig, axs
def golden_pyramid(self, z, mask=False, spiral=True, fig_width=13):
        """
        The Golden Laplacian Pyramid.
        To represent the edges of the image at different levels, we may use a simple recursive approach constructing progressively a set of images of decreasing sizes, from a base to the summit of a pyramid. Using simple down-scaling and up-scaling operators we may approximate well a Laplacian operator. This is represented here by stacking images on a Golden Rectangle, that is where the aspect ratio is the golden section $\phi \eqdef \frac{1+\sqrt{5}}{2}$. We present here the base image on the left and the successive levels of the pyramid in a clockwise fashion (for clarity, we stopped at level $8$). Note that here we also use $\phi^2$ (that is $\phi+1$) as the down-scaling factor so that the resolution of the pyramid images correspond across scales. Note at last that coefficient are very kurtotic: most are near zero, the distribution of coefficients has long tails.

        """
        import matplotlib.pyplot as plt

        opts= {'vmin':0., 'vmax':1., 'interpolation':'nearest', 'origin':'upper'}

        N_X, N_Y = z.shape[0], z.shape[1]
        if spiral:
            phi = (np.sqrt(5)+1.)/2. # golden ratio
            fig = plt.figure(figsize=(fig_width, N_X/N_Y*fig_width/phi), frameon=True)
            xmin, ymin, size = 0, 0, 1.
        else:
            fig = plt.figure(figsize=(fig_width, N_X/N_Y*fig_width*self.n_levels), frameon=True)

        axs = []
        for i_sf_0 in range(len(self.sf_0)):
            if spiral:
                # https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.add_axes says:
                # Add an axes at position rect [left, bottom, width, height] where all quantities are in fractions of figure width and height.
                ax = fig.add_axes((xmin/phi, ymin, size/phi, size), facecolor='w')
            else:
                ax = fig.add_axes((0, i_sf_0/self.n_levels, 1, 1/self.n_levels), facecolor='w')
            ax.axis(c='r', lw=1)
            plt.setp(ax, xticks=[], yticks=[])
            im_RGB = np.zeros((self.pe.N_X, self.pe.N_Y, 3))
            for i_theta, theta_ in enumerate(self.theta):
                im_abs = np.absolute(z[:, :, i_theta, i_sf_0])
                RGB = np.array([.5*np.sin(2*theta_ + 2*i*np.pi/3)+.5 for i in range(3)])
                im_RGB += im_abs[:,:, np.newaxis] * RGB[np.newaxis, np.newaxis, :]

            im_RGB /= im_RGB.max()
            ax.imshow(1-im_RGB, **opts)
            #ax.grid(b=False, which="both")
            if mask:
                linewidth_mask = 1 #
                from matplotlib.patches import Ellipse
                circ = Ellipse((.5*self.pe.N_Y, .5*self.pe.N_X),
                                self.pe.N_Y-linewidth_mask, self.pe.N_X-linewidth_mask,
                                fill=False, facecolor='none', edgecolor = 'black', alpha = 0.5, ls='dashed', lw=linewidth_mask)
                ax.add_patch(circ)
            if spiral:
                i_orientation = np.mod(i_sf_0, 4)
                if i_orientation==0:
                    xmin += size
                    ymin += size/phi**2
                elif i_orientation==1:
                    xmin += size/phi**2
                    ymin += -size/phi
                elif i_orientation==2:
                    xmin += -size/phi
                elif i_orientation==3:
                    ymin += size
                size /= phi
            axs.append(ax)

        return fig, axs
The Golden Laplacian Pyramid.
        To represent the edges of the image at different levels, we may use a simple recursive approach constructing progressively a set of images of decreasing sizes, from a base to the summit of a pyramid. Using simple down-scaling and up-scaling operators we may approximate well a Laplacian operator. This is represented here by stacking images on a Golden Rectangle, that is where the aspect ratio is the golden section $\phi \eqdef \frac{1+\sqrt{5}}{2}$. We present here the base image on the left and the successive levels of the pyramid in a clockwise fashion (for clarity, we stopped at level $8$). Note that here we also use $\phi^2$ (that is $\phi+1$) as the down-scaling factor so that the resolution of the pyramid images correspond across scales. Note at last that coefficient are very kurtotic: most are near zero, the distribution of coefficients has long tails.