Example #1
0
    def SSFP(self, theta, row, col, te, tr, image_shape0, image_shape1, T2, T1,
             phantom, Gy, Start_up):

        Kspace_ssfp = np.zeros((image_shape0, image_shape1), dtype=np.complex_)

        if (Start_up == True):
            phantom = Fast.startup_cycle(phantom, theta / 2, te, tr, T2, T1,
                                         row, col, 1)

        phantom = Fast.startup_cycle(phantom, theta, te, tr, T2, T1, row, col,
                                     15)

        for r in range(Kspace_ssfp.shape[0]):  #rows
            theta = -theta
            phantom = Fast.rotate_decay(phantom, theta, te, T2, row, col)
            for c in range(Kspace_ssfp.shape[1]):
                Gx_step = ((2 * math.pi) / row) * r
                Gy_step = (Gy / col) * c
                for ph_row in range(row):
                    for ph_col in range(col):
                        Toltal_theta = (Gx_step * ph_row) + (Gy_step * ph_col)
                        Mag = math.sqrt(((phantom[ph_row, ph_col, 0]) *
                                         (phantom[ph_row, ph_col, 0])) +
                                        ((phantom[ph_row, ph_col, 1]) *
                                         (phantom[ph_row, ph_col, 1])))

                        Kspace_ssfp[r, c] = Kspace_ssfp[r, c] + (
                            Mag * np.exp(-1j * Toltal_theta))
                        QApplication.processEvents()

                QApplication.processEvents()

            print(theta)
            for ph_rowtr in range(row):
                for ph_coltr in range(col):
                    self.phantom[ph_rowtr, ph_coltr, 0] = 0
                    self.phantom[ph_rowtr, ph_coltr, 1] = 0
                    self.phantom[ph_rowtr, ph_coltr, 2] = (
                        (phantom[ph_rowtr, ph_coltr, 2]) *
                        np.exp(-tr / T1[ph_rowtr, ph_coltr])) + (
                            1 - np.exp(-tr / T1[ph_rowtr, ph_coltr]))

            QApplication.processEvents()
        iff = np.fft.ifft2(Kspace_ssfp)

        #print(iff)
        inverse_array = np.abs(iff)
        inverse_array = (inverse_array - np.amin(inverse_array)) * 255 / (
            np.amax(inverse_array) - np.amin(inverse_array))
        inverse_img = gray2qimage(inverse_array)
        imgreconstruction = inverse_img
        return imgreconstruction
Example #2
0
    def GRE(self, theta, row, col, te, tr, image_shape0, image_shape1, T2, T1,
            phantom, Gy, Start_up):

        Kspace = np.zeros((image_shape0, image_shape1), dtype=np.complex_)

        if (Start_up == True):
            phantom = Fast.startup_cycle(phantom, theta, te, tr, T2, T1, row,
                                         col, 15)

        for r in range(Kspace.shape[0]):  #rows
            phantom = Fast.rotate_decay(phantom, theta, te, T2, row, col)

            for c in range(Kspace.shape[1]):  #columns
                Gx_step = ((2 * math.pi) / row) * r
                Gy_step = ((Gy) / col) * c
                for ph_row in range(row):
                    for ph_col in range(col):
                        Toltal_theta = (Gx_step * ph_row) + (Gy_step * ph_col)
                        Mag = math.sqrt(((phantom[ph_row, ph_col, 0]) *
                                         (phantom[ph_row, ph_col, 0])) +
                                        ((phantom[ph_row, ph_col, 1]) *
                                         (phantom[ph_row, ph_col, 1])))

                        Kspace[r,
                               c] = Kspace[r, c] + (Mag *
                                                    np.exp(-1j * Toltal_theta))
                        QApplication.processEvents()
                QApplication.processEvents()
            phantom = Fast.recovery(phantom, row, col, tr, T1)
            QApplication.processEvents()

        iff = np.fft.ifft2(Kspace)

        inverse_array = np.abs(iff)
        inverse_array = (inverse_array - np.amin(inverse_array)) * 255 / (
            np.amax(inverse_array) - np.amin(inverse_array))
        inverse_img = gray2qimage(inverse_array)
        imgreconstruction = inverse_img
        return imgreconstruction
def main ():
    
    # 
    # Get the configuration parameters from the user. Reset to default
    # values if invalid input is entered.
    #
    try:
        if len(sys.argv) == 3:
            n = int(sys.argv[1])
            m = int(sys.argv[2])
            if (n <= 0 or m <= 0):
                print("Invalid input. Resetting to default parameters.")
                n = 10
                m = 50
        else:
            print("Invalid input. Resetting to default parameters.")
            n = 10
            m = 50
    except(ValueError, IndexError):
        print("Invalid input. Resetting to default parameters.")
        n = 10
        m = 50
        
    # Part 1 - Bakery Algorithm
    
    # Print the banner!
    print("Running Lamport's bakery algorithm")
    print("")
    
    # Initialize the thread list
    thread_list_bakery = []
    
    # Initialize the threads
    for i in range(n) :
        thread = Bakery.Bakery()
        thread.set_pid(i)
        thread_list_bakery.append(thread)

    # Assign requests to threads randomly
    for i in range (m):
        # Pick a random thread and increment its request count
        if (n > 1):
            p = random.randint(0, n - 1)
        else:
            p = 0
        thread = thread_list_bakery[p]
        thread.pending_req = thread.pending_req + 1

    # 
    # Call the setup routine to initialize shared variables.
    # This will also start the threads.
    #
    Bakery.setup(thread_list_bakery, m)
        
    # Part 2 - Fast Mutual Exclusion Algorithm
     
    # Print the banner!
    print("")
    print("Running Lamport's fast mutual exclusion algorithm")
    print("")
    
    # Initialize the thread list
    thread_list_fast = []
    
    # Initialize the threads
    for i in range(n) :
        thread = Fast.Fast()
        thread.set_pid(i)
        thread_list_fast.append(thread)

    # Assign requests to threads randomly
    for i in range (m):
        # Pick a random thread and increment its request count
        if (n > 1):
            p = random.randint(0, n - 1)
        else:
            p = 0
        thread = thread_list_fast[p]
        thread.pending_req = thread.pending_req + 1
        
    # 
    # Call the setup routine to initialize shared variables.
    # This will also start the threads.
    #
    Fast.setup(thread_list_fast, m)
import sys

if len(sys.argv)!=3:
    sys.exit("\n\nwrong number of arguments, usage: python randnum.py threads requests\n\n")
    
thr = int(sys.argv[1])
req = int(sys.argv[2])

#initialising a list whose index represents the thread and its value the number requests assigned to it
assign = [0]*thr

# randomly distributing the requests among the threads
while req:
    j = random.randrange(0, thr)
    assign[j]+=1
    req-=1

# just to check
for x in assign:
	print (x)

print ("\nRunning Lamport's fast mutual exclusion algorithm\n")
Fast.spawnThreads(assign)

print ("\n\nRunning Lamport's bakery algorithm\n\n")
Bakery.spawnThreads(assign)