コード例 #1
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def new_subset(self, mode, subset_size):
     if mode == 'random':
         return self._random_no_replacement(subset_size)
     elif mode == 'ordered':
         raise UnexpectedParameter(
             "'%s' subset selection mode not yet supported." % str(mode))
     else:
         raise UnexpectedParameter("'mode' parameter %s not recognised." %
                                   str(mode))
コード例 #2
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_gantry_angular_positions(self, first_position_deg,
                                  last_position_deg, N_positions):
     if not (isscalar(first_position_deg) and isscalar(last_position_deg)
             and isscalar(N_positions)):
         raise UnexpectedParameter('Expected scalar values.')
     if not isinstance(N_positions, type(1)):
         raise UnexpectedParameter('Expected an integer value.')
     self._p_gantry_angular_position_first = first_position_deg
     self._p_gantry_angular_position_last = last_position_deg
     self._p_gantry_angular_positions = N_positions
     self._subset_generator = SubsetGenerator(
         self._p_gantry_angular_positions)
コード例 #3
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_collimator(self, collimator):
     if not isinstance(collimator, Collimators.BaseCollimatorSPECT):
         raise UnexpectedParameter(
             'Expected an instance of BaseCollimatorSPECT')
     self._collimator = collimator
     self.__make_psf()
     self._need_update_norm = True
コード例 #4
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_scintillator(self, scintillator):
     if not isinstance(scintillator, Scintillators.BaseScintillatorSPECT):
         raise UnexpectedParameter(
             'Expected an instance of BaseScintillatorSPECT')
     self._scintillator = scintillator
     self.__make_psf()
     self._need_update_norm = True
コード例 #5
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_n_pixels(self, n_pixels_x, n_pixels_y):
     if (not isscalar(n_pixels_x)) or (not isscalar(n_pixels_y)):
         raise UnexpectedParameter('Expected integer scalar values.'
                                   )  #FIXME: make sure it is integer
     self._p_n_pix_x = n_pixels_x
     self._p_n_pix_y = n_pixels_y
     self._need_update_norm = True
コード例 #6
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_measurement(self, measurement):
     if not (self._p_n_pix_x == measurement.shape[0]
             and self._p_n_pix_y == measurement.shape[1]
             and self._p_gantry_angular_positions == measurement.shape[2]):
         raise UnexpectedParameter(
             'Measurement size is not compatible with n_pix_x, n_pix_y, gantry_angular_positions. '
         )
     self._measurement = measurement
コード例 #7
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
    def estimate_activity(self,
                          attenuation=None,
                          psf=None,
                          iterations=DEFAULT_ITERATIONS,
                          subset_size=DEFAULT_SUBSET_SIZE,
                          subset_mode='random',
                          method="EM",
                          m=32,
                          factr=0.01,
                          pgtol=1e-16,
                          maxfun=10000,
                          smoothing=0.0,
                          activity=None):
        progress_bar = ProgressBar()
        progress_bar.set_percentage(0.1)
        if activity == None:
            activity = ones(
                (self._p_n_pix_x, self._p_n_pix_y, self._p_n_pix_x),
                dtype=float32,
                order="F")
        if attenuation is None:
            attenuation = self._attenuation
            if attenuation is not None:
                if isinstance(attenuation, ndarray):
                    attenuation = float32(attenuation)
                else:
                    attenuation = float32(attenuation.data)
        if psf is None:
            psf = self._psf
        if method == "EM":
            print "Reconstruction method: EM"
            for i in range(iterations):
                # Subsets:
                if subset_size is None:
                    subsets_array = None
                    subset_size = self._p_gantry_angular_positions
                elif subset_size >= self._p_gantry_angular_positions:
                    subsets_array = None
                    subset_size = self._p_gantry_angular_positions
                else:
                    subsets_array = self._subset_generator.new_subset(
                        subset_mode, subset_size)
                if subsets_array is not None:
                    proj = self.project(activity,
                                        attenuation=attenuation,
                                        psf=psf,
                                        subsets_array=subsets_array).data
                    measurement = self._measurement[:, :,
                                                    where(subsets_array
                                                          )].reshape(
                                                              (self._p_n_pix_x,
                                                               self._p_n_pix_y,
                                                               subset_size))
                    measurement = asfortranarray(
                        ascontiguousarray(measurement))
                    P = (measurement + EPS) / (proj + EPS)
                    norm = self.backproject(ones(
                        (self._p_n_pix_x, self._p_n_pix_y, subset_size),
                        dtype=float32,
                        order="F"),
                                            attenuation=attenuation,
                                            psf=psf,
                                            subsets_array=subsets_array).data
                    update = (self.backproject(
                        P,
                        attenuation=attenuation,
                        psf=psf,
                        subsets_array=subsets_array).data + EPS) / (norm + EPS)
                else:
                    proj = self.project(activity,
                                        attenuation=attenuation,
                                        psf=psf).data
                    P = (self._measurement + EPS) / (proj + EPS)
                    norm = self.get_normalization()
                    update = (self.backproject(
                        P, attenuation=attenuation, psf=psf).data +
                              EPS) / (norm + EPS)
                activity = activity * update  #* self.get_mask().data

                progress_bar.set_percentage((i + 1) * 100.0 / iterations)
                #print "Iteration: %d    max act: %f    min act: %f    max proj: %f    min proj: %f    max norm: %f    min norm: %f"%(i, activity.max(), activity.min(), proj.max(), proj.min(), norm.data.max(), norm.data.min() )
            progress_bar.set_percentage(100.0)
        elif method == "LBFGS":
            print "Reconstruction method: LBFGS-B"
            bounds = [(None, None)] * activity.size
            for i in range(0, activity.size):
                bounds[i] = (0, None)
            args = [activity.shape, smoothing]
            activity0 = float64(activity.reshape(activity.size))
            # print "SIZE ACTIVITY0: ",activity0.shape
            activity_rec, f, d = optimize.fmin_l_bfgs_b(
                self.get_likelihood,
                activity0,
                fprime=self.get_gradient_activity,
                m=m,
                factr=factr,
                pgtol=pgtol,
                args=args,
                maxfun=maxfun,
                iprint=0,
                bounds=bounds)
            activity = float32(activity_rec.reshape(activity.shape))
            progress_bar.set_percentage(100.0)
        else:
            raise UnexpectedParameter("Reconstruction method %s unknown" %
                                      method)
        return Image3D(activity)
コード例 #8
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_pixel_size(self, pixel_size_x, pixel_size_y):
     if (not isscalar(pixel_size_x)) or (not isscalar(pixel_size_y)):
         raise UnexpectedParameter('Expected scalar values.')
     self._p_pix_size_x_mm = pixel_size_x
     self._p_pix_size_y_mm = pixel_size_y
コード例 #9
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_radius(self, radius_mm):
     if not isscalar(radius_mm):
         raise UnexpectedParameter('Expected a scalar value.')
     self._p_radius_mm = radius_mm
コード例 #10
0
ファイル: SPECT.py プロジェクト: shihao80/occiput
 def set_scan_time(self, scan_time_sec):
     if not isscalar(scan_time_sec):
         raise UnexpectedParameter('Expected a scalar value.')
     self._p_scan_time_sec = scan_time_sec