Beispiel #1
0
def dft(args):
    '''Compute and show DFT of image'''
    X = basic_image_ip(IMAGE_PATH, args)
    if args.verbose:
        print (X.shape)
    fX = dip.fft2(X)
    fX = dip.fftshift(fX)
    fX = np.log(np.abs(fX))
    if args.verbose:
        print ("Done with FFT")
    dip.imshow(fX)
    dip.show()
Beispiel #2
0
#(c) Reading an image
X = dip.im_read(picture_link)

#(d) Converting the image to normalized floating point space
X = dip.im_to_float(X)
X *= 255

#(e) Adding Constant to Image
Y = X + 75

#(f) Renormalize the image and covert to integer
Y = dip.float_to_im(Y/255)

#(g) Writing an image to disk
dip.im_write(Y, save_link_1)

#(h) Square Intenstiy and write image to disk
Z = X**2
Z = dip.float_to_im(Z/255)
Z = dip.im_write(Z, save_link_2)

#(i) Compute FFT of X
fX = dip.fft2(X)
fX = dip.fftshift(fX)
fX = np.log(np.abs(fX))

#(j) Save and show the resulting spectrum
dip.imshow(fX)
dip.show()
Beispiel #3
0
scan_id, frame_num, band = find_image(coordinateMetadata, utc)

params = find_image(coordinateMetadata, utc)

image = download_image(OBJECT, params)
print(image)

w = wcs.WCS(image)
x, y = w.wcs_world2pix(asteroidMetadata.ra[element],
                       asteroidMetadata.dec[element], 0)

X = display_fits(image)

X = filter(X)

plt.imshow(np.log(np.abs(X)))
plt.show()

fx = dip.fftshift(dip.fft2(X))
radius = 30
center = len(fx) / 2

f = np.log(np.abs(fx))
for a in range(len(f)):
    for b in range(len(f[a])):
        if np.square(center - a) + np.square(center - b) < np.square(radius):
            f[a, b] = 0

plt.imshow(np.log(np.abs(dip.ifft2(fx))))
plt.show()
Beispiel #4
0
import dippykit as dip
import numpy as np


# Part (a)
I1 = dip.im_read('/home/harshbhate/Pictures/lena.png')  # Specify your image here
I1 = dip.im_to_float(I1) #Converting image to float
I1 *= 255 #Normalizing
# Part (b)
# Take the Fourier transform of the image
H1 = dip.fft2(I1)  # Fourier transform of I1
H1 = dip.fftshift(H1)
H1 = np.log(np.abs(H1))
print ("Shape of I1:"+str(I1.shape))
print("Shape of H1"+str(H1.shape))
# Part (c)
# Downsample the image by 2 in both directions (and take its Fourier transform)
x_scaling = 2
y_scaling = 2
sampling_matrix = np.array([[x_scaling, 0],[0, y_scaling]])
I2 = dip.sampling.resample(I1, sampling_matrix)  # Downsampled I1
H2 = dip.fft2(I2)  # Fourier transform of I2
# Part (d)
# Pad the downsampled image's spectrum (H2) with zeros and then take its
# inverse Fourier transform
H3 = np.pad(H2,(128, 128), 'constant', constant_values = (0,0))  # Zero-padded H2
I3 = np.abs(dip.ifft2(H3)) # Interpolated image
I3 = I3/(np.amax(I3))*255   #Normalizing
#Converting everything back to int and normalizing
I1 = dip.float_to_im(I1/255)
I2 = dip.float_to_im(I2/255)
Beispiel #5
0
def parser():
    '''Parsing the input Argument'''
    parser = argparse.ArgumentParser()
    parser.add_argument("-v","--verbose", help="increase output verbosity",
                        action="store_true")
    args = parser.parse_args()
    return args

if __name__ == "__main__":
    '''Main Function'''
    #pdb.set_trace()
    args = parser()
    dft(args)
    M = np.array([[0, 1],
                  [1, 0]])
    if args.verbose:
        print ("The M matrix:\n"+str(M))
    L = L_matrix(M, args)
    if args.verbose:
        print ("The L matrix:\n"+str(L))
    Xd = downsample(M, args, 'm_5.jpg')
    Xt = upsample(Xd, L, args, None, 'm_5.jpg')
    Xt = upsample(Xd, L, args, 'lin', 'm_5_lin.jpg')
    #FFT of image rotated by 90
    fX = dip.fft2(Xd)
    fX = dip.fftshift(fX)
    fX = np.log(np.abs(fX))
    dip.imshow(fX)
    dip.show()

    PSNR (Xt, args)
Beispiel #6
0
# Proof of concept low pass filter
dim_filter = 800

h = np.zeros((dim_filter, dim_filter))
for u in range(dim_filter):
    for v in range(dim_filter):
        h[u][v] = exp(-(u + v) / (dim_filter * 0.3))

# Loading image
im = dip.im_read('images/UW_400.png')
im = dip.im_to_float(im)

if 2 < im.ndim:
    im = np.mean(im, axis=2)

F = dip.fft2(im)
print(h * F)

#Plot results
#Original spectra
dip.figure(1)

dip.subplot(2, 2, 1)
dip.imshow(im, 'gray')
dip.title('Original Image')

dip.subplot(2, 2, 2)
dip.imshow(np.real(dip.ifft2(F * h)), 'gray')
dip.title('Modified image')

dip.subplot(2, 2, 3)