Exemplo n.º 1
0
    def load_image(self, path='images/pixelart.png', display=False):
        img = cv.imread(path, cv.IMREAD_GRAYSCALE)

        if display:
            # Display image
            plt.close('all')
            view = viewer(img, title=path.split('/')[-1], subplots=(1, 1))

        return img
Exemplo n.º 2
0
    def get_gaussian_kernel(self, size, sig, display=False):
        # Initializing value of x-axis and y-axis
        # in the range -1 to 1
        x, y = np.meshgrid(np.linspace(-1, 1, size), np.linspace(-1, 1, size))
        dst = np.sqrt(x * x + y * y)

        # Calculating Gaussian array
        gauss = np.exp(-(dst**2) / (2.0 * sig**2))

        if display:
            # Display kernel
            plt.close('all')
            view = viewer(gauss, title='Gaussian kernel', subplots=(1, 1))

        return gauss
Exemplo n.º 3
0
 def visual_comparison(self, use_saved=False):
     if not use_saved:
         self.img_convolved = self.convolve_2d()
     self.img_fft_filtered = self.FFT_filtering()
     self.img_fft_filtered_padded = self.FFT_filtering(mode='full')
     plt.close('all')
     titles = [
         'Original', 'FFT filtered (no padding)', 'Convolution',
         'FFT filtered (zero padding)'
     ]
     view = viewer([
         self.img, self.img_fft_filtered, self.img_convolved,
         self.img_fft_filtered_padded
     ],
                   title=titles,
                   subplots=(2, 2),
                   joint_zoom=True)
Exemplo n.º 4
0
    def convolve_2d(self,
                    kernel=None,
                    mode='same',
                    boundary='fill',
                    fillvalue=0,
                    display=False,
                    save=False):
        kernel = self.kernel if kernel is None else kernel
        img_convolved = signal.convolve2d(self.img,
                                          kernel,
                                          mode=mode,
                                          boundary=boundary,
                                          fillvalue=fillvalue)

        if display:
            plt.close('all')
            view = viewer([self.img, img_convolved],
                          title=['Original image', 'Convolved image'],
                          subplots=(1, 2))

        if save:
            self.img_convolved = img_convolved

        return img_convolved
Exemplo n.º 5
0
 def display_kernel(self):
     # Display kernel
     plt.close('all')
     view = viewer(self.kernel, title='Gaussian kernel', subplots=(1, 1))