def fareyMapping(N): ''' Print out the Farey/rational angle mapping to the finite angle set. The angles are based on L1 norm minimal rational angle set. Also returns the finite angle set, matching rational angles and No. of bins lists ''' #create angle set with Farey vectors fareyVectors = farey.Farey() fareyVectors.compactOn() fareyVectors.generateFiniteWithCoverage(N) # angles = fareyVectors.vectors # print "Number of Projections:", len(angles) # print fareyVectors.finiteAngles # print fareyVectors.vectors #sort to reorder result for prettier printing finiteAnglesSorted, anglesSorted = fareyVectors.sort('finite') #print mapping BList = [] for finiteAngle, angle in zip(finiteAnglesSorted, anglesSorted): p, q = farey.get_pq(angle) B = farey.projectionLength(angle, N, N) BList.append(B) print("m:", finiteAngle, "p:", p, "q:", q, "B:", B) return finiteAnglesSorted, anglesSorted, BList
def getMojetteSlice(angle, P, Q, data, center=False): ''' Get the Mojette slice (at angle) of a NxN discrete array using the discrete non-periodic Fourier slice theorem. This can be applied to the DFT or the NTT arrays. ''' N, N = data.shape p, q = farey.get_pq(angle) B = getMojetteProjectionLength(angle, P, Q) # print "B Mojette:", B offset = 0.0 if center: offset = N/2.0 slice = np.zeros(2*B-1, dtype=data.dtype) # slice = np.zeros(B, dtype=data.dtype) for translate in range(0, B): translateP = (p*translate)%N #has issues in C, may need checking translatePConjugate = (N-translateP+offset)%N #has issues in C, may need checking translateQ = (q*translate)%N #has issues in C, may need checking translateQConjugate = (N-translateQ+offset)%N #has issues in C, may need checking slice[translate] = data[(translateQ+offset)%N, (translateP+offset)%N] if translate != 0: slice[(2*B-1-translate)%N] = data[translateQConjugate, translatePConjugate] # slice[(B-translate)%N] = data[translateQConjugate, translatePConjugate] return slice
def computeKatzLines(kSpace, anglesSorted, finiteAnglesSorted, K, centered = True, twoQuads = False): ''' compute finite lines coordinates given Katz criterion Returns a list or list of slice 2-tuples and corresponding list of angles and m values perp computes the perpendicular (s) lines as well ''' N, M = kSpace.shape lines = [] angles = [] mValues = [] for m, angle in zip(finiteAnglesSorted, anglesSorted): if isKatzCriterion(N, N, angles, K): print("Katz Criterion Met. Breaking") break m, inv = farey.toFinite(angle, N) u, v = radon.getSliceCoordinates2(m, kSpace, centered) lines.append((u,v)) mValues.append(m) angles.append(angle) #second quadrant if twoQuads: if m != 0 and m != N: #dont repeat these m = N-m u, v = radon.getSliceCoordinates2(m, kSpace, centered) lines.append((u,v)) mValues.append(m) p, q = farey.get_pq(angle) newAngle = farey.farey(-p,q) #not confirmed angles.append(newAngle) return lines, angles, mValues
def mojetteProjection(projection, N, angle, P, Q): ''' Convert a finite projection into a Mojette projection for given (p,q). Assumes you have correctly determined (p,q) for the m value of the finite projection. ''' # dyadic = True # if N % 2 == 1: # if odd, assume prime # dyadic = False p, q = farey.get_pq(angle) B = farey.projectionLength(angle, P, Q) #no. of bins m, inv = farey.toFinite(angle, N) translateOffset, perp = farey.finiteTranslateOffset(angle, N, P, Q) mojetteProj = np.zeros(B) angleSign = p * q '''if nt.is_coprime(q, N): inv = q else: #perp projection inv = p for translate, bin in enumerate(projection): translateMojette = int((inv*translate)%N) if angleSign >= 0 and perp: #Reverse for perp translateMojette = int(translateOffset) - translateMojette else: translateMojette += int(translateOffset) print "TR:", translate, "Tm:", translateMojette mojetteProj[translateMojette] += bin''' for translate, bin in enumerate(mojetteProj): if angleSign >= 0 and perp: #Reverse for perp translateMojette = int(translateOffset) - int(translate) else: translateMojette = int(translate) - int(translateOffset) if translateMojette < 0: translateFinite = (N - (inv * abs(translateMojette)) % N) % N else: translateFinite = (inv * translateMojette ) % N #has issues in C, may need checking mojetteProj[translate] += projection[translateFinite] # print "TR:", translateFinite, "TM:", translate return mojetteProj
def isKatzCriterion(P, Q, angles, K=1): ''' Return true if angle set meets Katz criterion for exact reconstruction of discrete arrays ''' sumOfP = 0 sumOfQ = 0 n = len(angles) for j in range(0, n): p, q = farey.get_pq(angles[j]) sumOfP += abs(p) sumOfQ += abs(q) if sumOfP > K * P or sumOfQ > K * Q: return True else: return False