Beispiel #1
0
 def _construct_ilang_model(self):
     # define the ilang probabilistic model
     self.ilang_model = MR_Static_Gaussian(self)
     # construct a basic Directed Acyclical Graph
     self.ilang_graph = ProbabilisticGraphicalModel(['x', 'k', 'sigma'])
     self.ilang_graph.set_nodes_given(['k', 'sigma'], True)
     self.ilang_graph.add_dependence(self.ilang_model, {
         'x': 'x',
         'k': 'k',
         'sigma': 'sigma'
     })
Beispiel #2
0
 def _construct_ilang_model(self): 
     # define the ilang probabilistic model 
     self.ilang_model = MR_Static_Gaussian(self) 
     # construct a basic Directed Acyclical Graph 
     self.ilang_graph = ProbabilisticGraphicalModel(['x','k','sigma']) 
     self.ilang_graph.set_nodes_given(['k','sigma'],True) 
     self.ilang_graph.add_dependence(self.ilang_model,{'x':'x','k':'k','sigma':'sigma'}) 
Beispiel #3
0
class MR_Static_Scan: 
    def __init__(self): 
        self.kspace = None 
    
    def load_kspace(self,filename): 
        self.kspace = KSpace() 
        self.kspace.load_from_file(filename) 
        self._construct_ilang_model() 
    
    def reconstruct_iterative(self, method=None, iterations=20, tol=None, dt=0.4, beta=0.05): 
        kspace = self.kspace.get_static_data()
        shape = kspace.shape
        image = asarray(complex64(zeros(shape)),order='F')
        for iter in range(iterations): 
            diff = kspace - self.project(image)
            grad = -self.backproject(diff) 
            image_abs = abs(image) 
            kernel = -ones((3,3,3))
            kernel[1,1,1]=26; 
            # 1) smooth magnitude 
            eps = 1e-8
            norm = 2*(scipy.ndimage.filters.convolve(image_abs,kernel)+eps) / (image_abs+eps);  # !!!
            # 2) smooth square magnitude 
            #norm = 4*(scipy.ndimage.filters.convolve(image_abs,kernel))              
            g0_real = -real(image) * norm
            g0_imag = -imag(image) * norm
            g0 = complex64(g0_real+g0_imag*1j)
            image = image - dt * (grad - beta*g0) 
        return Image3D(abs(image)) 

    def reconstruct_ifft(self): 
        kspace = self.kspace.get_static_data() 
        image = asarray( fftshift(ifftn(kspace)), order='F')
        return Image3D(abs(image)) 

    def project(self, volume ): 
        return asarray( fftn(fftshift(volume)), order='F')

    def backproject(self, kspace ): 
        return asarray( fftshift(ifftn(kspace)), order='F' )

    def _construct_ilang_model(self): 
        # define the ilang probabilistic model 
        self.ilang_model = MR_Static_Gaussian(self) 
        # construct a basic Directed Acyclical Graph 
        self.ilang_graph = ProbabilisticGraphicalModel(['x','k','sigma']) 
        self.ilang_graph.set_nodes_given(['k','sigma'],True) 
        self.ilang_graph.add_dependence(self.ilang_model,{'x':'x','k':'k','sigma':'sigma'}) 
        # construct a basic sampler object 
        #self.sampler     = Sampler(self.ilang_graph) 

    def _repr_html_(self): 
        if not has_ipy_table: 
            return "Please install ipy_table." 
        table_data = [ 
        ['bla   ',1],
        ['blabla',2], ]

        table = ipy_table.make_table(table_data)
        table = ipy_table.apply_theme('basic_left')
        table = ipy_table.set_global_style(float_format="%3.3f")        
        return table._repr_html_() 
Beispiel #4
0
class MR_Static_Scan:
    def __init__(self):
        self.kspace = None

    def load_kspace(self, filename):
        self.kspace = KSpace()
        self.kspace.load_from_file(filename)
        self._construct_ilang_model()

    def reconstruct_iterative(self,
                              method=None,
                              iterations=20,
                              tol=None,
                              dt=0.4,
                              beta=0.05):
        kspace = self.kspace.get_static_data()
        shape = kspace.shape
        image = asarray(complex64(zeros(shape)), order='F')
        for iter in range(iterations):
            diff = kspace - self.project(image)
            grad = -self.backproject(diff)
            image_abs = abs(image)
            kernel = -ones((3, 3, 3))
            kernel[1, 1, 1] = 26
            # 1) smooth magnitude
            eps = 1e-8
            norm = 2 * (scipy.ndimage.filters.convolve(image_abs, kernel) +
                        eps) / (image_abs + eps)
            # !!!
            # 2) smooth square magnitude
            #norm = 4*(scipy.ndimage.filters.convolve(image_abs,kernel))
            g0_real = -real(image) * norm
            g0_imag = -imag(image) * norm
            g0 = complex64(g0_real + g0_imag * 1j)
            image = image - dt * (grad - beta * g0)
        return Image3D(abs(image))

    def reconstruct_ifft(self):
        kspace = self.kspace.get_static_data()
        image = asarray(fftshift(ifftn(kspace)), order='F')
        return Image3D(abs(image))

    def project(self, volume):
        return asarray(fftn(fftshift(volume)), order='F')

    def backproject(self, kspace):
        return asarray(fftshift(ifftn(kspace)), order='F')

    def _construct_ilang_model(self):
        # define the ilang probabilistic model
        self.ilang_model = MR_Static_Gaussian(self)
        # construct a basic Directed Acyclical Graph
        self.ilang_graph = ProbabilisticGraphicalModel(['x', 'k', 'sigma'])
        self.ilang_graph.set_nodes_given(['k', 'sigma'], True)
        self.ilang_graph.add_dependence(self.ilang_model, {
            'x': 'x',
            'k': 'k',
            'sigma': 'sigma'
        })
        # construct a basic sampler object
        #self.sampler     = Sampler(self.ilang_graph)

    def _repr_html_(self):
        if not has_ipy_table:
            return "Please install ipy_table."
        table_data = [
            ['bla   ', 1],
            ['blabla', 2],
        ]

        table = ipy_table.make_table(table_data)
        table = ipy_table.apply_theme('basic_left')
        table = ipy_table.set_global_style(float_format="%3.3f")
        return table._repr_html_()