Exemplo n.º 1
0
start = time.time()
recon, firstRecon = iterative.sirt_frt_complex(
    it, N, drtSpace, mValues, t, 2, 1, oversampleFilter=oversampleFilter)
end = time.time()
elapsed = end - start
print("SIRT Reconstruction took " + str(elapsed) + " secs or " +
      str(elapsed / 60) + " mins")
testdrtSpace = finite.frt_complex(image, N, mValues=mValues)

recon = np.abs(recon)

diff = image - recon
sample = dftSpace * fractalMine
mse = imageio.immse(image, np.abs(recon))
ssim = imageio.imssim(image.astype(float), recon.astype(float))
psnr = imageio.impsnr(image, np.abs(recon))
print("RMSE:", math.sqrt(mse))
print("SSIM:", ssim)
print("PSNR:", psnr)

plt.figure(1)
plt.imshow(np.abs(drtSpace))
plt.figure(2)
plt.imshow(np.abs(recon))
plt.figure(3)
plt.imshow(np.abs(image))
plt.figure(4)
plt.imshow(np.abs(firstRecon))
plt.figure(5)
plt.imshow(np.abs(finite.frt_complex(recon, N)))
plt.figure(6)
    print("Image number: ", i)
    if i >= 0:
        break

end = time.time()
elapsed = end - start
print("ABfMLEM Reconstruction took " + str(elapsed) + " secs or " +
      str(elapsed / 60) + " mins")
recon = np.abs(recon)
images = np.abs(images)
diff = np.abs(image - recon)

mse = imageio.immse(np.abs(images[0, :, :]), np.abs(recon[0, :, :]))
ssim = imageio.imssim(
    np.abs(images[0, :, :]).astype(float),
    np.abs(recon[0, :, :]).astype(float))
psnr = imageio.impsnr(np.abs(images[0, :, :]), np.abs(recon[0, :, :]))
print("RMSE:", math.sqrt(mse))
print("SSIM:", ssim)
print("PSNR:", psnr)

plt.figure(2)
plt.imshow(np.abs(recon[0, :, :]))
plt.figure(3)
plt.imshow(np.abs(images[0, :, :]))
plt.figure(4)
plt.imshow(np.abs(firstRecon[0, :, :]))
plt.figure(9)
plt.imshow(np.abs(diff[0, :, :]))
plt.figure(10)
plt.imshow(np.abs(fftpack.ifft2(dftSpace[0, :, :] * fractalMine)))
Exemplo n.º 3
0
#radialReconDict = np.load('result_radial.npz')
radialReconDict = np.load('result_phantom_radial.npz')
#radialReconDict = np.load('result_camera_radial.npz')
radialRecon = radialReconDict['recon']
radialPSNRS = radialReconDict['psnrs']  #1 iteration
radialSSIMS = radialReconDict['ssims']
print("Radial Recon Size:", radialRecon.shape)
print("Radial Recon Min/Max:", radialRecon.min(), radialRecon.max())

#compute metrics
mse = imageio.immse(imageio.immask(image, mask, N, N),
                    imageio.immask(mlemRecon, mask, N, N))
ssim = imageio.imssim(
    imageio.immask(image, mask, N, N).astype(float),
    imageio.immask(mlemRecon, mask, N, N).astype(float))
psnr = imageio.impsnr(imageio.immask(image, mask, N, N),
                      imageio.immask(mlemRecon, mask, N, N))
print("MLEM Results ------")
print("RMSE:", math.sqrt(mse))
print("SSIM:", ssim)
print("PSNR:", psnr)

mse = imageio.immse(imageio.immask(image, mask, N, N),
                    imageio.immask(sirtRecon, mask, N, N))
ssim = imageio.imssim(
    imageio.immask(image, mask, N, N).astype(float),
    imageio.immask(sirtRecon, mask, N, N).astype(float))
psnr = imageio.impsnr(imageio.immask(image, mask, N, N),
                      imageio.immask(sirtRecon, mask, N, N))
print("SIRT Results ------")
print("RMSE:", math.sqrt(mse))
print("SSIM:", ssim)
Exemplo n.º 4
0
    
#csReconMat = loadmat('result_lego_2.mat')
csReconMat = loadmat('result_lego_4.mat')
#csReconMat = loadmat('result_lego_8.mat')
csRecon = np.abs(csReconMat['im_res'])*maxValue
diff2 = image2-csRecon

data2 = np.load('result_radial.npz')
radialRecon = data2['recon']
diff3 = image2-radialRecon
    
#-------------------------------
#compute metrics
mse = imageio.immse(image, np.abs(recon))
ssim = imageio.imssim(image.astype(float), np.abs(recon).astype(float))
psnr = imageio.impsnr(image, np.abs(recon))
print("ChaoS RMSE:", math.sqrt(mse))
print("ChaoS SSIM:", ssim)
print("ChaoS PSNR:", psnr)
mse = imageio.immse(image2, np.abs(csRecon))
ssim = imageio.imssim(image2.astype(float), np.abs(csRecon).astype(float))
psnr = imageio.impsnr(image2, np.abs(csRecon))
print("CS RMSE:", math.sqrt(mse))
print("CS SSIM:", ssim)
print("CS PSNR:", psnr)
mse = imageio.immse(image2, np.abs(radialRecon))
ssim = imageio.imssim(image2.astype(float), np.abs(radialRecon).astype(float))
psnr = imageio.impsnr(image2, np.abs(radialRecon))
print("Radial RMSE:", math.sqrt(mse))
print("Radial SSIM:", ssim)
print("Radial PSNR:", psnr)
Exemplo n.º 5
0
#-------------------------------
#reconstruct test using MLEM
start = time.time()  #time generation
recon = abmlem_expand_complex(iterations, p, drtSpace, subsetsMValues,
                              finite.frt_complex, finite.ifrt_complex)
recon = fftpack.ifftshift(recon)
recon = np.abs(recon)
print("Done")
end = time.time()
elapsed = end - start
print("OSEM Reconstruction took " + str(elapsed) + " secs or " +
      str(elapsed / 60) + " mins in total")

mse = imageio.immse(image, recon)
ssim = imageio.imssim(image.astype(float), recon.astype(float))
psnr = imageio.impsnr(image, recon)
print("RMSE:", math.sqrt(mse))
print("SSIM:", ssim)
print("PSNR:", psnr)
diff = image - recon

#save data
np.savez('result_abmlem.npz',
         K=K,
         s=s,
         p=p,
         iterations=iterations,
         recon=recon,
         diff=diff,
         image=image)
Exemplo n.º 6
0
def ossirt_expand_complex(iterations,
                          t,
                          p,
                          g_j,
                          os_mValues,
                          projector,
                          backprojector,
                          image,
                          mask,
                          epsilon=1e3,
                          dtype=np.int32):
    '''
    # Gary's implementation
    # From Lalush and Wernick;
    # f^\hat <- (f^\hat / |\sum h|) * \sum h * (g_j / g)          ... (*)
    # where g = \sum (h f^\hat)                                   ... (**)
    #
    # self.f is the current estimate f^\hat
    # The following g from (**) is equivalent to g = \sum (h f^\hat)
    '''
    norm = False
    center = False
    fdtype = floatType
    f = np.zeros((p, p), fdtype)

    mses = []
    psnrs = []
    ssims = []
    for i in range(0, iterations):
        print("Iteration:", i)
        for j, mValues in enumerate(os_mValues):
            #            print("Subset:", j)
            muFinite = len(mValues)

            g = projector(f, p, fdtype, mValues)

            # form parenthesised term (g_j / g) from (*)
            r = np.zeros_like(g)
            for m in mValues:
                #                r[m,:] = g_j[m,:] - g[m,:]
                for y in range(p):
                    r[m, y] = (g[m, y] - g_j[m, y]) / (muFinite * muFinite)

            # backproject to form \sum h * (g_j / g)
            g_r = backprojector(r, p, norm, center, 1, 0, mValues) / muFinite

            # Renormalise backprojected term / \sum h)
            # Normalise the individual pixels in the reconstruction
            f -= t * g_r

        if smoothReconMode > 0 and i % smoothIncrement == 0 and i > 0:  #smooth to stem growth of noise
            if smoothReconMode == 1:
                print("Smooth TV")
                f = denoise_tv_chambolle(f, 0.02, multichannel=False)
            elif smoothReconMode == 2:
                h = parameters[4]  #6, phantom; 4, camera
                if i > smoothMaxIteration:
                    h /= 2.0
                if i > smoothMaxIteration2:
                    h /= 4.0
                print("Smooth NL h:", h)
                fReal = denoise_nl_means(np.real(f),
                                         patch_size=3,
                                         patch_distance=7,
                                         h=h,
                                         multichannel=False,
                                         fast_mode=True).astype(fdtype)
                fImag = denoise_nl_means(np.imag(f),
                                         patch_size=3,
                                         patch_distance=7,
                                         h=h,
                                         multichannel=False,
                                         fast_mode=True).astype(fdtype)
                f = fReal + 1j * fImag
            elif smoothReconMode == 3:
                print("Smooth Median")
                f = ndimage.median_filter(f, 3)

        if i % plotIncrement == 0:
            img = imageio.immask(image, mask, N, N)
            recon = imageio.immask(f, mask, N, N)
            recon = np.abs(recon)
            mse = imageio.immse(img, recon)
            psnr = imageio.impsnr(img, recon)
            ssim = imageio.imssim(img.astype(float), recon.astype(float))
            print("RMSE:", math.sqrt(mse), "PSNR:", psnr, "SSIM:", ssim)
            mses.append(mse)
            psnrs.append(psnr)
            ssims.append(ssim)

    return f, mses, psnrs, ssims
Exemplo n.º 7
0
powSpectLena = np.abs(fftLenaShifted)

#add noise to kSpace
noise = finite.noise(fftLenaShifted, SNR)
if addNoise:
    fftLenaShifted += noise

#Recover full image with noise
print("Actual noisy image")
reconLena = fftpack.ifft2(fftLenaShifted)  #the '2' is important
reconLena = np.abs(reconLena)
reconNoise = lena - reconLena

mse = imageio.immse(lena, np.abs(reconLena))
ssim = imageio.imssim(lena.astype(float), np.abs(reconLena).astype(float))
psnr = imageio.impsnr(lena, np.abs(reconLena))
print("Acutal RMSE:", math.sqrt(mse))
print("Acutal SSIM:", ssim)
print("Acutal PSNR:", psnr)

#compute lines
centered = True
subsetsLines = []
subsetsMValues = []
mu = 0
for angles in subsetsAngles:
    lines = []
    mValues = []
    for angle in angles:
        m, inv = farey.toFinite(angle, p)
        u, v = radon.getSliceCoordinates2(m, powSpectLena, centered, p)