Example #1
0
def display_diff(im1, im2):
    im_diff = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY) - cv2.cvtColor(
        im2, cv2.COLOR_BGR2GRAY)
    dip.figure()
    dip.imshow(im_diff)
    dip.title('Difference image')
    dip.show()
Example #2
0
def display_images(images, text):
    num = len(images)

    dip.figure()
    for i in range(num):
        dip.subplot(1, num, i + 1)
        dip.title(text[i])
        dip.imshow(images[i])

    dip.show()
Example #3
0
 def _test_noise_mode(self, file, deg_type):
     fh = ImageFileHandler()
     im = fh.open_image_file_as_matrix(file)
     degraded_im = self.degrade(im, degradation_type=deg_type)
     dip.figure()
     dip.subplot(121)
     dip.imshow(im, cmap="gray")
     dip.subplot(122)
     dip.imshow(degraded_im, cmap="gray")
     dip.xlabel("PSNR: {0:.2f}".format(dip.PSNR(im, degraded_im)))
     dip.show()
Example #4
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()
Example #5
0
def show_image(IMG, IMG_DCT, IMG_DIFF, IMG_RECONS):
    '''Function to display image'''
    IMG = floater(IMG)
    IMG_DCT = floater(IMG_DCT)
    IMG_DIFF = floater(IMG_DIFF)
    IMG_RECONS = floater(IMG_RECONS)

    dip.figure()
    dip.subplot(2, 2, 1)
    dip.imshow(IMG, 'gray')
    dip.title('Grayscale Image', fontsize='x-small')

    dip.subplot(2, 2, 2)
    dip.imshow(IMG_DCT, 'gray')
    dip.title('DCT of Image', fontsize='x-small')

    dip.subplot(2, 2, 3)
    dip.imshow(IMG_DIFF)
    dip.colorbar()
    dip.title('Error image', fontsize='x-small')

    dip.subplot(2, 2, 4)
    dip.imshow(IMG_RECONS, 'gray')
    dip.title('Reconstructed Image', fontsize='x-small')

    dip.show()
Example #6
0
def float_image_op(IMG, save_path, args, downsample = True):
    '''Function to display and save an float image'''
    IMG = dip.float_to_im(IMG/255)
    if downsample:
        save_path = os.path.join (SAVE_PATH, DOWNSAMPLE_DIR,save_path)
    else:
        save_path = os.path.join (SAVE_PATH, UPSAMPLE_DIR,save_path)    
    dip.image_io.im_write(IMG, save_path)
    if args.verbose:
        if downsample:
            print ("Downsampled Image is saved")
        else:
            print ("Upsampled Image is saved")
    dip.imshow(IMG)
    dip.show()
    def _test_restore_mode(self, file, deg_type, save_images=False, name=None):
        fh = ImageFileHandler()
        im_degrader = ImageDegrader()
        im = fh.open_image_file_as_matrix(file)
        degraded_im = im_degrader.degrade(im,
                                          degradation_type=deg_type,
                                          severity_value=.5)
        restored_im, clustered_im, h_params = self.multiplicative_clustering_restore(
            degraded_im)
        restored_im_2 = self.fast_multiplicative_restore(
            degraded_im, h_param=np.mean(h_params), search_window_size=21)
        if save_images:
            dip.im_write(dip.float_to_im(degraded_im),
                         "./" + name + "_degraded_image.jpg",
                         quality=95)
            dip.im_write(dip.float_to_im(restored_im),
                         "./" + name + "_restored_image.jpg",
                         quality=95)
            dip.im_write(dip.float_to_im(clustered_im),
                         "./" + name + "_clustered_image.jpg",
                         quality=95)

        dip.figure()

        dip.subplot(141)
        dip.imshow(im, cmap="gray")

        dip.subplot(142)
        dip.imshow(degraded_im, cmap="gray")
        dip.xlabel("PSNR: {0:.2f}, SSIM: {1:.2f}".format(
            dip.PSNR(im, degraded_im),
            dip.SSIM(im, degraded_im)[0]))

        dip.subplot(143)
        dip.imshow(restored_im, cmap="gray")
        dip.xlabel("PSNR: {0:.2f}, SSIM: {1:.2f}".format(
            dip.PSNR(im, restored_im),
            dip.SSIM(im, restored_im)[0]))

        dip.subplot(144)
        dip.imshow(restored_im_2, cmap="gray")
        dip.xlabel("PSNR: {0:.2f}, SSIM: {1:.2f}".format(
            dip.PSNR(im, restored_im_2),
            dip.SSIM(im, restored_im_2)[0]))

        dip.show()
Example #8
0
def display_image(IMAGES):
    '''Display the Images and save'''
    IMAGES = [dip.float_to_im(IMG / 255) for IMG in IMAGES]
    dip.figure()
    dip.subplot(2, 2, 1)
    dip.imshow(IMAGES[0], 'gray')
    dip.title('Airplane Original Image')
    dip.subplot(2, 2, 2)
    dip.imshow(IMAGES[1], 'gray')
    dip.title('Brussels Original Image')
    dip.subplot(2, 2, 3)
    dip.imshow(IMAGES[2], 'gray')
    dip.title('Reconstructed Airplane Image')
    dip.subplot(2, 2, 4)
    dip.imshow(IMAGES[3], 'gray')
    dip.title('Reconstructed Brussels Image')
    dip.show()
def display_image(args, IMAGES):
    '''Display a float image and save'''
    if args.verbose:
        msg = bcolors.OKBLUE + "Displaying and saving the image" + bcolors.ENDC
        name = "lena_interp.png"
    IMAGES = [dip.float_to_im(IMG / 255) for IMG in IMAGES]
    dip.figure()
    dip.subplot(2, 2, 1)
    dip.imshow(IMAGES[0], 'gray')
    dip.title('Original Image')
    dip.subplot(2, 2, 2)
    dip.imshow(IMAGES[1], 'gray')
    dip.title('Interpolated Image')
    dip.subplot(2, 2, 3)
    dip.imshow(IMAGES[2], 'gray')
    dip.title('Reconstructed Image')
    dip.subplot(2, 2, 4)
    dip.imshow(IMAGES[3], 'gray')
    dip.title('Difference Image')
    dip.show()
PSNR_mild = dip.metrics.PSNR(dip.float_to_im(X / 255),
                             dip.float_to_im(extEdgeMildX / 255))
PSNR_severe = dip.metrics.PSNR(dip.float_to_im(X / 255),
                               dip.float_to_im(extEdgeSevereX / 255))

#Displaying PSNR Output
print("\n\tPSNR for extended Laplacian with minor blurring is %.2f" %
      PSNR_minor)
print("\n\tPSNR for extended Laplacian with mild blurring is %.2f" % PSNR_mild)
print("\n\tPSNR for extended Laplacian with severe blurring is %.2f" %
      PSNR_severe)

#Image Output
dip.figure()
dip.subplot(3, 4, 1)
dip.imshow(X, 'gray')
dip.title('Original Image', fontsize='x-small')
dip.subplot(3, 4, 2)
dip.imshow(minorX, 'gray')
dip.title('Minor Blurring', fontsize='x-small')
dip.subplot(3, 4, 3)
dip.imshow(mildX, 'gray')
dip.title('Mild Blurring', fontsize='x-small')
dip.subplot(3, 4, 4)
dip.imshow(severeX, 'gray')
dip.title('Severe Blurring', fontsize='x-small')
dip.subplot(3, 4, 5)
dip.imshow(edgeMinorX, 'gray')
dip.title('Laplacian on Minor Blurring', fontsize='x-small')
dip.subplot(3, 4, 6)
dip.imshow(edgeMildX, 'gray')
Example #11
0
yy = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
Gx = signal.convolve2d(img, xx, boundary='symm', mode='same')
Gy = signal.convolve2d(img, yy, boundary='symm', mode='same')
Igradient_fd = 5
featureimg_total = np.zeros((r, c, Igradient_fd))
featureimg_total[:, :, 0] = img
featureimg_total[:, :, 1] = Gx
featureimg_total[:, :, 2] = np.abs(Gx)
featureimg_total[:, :, 3] = Gy
featureimg_total[:, :, 4] = np.abs(Gy)

Igradient_fd = 5
for j in np.arange(Igradient_fd):
    featureimg = featureimg_total[:, :, j]
    dfeatureimg = featureimg.astype('double')
    itimg = np.cumsum(featureimg, axis=0)
    # dip.imshow(itimg,'gray')
    # dip.show()
    # cv2.imshow('imshow2',itimg/8)
    itimg = np.cumsum(itimg, axis=1)
    iimg = np.zeros((itimg.shape[0] + 2, itimg.shape[1] + 2))
    iimg[1:-1, 1:-1] = itimg
    dip.imshow(iimg, 'gray')
    dip.show()
    # dip.imshow(featureimg_total[:,:,j],'gray')
    # dip.show()
    # cv2.imshow('imshow1',itimg/8)
    # cv2.imshow('imshow0',featureimg_total[:,:,j]/8)

    cv2.waitKey(0)
cv2.destroyAllWindows()
def run_optical_flow(filepath_ind: int, OF_alg: int, param: int=100,
                     display: bool=True):

    frame_1 = dip.im_read(filepaths[filepath_ind] + 'frame1.png')[:, :, :3]
    frame_2 = dip.im_read(filepaths[filepath_ind] + 'frame2.png')[:, :, :3]
    residual = np.abs(frame_1.astype(float) - frame_2.astype(float)) \
            .astype(np.uint8)
    frame_1_gray = dip.rgb2gray(frame_1)
    frame_2_gray = dip.rgb2gray(frame_2)
    PSNR_val = dip.PSNR(frame_1_gray, frame_2_gray)
    if display:
        # Plot the initial images
        dip.figure()
        dip.subplot(1, 3, 1)
        dip.imshow(frame_1)
        dip.title('Frame 1', fontsize='x-small')
        dip.subplot(1, 3, 2)
        dip.imshow(frame_2)
        dip.title('Frame 2', fontsize='x-small')
        dip.subplot(1, 3, 3)
        dip.imshow(residual)
        dip.title('Residual - PSNR: {:.2f} dB'.format(PSNR_val), fontsize='x-small')

    # Convert to grayscale for analysis
    frame_1 = dip.im_to_float(frame_1_gray)
    frame_2 = dip.im_to_float(frame_2_gray)
    start_time = default_timer()

    # ============================ EDIT THIS PART =============================
    mask_x = np.array([[-1, 1], [-1,1]])
    mask_y = np.array([[-1, -1], [1,1]])
    mask_t_2 = np.array([[-1, -1], [-1,-1]])
    mask_t_1 = np.array([[1, 1], [1,1]])
    dIx = dip.convolve2d(frame_1, mask_x, mode='same', like_matlab=True)
    dIy = dip.convolve2d(frame_1, mask_y, mode='same', like_matlab=True)
    dIt = dip.convolve2d(frame_1, mask_t_1, mode='same', like_matlab=True) + dip.convolve2d(frame_2, mask_t_2, mode='same', like_matlab=True)
    
    # ==========!!!!! DO NOT EDIT ANYTHING BELOW THIS !!!!!====================

    # Instantiate blank u and v matrices
    u = np.zeros_like(frame_1)
    v = np.zeros_like(frame_1)

    if 0 == OF_alg:
        print('The optical flow is estimated using Horn-Schuck...')
        u, v = horn_schuck(u, v, dIx, dIy, dIt, param)
    elif 1 == OF_alg:
        print('The optical flow is estimated using Lucas-Kanade...')
        u, v = lucas_kanade(u, v, dIx, dIy, dIt, param)
    else:
        raise ValueError('OF_alg must be either 0 or 1')

    end_time = default_timer()

    # Determine run time
    duration = end_time - start_time
    clock = [int(duration // 60), int(duration % 60)]
    print('Flow estimation time was {} minutes and {} seconds'
            .format(*clock))

    # Downsample for better visuals
    stride = 10
    m, n = frame_1.shape
    x, y = np.meshgrid(range(n), range(m))
    x = x.astype('float64')
    y = y.astype('float64')

    # Downsampled u and v
    u_ds = u[::stride, ::stride]
    v_ds = v[::stride, ::stride]

    # Coords for downsampled u and v
    x_ds = x[::stride, ::stride]
    y_ds = y[::stride, ::stride]

    # Estimated flow
    estimated_flow = np.stack((u, v), axis=2)

    # Read file for ground truth flow
    ground_truth_flow = read_flow_file(filepaths[filepath_ind] + 'flow1_2.flo')
    u_gt_orig = ground_truth_flow[:, :, 0]
    v_gt_orig = ground_truth_flow[:, :, 1]
    u_gt = np.where(np.isnan(u_gt_orig), 0, u_gt_orig)
    v_gt = np.where(np.isnan(v_gt_orig), 0, v_gt_orig)


    # Downsampled u_gt and v_gt
    u_gt_ds = u_gt[::stride, ::stride]
    v_gt_ds = v_gt[::stride, ::stride]
    if display:
        # Plot the optical flow field
        dip.figure()
        dip.subplot(2, 2, 1)
        dip.imshow(frame_2, 'gray')
        dip.quiver(x_ds, y_ds, u_ds, v_ds, color='r')
        dip.title('Estimated', fontsize='x-small')
        dip.subplot(2, 2, 2)
        dip.imshow(frame_2, 'gray')
        dip.quiver(x_ds, y_ds, u_gt_ds, v_gt_ds, color='r')
        dip.title('Ground truth', fontsize='x-small')
        # Draw colored velocity flow maps
        dip.subplot(2, 2, 3)
        dip.imshow(flow_to_color(estimated_flow))
        dip.title('Estimated', fontsize='x-small')
        dip.subplot(2, 2, 4)
        dip.imshow(flow_to_color(ground_truth_flow))
        dip.title('Ground truth', fontsize='x-small')

    # Normalization for metric computations
    normalize = lambda im: (im - np.min(im)) / (np.max(im) - np.min(im))
    un = normalize(u)
    un_gt = normalize(u_gt)
    un_gt[np.isnan(u_gt_orig)] = 1
    vn = normalize(v)
    vn_gt = normalize(v_gt)
    vn_gt[np.isnan(v_gt_orig)] = 1

    # Error calculations and displays
    EPE = ((un - un_gt) ** 2 + (vn - vn_gt) ** 2) ** 0.5
    AE = np.arccos(((un * un_gt) + (vn * vn_gt) + 1) /
                   (((un + vn + 1) * (un_gt + vn_gt + 1)) ** 0.5))
    EPE_nan_ratio = np.sum(np.isnan(EPE)) / EPE.size
    AE_nan_ratio = np.sum(np.isnan(AE)) / AE.size
    EPE_inf_ratio = np.sum(np.isinf(EPE)) / EPE.size
    AE_inf_ratio = np.sum(np.isinf(AE)) / AE.size
    print('Error nan ratio: EPE={:.2f}, AE={:.2f}'
            .format(EPE_nan_ratio, AE_nan_ratio))
    print('Error inf ratio: EPE={:.2f}, AE={:.2f}'
            .format(EPE_inf_ratio, AE_inf_ratio))
    EPE_avg = np.mean(EPE[~np.isnan(EPE)])
    AE_avg = np.mean(AE[~np.isnan(AE)])
    print('EPE={:.2f}, AE={:.2f}'.format(EPE_avg, AE_avg))

    if display:
        dip.show()

    return clock, EPE_avg, AE_avg
Example #13
0
# 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)
I3 = dip.float_to_im(I3/255)
H2 = dip.fftshift(H2)
H2 = np.log(np.abs(H2))
H3 = np.pad(H2,(128, 128), 'constant', constant_values = (0,0))
# Plotting
dip.figure()
dip.subplot(2, 3, 1)
dip.imshow(I1, 'gray')
dip.title('Original Image')
dip.subplot(2, 3, 2)
dip.imshow(I2, 'gray')
dip.title('Downsampled Image')
dip.subplot(2, 3, 3)
dip.imshow(I3, 'gray')
dip.title('Interpolated image')
dip.subplot(2, 3, 4)
dip.imshow(H1, 'gray')
dip.title('Spectrum of Original Image')
dip.subplot(2, 3, 5)
dip.imshow(H2, 'gray')
dip.title('Spectrum of Downsampled Image')
dip.subplot(2, 3, 6)
dip.imshow(H3, 'gray')
Example #14
0
    return X_rec


#X = dip.im_read('airplane_downsample_gray_square.jpg')
X = dip.im_read('brussels_gray_square.jpg')

X_hat_1 = KLT_blocks(X, 1, 10)
X_hat_12 = KLT_blocks(X, 12, 10)
X_hat_24 = KLT_blocks(X, 24, 10)
diff_1 = X - X_hat_1
diff_12 = X - X_hat_12
diff_24 = X - X_hat_24

dip.figure(1)
dip.subplot(2, 2, 1)
dip.imshow(X, 'gray')
dip.title('Original')
dip.subplot(2, 2, 2)
dip.imshow(X_hat_1, 'gray')
dip.title('k = 1')
dip.subplot(2, 2, 3)
dip.imshow(X_hat_12, 'gray')
dip.title('k = 12')
dip.subplot(2, 2, 4)
dip.imshow(X_hat_24, 'gray')
dip.title('k = 24')

dip.figure(2)
dip.subplot(1, 3, 1)
dip.imshow(diff_1, 'gray')
dip.colorbar()
# STEP 1: Loading the image
# ============================ EDIT THIS PART =================================
im = dip.image_io.im_read(img_path)

# STEP 2: Converting to YCrCb
# ============================ EDIT THIS PART =================================
im = dip.utilities.rgb2ycbcr(im) # HINT: Look into dip.rgb2ycbcr

# STEP 3: Keep only the luminance channel
# ============================ EDIT THIS PART =================================
im = im[:,:,0]

# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
dip.figure()
dip.subplot(2, 2, 1)
dip.imshow(im, 'gray')
dip.title('Grayscale image', fontsize='x-small')

# STEP 4: Calculating the image entropy
# ============================ EDIT THIS PART =================================
H = dip.metrics.entropy(im)

# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
print("Entropy of the grayscale image = {:.2f} bits/pixel".format(H))

# STEP 5: Coding of the original image
# ============================ EDIT THIS PART =================================
byte_seq, _,_,_ = dip.coding.huffman_encode(im.flatten())
l,b = im.shape
im_bit_rate = (len(byte_seq)*8.0)/float(l*b)
# ===================!!!!! DO NOT EDIT THIS PART !!!!!=========================
Example #16
0
im_gaussian = dip.image_noise(im, "gaussian")
im_poisson = dip.image_noise(im, "poisson")
im_salt_pepper = dip.image_noise(im, "s&p")
im_speckle = dip.image_noise(im, "speckle")

# Compute the SSIM values and images
# ============================ EDIT THIS PART =============================
mssim_gaussian, ssim_image_gaussian = dip.metrics.SSIM(im, im_gaussian)
mssim_poisson, ssim_image_poisson = dip.metrics.SSIM(im, im_poisson)
mssim_salt_pepper, ssim_image_salt_pepper = dip.metrics.SSIM(
    im, im_salt_pepper)
mssim_speckle, ssim_image_speckle = dip.metrics.SSIM(im, im_speckle)

dip.figure()
dip.subplot(2, 4, 1)
dip.imshow(im_gaussian, 'gray')
dip.title('Distortion type: gaussian', fontsize='x-small')
dip.subplot(2, 4, 2)
dip.imshow(im_poisson, 'gray')
dip.title('Distortion type: poisson', fontsize='x-small')
dip.subplot(2, 4, 3)
dip.imshow(im_salt_pepper, 'gray')
dip.title('Distortion type: salt & pepper', fontsize='x-small')
dip.subplot(2, 4, 4)
dip.imshow(im_speckle, 'gray')
dip.title('Distortion type: speckle', fontsize='x-small')

dip.subplot(2, 4, 5)
dip.imshow(ssim_image_gaussian, 'gray')
dip.title('SSIM Map; MSSIM={0:.2f}'.format(mssim_gaussian), fontsize='x-small')
dip.subplot(2, 4, 6)
Example #17
0
"""
example code, will show a random FITS image
"""

import numpy as np
import dippykit as dip
import neowise_api as neo
from fits_file import Fits

IMAGE_DETAILS = neo.find_params()
NAME = IMAGE_DETAILS[0]
IMAGE = neo.download_fits(NAME)
FITS = Fits(IMAGE, IMAGE_DETAILS)
FITS.filter_image()
FITS.image = np.clip(FITS.image, np.median(FITS.image), np.max(FITS.image))
FITS.image = np.log(FITS.image - np.median(FITS.image) + 1)
FITS.image = np.clip(FITS.image, 0.3 * np.max(FITS.image), np.max(FITS.image))
print(FITS.coordinates())
dip.imshow(FITS.image, cmap='gist_heat')
dip.colorbar()
dip.show()
Example #18
0
print('sharpen3')
print(dip.PSNR(img, sharpen3))

Esharpen1 = scale(img1 - ELap1)
print('Esharpen1')
print(dip.PSNR(img, Esharpen1))
Esharpen2 = scale(img2 - ELap2)
print('Esharpen2')
print(dip.PSNR(img, Esharpen2))
Esharpen3 = scale(img3 - ELap3)
print('Esharpen3')
print(dip.PSNR(img, Esharpen3))

dip.figure(1)
dip.subplot(1, 3, 1)
dip.imshow(img1, 'gray')
dip.title('Minor Distortion')
dip.subplot(1, 3, 2)
dip.imshow(img2, 'gray')
dip.title('Mild Distortion')
dip.subplot(1, 3, 3)
dip.imshow(img3, 'gray')
dip.title('Severe Distortion')

dip.figure(2)
dip.subplot(1, 3, 1)
dip.imshow(Lap1, 'gray')
dip.title('Minor Distortion')
dip.subplot(1, 3, 2)
dip.imshow(Lap2, 'gray')
dip.title('Mild Distortion')
            for l in range(SIZE):
                xIndex = n - k
                yIndex = m - l
                if (xIndex < 0):
                    xIndex = LEN + xIndex
                if (yIndex < 0):
                    yIndex = WIDTH + yIndex
                coeff = (k**2 + l**2) / (2 * (sigma**2))
                h_kl = np.exp(-coeff)
                coeffSum = coeffSum + h_kl
                outputSum = outputSum + h_kl * g[xIndex, yIndex]
        gaussianImage[n, m] = (outputSum + TEENY) / (coeffSum + TEENY)
#Displaying the Images
dip.figure()
dip.subplot(1, 5, 1)
dip.imshow(f, 'gray')
dip.title('Original Image', fontsize='x-small')
dip.subplot(1, 5, 2)
dip.imshow(g, 'gray')
dip.title('Noised Image', fontsize='x-small')
dip.subplot(1, 5, 3)
dip.imshow(gaussianImage, 'gray')
dip.title('Gaussian Filtering', fontsize='x-small')
#Printing the MSE
mseGaussian = dip.metrics.MSE(f * 255, gaussianImage * 255)
print("\n\tThe MSE for Gaussian Transform is %.2f.\n" % mseGaussian)

#Computing the Sigma Filter
SIZE = 6
p = 40 / 255
TEENY = 0.0000000000001
Example #20
0
        tmp2 = np.pad(tmp2, ((0, 0), (error_col, error_col), (0, 0)),
                      'constant',
                      constant_values=(0, 0))
    tmp3 = tmp2[int(tmp2.shape[0] / 2 - 1 - row / 2 +
                    1):int(tmp2.shape[0] / 2 + row / 2),
                int(tmp2.shape[1] / 2 - 1 - col / 2 +
                    1):int(tmp2.shape[1] / 2 + col / 2), :]
    tmp4 = np.clip(tmp3, 0, 1)
    return tmp4


#example
filename = 'images/airplane.jpg'
im = dip.im_read(filename)
#downSampling
down_IMG = zoomAndshrink(im, 2.5, 1.0 / 1.7, 27.5 / 180.0 * np.pi)
dip.figure(1)
dip.imshow(down_IMG)

#upSampling
up_IMG = zoomAndshrink_inv(down_IMG, 0.4, 1.7, -27.5 / 180.0 * np.pi, im.shape)
dip.figure(2)
dip.imshow(up_IMG)

#show difference
dip.figure(3)
dip.imshow(im - up_IMG)

#show PSNR
print(dip.PSNR(im, up_IMG))
dip.show()
Example #21
0
# 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)
dip.imshow(abs(np.log(dip.fftshift(F))), 'gray')
dip.title('Original spectra')

dip.subplot(2, 2, 4)
dip.imshow(abs(np.log(dip.fftshift(F) * h)), 'gray')
dip.title('Modified spectra')

dip.show()
Example #22
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()
Example #23
0
                    pixel_array[p] =  avg_pixel_value
                    
            

            if (im_skin[i,j] == [0,0,0]).all():
                im_skin_interp[i,j] = pixel_array[0]
            if (im_skin[i,j+1] == [0,0,0]).all():
                im_skin_interp[i,j+1] = pixel_array[1]
            if (im_skin[i+1,j] == [0,0,0]).all():
                im_skin_interp[i+1 ,j] = pixel_array[2]
            if (im_skin[i+1,j+1] == [0,0,0]).all():
                im_skin_interp[i+1,j+1] = pixel_array[3]
            
#Display only skin-coloured pixels on original image and interpolated skin 

"""
%matplotlib inline
dip.imshow(im_skin)
dip.show()

%matplotlib inline
dip.imshow(im_skin_interp)
dip.show()

"""
#COPY PIXELS OF INTERPOLATED SKIN ONTO THE ORIGINAL PICTURE

im_res = np.copy(im_original)


cv2.imwrite('temp_images/mask.png',mask)