def artifact12 (self): ## (;:;:;:) kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 ####### PREP ##########################################################33 vectors = self.startup(vectors) vectors = self.preparation(vectors) vectors = rotateX(vectors, 20) rotatedMatrix = vectors for i in range(0, round(0.2*self.phantomSize)): decayedRotatedMatrix = decay(rotatedMatrix, self.T2, 0.008) for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * i stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[i, j] = valueToAdd rotatedMatrix = recovery(decayedRotatedMatrix,self.T1,0.1) self.showKSpace(kSpace) print(i) if i % 2 == 0: vectors = rotateX(rotatedMatrix, -1 * 20 * 2) else: vectors = rotateX(rotatedMatrix, 20 * 2) kSpace = np.fft.fft2(kSpace) self.showReconstructedImage(kSpace)
def GRE_reconstruct_image(self): kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 ###### Prep ########################################################################################## vectors = self.startup(vectors) vectors = self.preparation(vectors) for i in range(0, round(self.phantomSize)): rotatedMatrix = rotateX(vectors, self.FA) decayedRotatedMatrix = decay(rotatedMatrix, self.T2, self.TE) for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * i stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[i, j] = valueToAdd decayedRotatedMatrix[:, :, 0] = 0 decayedRotatedMatrix[:, :, 1] = 0 self.showKSpace(kSpace) print(i) vectors = recovery(decayedRotatedMatrix, self.T1, self.TR) kSpace = np.fft.fft2(kSpace) self.showReconstructedImage(kSpace)
def artifact1 (self): kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 vectors = rotateX(vectors, 60) vectors = recovery(vectors, self.T1, 1000) for i in range(0, round(self.phantomSize)): rotatedMatrix = vectors decayedRotatedMatrix = decay(rotatedMatrix, self.T2, 45) for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * i stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[i, j] = valueToAdd self.showKSpace(kSpace) print(i) if i % 2 == 0: vectors = rotateX(rotatedMatrix, -1 * 60 * 2) else: vectors = rotateX(rotatedMatrix, 60 * 2) kSpace = np.fft.fftshift(kSpace) kSpace = np.fft.fft2(kSpace) self.showReconstructedImage(kSpace) #kSpace = np.fft.fftshift(kSpace) kSpace = np.fft.fft2(kSpace) self.showReconstructedImage(kSpace)
def ernst(self,color, T1=1000, T2=45 ): ert = self.ui.graphicsView_2 if self.acquisition == 'gre' or self.acquisition == 'se': angle = np.arange(0,180,1) anrad = angle /180 * np.pi ert.plot(np.sin(anrad)*(1-np.exp(-self.TR*1000/T1))*np.exp(-self.TE*1000/T2)/(1-(np.cos(anrad)*np.exp(-self.TR*1000/T1))), pen=pg.mkPen(color)) if self.acquisition == 'ssfp': kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 angle = np.arange(0,180,5) output = np.zeros(36) counter = -1 for fa in range(0,180,5): print(fa) counter += 1 rotatedMatrix = rotateX(vectors, fa) decayedRotatedMatrix = decay(rotatedMatrix,self.T2,self.TE) for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * 20 stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[0, j] = valueToAdd rotatedMatrix = recovery(rotatedMatrix,self.T1,self.TR) output[counter] = np.average(np.abs(kSpace)) ert.plot(angle,output,pen=pg.mkPen(color))
def IR(self,signal,T1cancel = 1000): TE = T1cancel * np.log(2) # self.TE = T1cancel * np.log(2) signal = rotateX(signal , 180) signal = recovery(signal,self.T1,TE) return signal
def startup(self,signal): try : for i in range(self.cycles): signal = rotateX(signal, self.FA) signal = decay(signal, self.T2, self.TE) signal = recovery(signal, self.T1, self.TR) except: return signal return signal
def artifact2(self): kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 if self.cycles is None: self.cycles = 3 vectors = self.startup(vectors) self.cycles = None else: vectors = self.startup(vectors) vectors = rotateX(vectors, 60) for i in range(0, round(self.phantomSize)): rotatedMatrix = rotateX(vectors, 90) decayedRotatedMatrix = decay(rotatedMatrix, self.T2, 1) if i == int(self.phantomSize / 2): threshold = int(self.phantomSize * 0.15) self.T1[:, 0:self.phantomSize - threshold] = self.T1[:, threshold:self.phantomSize] self.T2[:, 0:self.phantomSize - threshold] = self.T2[:, threshold:self.phantomSize] self.T1[:, self.phantomSize - threshold:self.phantomSize] = 0 self.T2[:, self.phantomSize - threshold:self.phantomSize] = 0 decayedRotatedMatrix[:, 0:self.phantomSize - threshold, :] = decayedRotatedMatrix[:, threshold: self. phantomSize, :] decayedRotatedMatrix[:, self.phantomSize - threshold:self.phantomSize, :] = 0 for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * i stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[i, j] = valueToAdd decayedRotatedMatrix[:, :, 0] = 0 decayedRotatedMatrix[:, :, 1] = 0 self.showKSpace(kSpace) print(i) vectors = recovery(decayedRotatedMatrix, self.T1, 10) kSpace = np.fft.fft2(kSpace) self.showReconstructedImage(kSpace)
def reconstructImage(self): kSpace = np.zeros((self.phantomSize, self.phantomSize), dtype=np.complex_) vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) vectors[:, :, 2] = 1 for i in range(0, self.phantomSize): rotatedMatrix = rotateX(vectors, self.cosFA, self.sinFA) decayedRotatedMatrix = decay(rotatedMatrix, self.T2, self.TE) for j in range(0, self.phantomSize): stepX = (360 / self.phantomSize) * i stepY = (360 / self.phantomSize) * j phaseEncodedMatrix = gradientXY(decayedRotatedMatrix, stepY, stepX) sigmaX = np.sum(phaseEncodedMatrix[:, :, 0]) sigmaY = np.sum(phaseEncodedMatrix[:, :, 1]) valueToAdd = np.complex(sigmaX, sigmaY) kSpace[i, j] = valueToAdd vectors = recovery(decayedRotatedMatrix, self.T1, self.TR) decayedRotatedMatrix[:, :, 0] = 0 decayedRotatedMatrix[:, :, 1] = 0 # vectors = np.zeros((self.phantomSize, self.phantomSize, 3)) # vectors[:, :, 2] = 1 self.showKSpace(kSpace) print(i) # kSpace = np.fft.fftshift(kSpace) # kSpace = np.fft.fft2(kSpace) # for i in range(0, self.phantomSize): # kSpace[i, :] = np.fft.fft(kSpace[i, :]) # for i in range(0, self.phantomSize): # kSpace[:, i] = np.fft.fft(kSpace[:, i]) kSpace = np.fft.fft2(kSpace) self.showKSpace(kSpace)