コード例 #1
0
    def smoothing(self, sigma_zero):
        """
        :param sigma_zero: initial sigma as a first smoothing
        :return:void (images are saved at disc space in path+ '/npy_arrays_3DGaussianFiltering'
        """
        path_to_save = '/3DGaussianSmoothing/'

        sigmas_x = (self.k**self.powers) * sigma_zero
        sigmas_y = (self.k**self.powers) * sigma_zero
        sigmas_z = ((self.k**self.powers) * sigma_zero) / (self.spacing[2] /
                                                           self.spacing[0])

        print(sigmas_x, sigmas_z)

        saving = SaveImage(self.path + path_to_save)

        for sigma_x, sigma_y, sigma_z in zip(sigmas_x, sigmas_y, sigmas_z):
            im = self.image.Image3D

            image = normalize(im, [np.min(im), np.max(im)], [-1.0, 1.0])

            print('befor ', np.min(image), np.max(image))
            smoothed_image = gaussian_filter(image,
                                             (sigma_x, sigma_y, sigma_z))
            smoothed_image = smoothed_image.astype(dtype=np.float32)

            smoothed_image = normalize(smoothed_image, [-1.0, 1.0], [0.0, 1.0])

            temp_image = deepcopy(self.image)
            temp_image.Image3D = smoothed_image

            temp_image.sigma = sigma_x

            saving.saveImage(temp_image)
コード例 #2
0
    def smoothing(self, sigma_zero):
        """
        :param sigma_zero: initial sigma as a first smoothing
        :return:void (images are saved at disc space in path+ '/npy_arrays_2DGaussianFiltering'
        """

        path_to_save = '/2DGaussianSmoothing/'

        sigmas_x = (self.k**self.powers) * sigma_zero / self.spacing[0]
        sigmas_y = (self.k**self.powers) * sigma_zero / self.spacing[1]

        # make directory

        im = self.image.Image3D[:, :, 20]
        saving = SaveImage(self.path + path_to_save)
        for sigma_x, sigma_y in zip(sigmas_x, sigmas_y):
            image = normalize(im, [np.min(im), np.max(im)], [-1.0, 1.0])
            smoothed_image = gaussian_filter(image, (sigma_x, sigma_y))
            print(np.min(smoothed_image), np.max(smoothed_image))
            smoothed_image = normalize(smoothed_image, [-1.0, 1.0], [0.0, 1.0])
            temp_image = deepcopy(self.image)
            temp_image.Image3D = smoothed_image
            temp_image.sigma = sigma_x

            saving.saveImage(temp_image)
コード例 #3
0
    def smoothing(self, sigma_zero):
        """
        :param sigma_zero: initial sigma as a first smoothing
        :return:void (images are saved at disc space in path+ '/npy_arrays_3DGaussianFiltering'
        """
        path_to_save = '/3DGaussianSmoothing/'

        sigmas_x = (self.k ** self.powers) * sigma_zero
        sigmas_y = (self.k ** self.powers) * sigma_zero
        sigmas_z = ((self.k ** self.powers) * sigma_zero) / (self.spacing[2] / self.spacing[0])

        print(sigmas_x, sigmas_z)

        saving = SaveImage(self.path + path_to_save)

        for sigma_x, sigma_y, sigma_z in zip(sigmas_x, sigmas_y, sigmas_z):
            im = self.image.Image3D

            image = normalize(im, [np.min(im), np.max(im)], [-1.0, 1.0])

            print('befor ', np.min(image), np.max(image))
            smoothed_image = gaussian_filter(image, (sigma_x, sigma_y, sigma_z))
            smoothed_image = smoothed_image.astype(dtype=np.float32)

            smoothed_image = normalize(smoothed_image, [-1.0, 1.0], [0.0, 1.0])

            temp_image = deepcopy(self.image)
            temp_image.Image3D = smoothed_image

            temp_image.sigma = sigma_x

            saving.saveImage(temp_image)
コード例 #4
0
    def smoothing(self, sigma_zero):
        """
        :param sigma_zero: initial sigma as a first smoothing
        :return:void (images are saved at disc space in path+ '/npy_arrays_2DGaussianFiltering'
        """

        path_to_save = '/2DGaussianSmoothing/'

        sigmas_x = (self.k ** self.powers) * sigma_zero / self.spacing[0]
        sigmas_y = (self.k ** self.powers) * sigma_zero / self.spacing[1]

        # make directory

        im = self.image.Image3D[:, :, 20]
        saving = SaveImage(self.path + path_to_save)
        for sigma_x, sigma_y in zip(sigmas_x, sigmas_y):
            image = normalize(im, [np.min(im), np.max(im)], [-1.0, 1.0])
            smoothed_image = gaussian_filter(image, (sigma_x, sigma_y))
            print(np.min(smoothed_image), np.max(smoothed_image))
            smoothed_image = normalize(smoothed_image, [-1.0, 1.0], [0.0, 1.0])
            temp_image = deepcopy(self.image)
            temp_image.Image3D = smoothed_image
            temp_image.sigma = sigma_x

            saving.saveImage(temp_image)
コード例 #5
0
ファイル: Histogram2D.py プロジェクト: DanielGutmann/DICOM
    def get_Histogram2D(self, elevation, azimuth, weights, plt=None):
        '''
        :param elevation: array with elevations
        :param azimuth: array with azimuth
        :param weights: array with weights
        :return: histogram of occurrence
        '''


        H, e, z = np.histogram2d(elevation.flatten(), azimuth.flatten(), bins=[self.No_bin_x, self.No_bin_y],
                                     normed=False, weights=weights.flatten(), range=[[0.0, np.pi], [0.0, 2 * np.pi]])
        H = normalize(H, [np.min(H), np.max(H)], [0., 1.])
        H = normalize(H, [np.min(H), np.max(H)], [-1., 1.])
        H = gaussian_filter(H, 0.1, truncate=3.0)
        H = normalize(H, [np.min(H), np.max(H)], [0., 1.])
        return H
コード例 #6
0
    def get_Histogram2D(self, elevation, azimuth, weights, plt=None):
        '''
        :param elevation: array with elevations
        :param azimuth: array with azimuth
        :param weights: array with weights
        :return: histogram of occurrence
        '''

        H, e, z = np.histogram2d(elevation.flatten(),
                                 azimuth.flatten(),
                                 bins=[self.No_bin_x, self.No_bin_y],
                                 normed=False,
                                 weights=weights.flatten(),
                                 range=[[0.0, np.pi], [0.0, 2 * np.pi]])
        H = normalize(H, [np.min(H), np.max(H)], [0., 1.])
        H = normalize(H, [np.min(H), np.max(H)], [-1., 1.])
        H = gaussian_filter(H, 0.1, truncate=3.0)
        H = normalize(H, [np.min(H), np.max(H)], [0., 1.])
        return H
コード例 #7
0
ファイル: DoG.py プロジェクト: Jake-zhi/SIFTinz
    def apply(self):
        list_of_image = self.ReadImage.openImage()
        saving = SaveImage(self.path + self.path_to_save)
        import numpy as np
        for i in range(0, len(list_of_image) - 1):

            DoG = list_of_image[i + 1].Image3D - list_of_image[i].Image3D
            print('before', np.min(DoG), np.max(DoG))
            DoG = normalize(DoG, [-1, 1], [0, 1])
            print(DoG.dtype)
            print(np.min(DoG), np.max(DoG))
            list_of_image[i].Image3D = DoG
            saving.saveImage(list_of_image[i])
コード例 #8
0
    def keypoints_histograms(self, image3D_agregator, keypooints_agregator):
        # diff in [mm space]
        dx, dy, dz = np.gradient(image3D_agregator.Image3D, image3D_agregator.spacing[0], image3D_agregator.spacing[1],
                                 image3D_agregator.spacing[2])

        keypoints = keypoints_concatenate(keypooints_agregator)

        # do konfigracji
        delta_azimuth = np.pi / 4.
        delta_elevation = np.pi / 4.
        #solid_azimuth=np.arange(0,2*np.pi+delta_elevation,delta_elevation)
        #solid_angle = 1.0 / (delta_elevation * (np.cos(solid_azimuth) - np.cos(solid_azimuth + delta_azimuth)))

        #solid_angle = normalize(solid_angle, [np.min(solid_angle), np.max(solid_angle)], [0, 1])

        keypoint_list = []

        for k in range(0, keypoints.shape[0]):
            try:
                i = keypoints[k][0]
                j = keypoints[k][1]
                z = keypoints[k][2]
            except IndexError:
                keypoint_list.append([0,0,0,0,0])
                pass
                continue



            temp_x = dx[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            temp_y = dy[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            temp_z = dz[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            if temp_x.shape[0] != 2 * self.size_in_pixels_xy + 1:  continue
            if temp_x.shape[1] != 2 * self.size_in_pixels_xy + 1:  continue
            if temp_x.shape[2] != 2 * self.size_in_pixels_xy + 1:  continue

            self.magnitude = np.sqrt(temp_x ** 2 + temp_y ** 2 + temp_z ** 2)
            self.azimuth = np.arctan2(temp_y, temp_x) + np.pi

            self.elevation = np.arctan2(temp_z,np.sqrt(temp_x ** 2 + temp_y ** 2))+np.pi/2


            self.magnitude = normalize(self.magnitude, [np.min(self.magnitude), np.max(self.magnitude)], [0, 1])

            self.gaussian_weight = normalize(self.gaussian_weight, [np.min(self.gaussian_weight),
                                                                    np.max(self.gaussian_weight)], [0, 1])

            weights = self.magnitude * self.gaussian_weight #* solid_angle
            self.weights = normalize(weights, [np.min(weights), np.max(weights)], [0, 1])

            NO_xbin = 4
            NO_ybin = 8

            H2D = Histogram2D(NO_xbin, NO_ybin)
            H2D.apply(self.elevation, self.azimuth, weights)
            #self.H2D = H2D.get_Histogram2D()
            #fig =figure()
            from mpl_toolkits.mplot3d import Axes3D
            #ax = fig.add_subplot(111,projection='3d')
            #barchart(H2D.H)

            #mlab.colorbar(nb_labels=2,label_fmt='%.1f')
            #show()
            angles = H2D.get_Histogram2D_max()
            if angles.size == 4:
                keypoint_list.append([i, j, z, angles[0][0], angles[0][1]])
                keypoint_list.append([i, j, z, angles[1][0], angles[1][1]])
            elif angles.size == 2:

                keypoint_list.append([i, j, z, angles[0][0], angles[0][1]])

        return keypoint_list
コード例 #9
0
    def apply(self, mask, spacing):
        mask = self.interp(mask, spacing)
        # constant for histogram
        delta_azimuth = np.pi / 4.
        delta_elevation = np.pi / 4.
        # mesurmet for histogram
        dx, dy, dz = np.gradient(mask)
        magnitude = np.sqrt(dx**2 + dy**2 + dz**2)
        azimuth = np.arctan2(dy, dx) + np.pi
        elevation = np.arctan2(dz, np.sqrt(dx**2 + dy**2)) + np.pi / 2
        # weights with normalization for equal contribution
        # solid_angle = 1 / (delta_elevation * (np.cos(azimuth) - np.cos(azimuth + delta_azimuth)))
        # solid_angle = normalize(solid_angle, [np.min(solid_angle), np.max(solid_angle)], [0, 1])
        self.magnitude = normalize(
            magnitude,
            [np.min(magnitude), np.max(magnitude)], [0, 1])
        self.gaussian_weight = normalize(
            self.gaussian_weight,
            [np.min(self.gaussian_weight),
             np.max(self.gaussian_weight)], [0, 1])
        weights = magnitude * self.gaussian_weight  # * solid_angle
        self.weights = normalize(
            weights, [np.min(weights), np.max(weights)], [0, 1])
        # splitig array mask for 8 equal parts
        div0 = np.array([
            8,
        ])
        div1 = np.array([
            7,
        ])
        # angles
        h0 = np.hsplit(azimuth, div0)[0]
        A_1 = np.vsplit(h0, div0)[0]  # 1
        A_2 = np.vsplit(h0, div0)[0]  # 2
        A_3 = np.vsplit(h0, div1)[1]  # 3
        A_4 = np.vsplit(h0, div1)[1]  #
        h1 = np.hsplit(azimuth, div1)[1]
        A_5 = np.vsplit(h1, div0)[0]  # 5
        A_6 = np.vsplit(h1, div0)[0]  # 6
        A_7 = np.vsplit(h1, div1)[1]  # 7
        A_8 = np.vsplit(h1, div1)[1]  # 8

        h0 = np.hsplit(elevation, div0)[0]
        E_1 = np.vsplit(h0, div0)[0]
        E_2 = np.vsplit(h0, div0)[0]
        E_3 = np.vsplit(h0, div1)[1]  # 3
        E_4 = np.vsplit(h0, div1)[1]  #
        h1 = np.hsplit(elevation, div1)[1]
        E_5 = np.vsplit(h1, div0)[0]  # 5
        E_6 = np.vsplit(h1, div0)[0]  # 6
        E_7 = np.vsplit(h1, div1)[1]  # 7
        E_8 = np.vsplit(h1, div1)[1]  # 8
        # weights
        w0 = np.hsplit(self.weights, div0)[0]
        W_1 = np.vsplit(h0, div0)[0]  # 1
        W_2 = np.vsplit(h0, div0)[0]  # 2
        W_3 = np.vsplit(h0, div1)[1]  # 3
        W_4 = np.vsplit(h0, div1)[1]  #
        w1 = np.hsplit(self.weights, div1)[1]
        W_5 = np.vsplit(h1, div0)[0]  # 5
        W_6 = np.vsplit(h1, div0)[0]  # 6
        W_7 = np.vsplit(h1, div1)[1]  # 7
        W_8 = np.vsplit(h1, div1)[1]  # 8
        # constatn for histogram
        NO_xbin = 4
        NO_ybin = 8

        H2D = Histogram2D(NO_xbin, NO_ybin)
        list_of_histograms_for_keypoint = []
        for i in range(1, 9):
            nr = str(i)
            list_of_histograms_for_keypoint.append(
                H2D.get_Histogram2D(eval('E_' + nr), eval('A_' + nr),
                                    eval('W_' + nr)))
        # list of histograms for descriptor (8 histograms as 4x8 bins)
        return np.array(list_of_histograms_for_keypoint)
コード例 #10
0
    def apply(self, mask, spacing):
        mask = self.interp(mask, spacing)
        # constant for histogram
        delta_azimuth = np.pi / 4.
        delta_elevation = np.pi / 4.
        # mesurmet for histogram
        dx, dy, dz = np.gradient(mask)
        magnitude = np.sqrt(dx ** 2 + dy ** 2 + dz ** 2)
        azimuth = np.arctan2(dy, dx) + np.pi
        elevation = np.arctan2(dz, np.sqrt(dx ** 2 + dy ** 2)) + np.pi / 2
        # weights with normalization for equal contribution
        # solid_angle = 1 / (delta_elevation * (np.cos(azimuth) - np.cos(azimuth + delta_azimuth)))
        # solid_angle = normalize(solid_angle, [np.min(solid_angle), np.max(solid_angle)], [0, 1])
        self.magnitude = normalize(magnitude, [np.min(magnitude), np.max(magnitude)], [0, 1])
        self.gaussian_weight = normalize(self.gaussian_weight, [np.min(self.gaussian_weight),
                                                                np.max(self.gaussian_weight)], [0, 1])
        weights = magnitude * self.gaussian_weight  # * solid_angle
        self.weights = normalize(weights, [np.min(weights), np.max(weights)], [0, 1])
        # splitig array mask for 8 equal parts
        div0 = np.array([8, ])
        div1 = np.array([7, ])
        # angles
        h0 = np.hsplit(azimuth, div0)[0]
        A_1 = np.vsplit(h0, div0)[0]  # 1
        A_2 = np.vsplit(h0, div0)[0]  # 2
        A_3 = np.vsplit(h0, div1)[1]  # 3
        A_4 = np.vsplit(h0, div1)[1]  #
        h1 = np.hsplit(azimuth, div1)[1]
        A_5 = np.vsplit(h1, div0)[0]  # 5
        A_6 = np.vsplit(h1, div0)[0]  # 6
        A_7 = np.vsplit(h1, div1)[1]  # 7
        A_8 = np.vsplit(h1, div1)[1]  # 8

        h0 = np.hsplit(elevation, div0)[0]
        E_1 = np.vsplit(h0, div0)[0]
        E_2 = np.vsplit(h0, div0)[0]
        E_3 = np.vsplit(h0, div1)[1]  # 3
        E_4 = np.vsplit(h0, div1)[1]  #
        h1 = np.hsplit(elevation, div1)[1]
        E_5 = np.vsplit(h1, div0)[0]  # 5
        E_6 = np.vsplit(h1, div0)[0]  # 6
        E_7 = np.vsplit(h1, div1)[1]  # 7
        E_8 = np.vsplit(h1, div1)[1]  # 8
        # weights
        w0 = np.hsplit(self.weights, div0)[0]
        W_1 = np.vsplit(h0, div0)[0]  # 1
        W_2 = np.vsplit(h0, div0)[0]  # 2
        W_3 = np.vsplit(h0, div1)[1]  # 3
        W_4 = np.vsplit(h0, div1)[1]  #
        w1 = np.hsplit(self.weights, div1)[1]
        W_5 = np.vsplit(h1, div0)[0]  # 5
        W_6 = np.vsplit(h1, div0)[0]  # 6
        W_7 = np.vsplit(h1, div1)[1]  # 7
        W_8 = np.vsplit(h1, div1)[1]  # 8
        # constatn for histogram
        NO_xbin = 4
        NO_ybin = 8

        H2D = Histogram2D(NO_xbin, NO_ybin)
        list_of_histograms_for_keypoint = []
        for i in range(1, 9):
            nr = str(i)
            list_of_histograms_for_keypoint.append(
                H2D.get_Histogram2D(eval('E_' + nr), eval('A_' + nr), eval('W_' + nr)))
        # list of histograms for descriptor (8 histograms as 4x8 bins)
        return np.array(list_of_histograms_for_keypoint)