<jupyter_start><jupyter_text>Task 2: Image resizing (Upsampling / Downsampling)Note that in digital image processing upsampling or downsampling simply means resizing your image. When you upsample you zoom the image and vice-versa. We will use two different spatial domain approach (interpolation method) to achieve this:1. Nearest Neighbour interpolation/ Pixel replication method [Wiki](https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation)2. Bilinear interpolation method [Wiki](https://en.wikipedia.org/wiki/Bilinear_interpolation)In this assignment we will will not analyse the frequency domain signal.<jupyter_code>%%bash
pip install git+https://github.com/ee604/ee604_plugins
# Importing required libraries

import cv2
import numpy as np
import matplotlib.pyplot as plt

from ee604_plugins import download_dataset, cv2_imshow

download_dataset(assignment_no=1, task_no=2) # download data for this assignment
data = cv2.imread("data/parallel_lines.jpg")
def resize_nn(img, k=1):
    '''
    Write a program to resample the given image by a factor 'k' using Nearest Neighbour method
    
    Inputs:
    + img - Original image
    + k - resampling factor, therefore if input image size is 300x300 
        - and k=0.5 ==> output image size = 150x150
    
    Ouputs:
    + out_img - numpy array (of dtype np.uint8) containing the output image.
    
    Allowed external package:
    + You are not allowed to use any cv2 resize module or any other external package. 
    
    '''
    
    #############################
    # Start your code from here #
    #############################
    
    # Replace with your code...
    
    #############################
    # End your code here ########
    #############################    
    
    return out_img
def resize_bilinear(img, k=1):
    '''
    Write a program to resample the given image by a factor 'k' using Bilinear interpolation method.
    
    Inputs:
    + img - Original image
    + k - resampling factor
    
    Ouputs:
    + out_img - numpy array (of dtype np.uint8) containing the output image.
    
    Allowed external package:
    + You are not allowed to use any cv2 resize module or any other external package. 
    
    '''
    
    #############################
    # Start your code from here #
    #############################
    
    # Replace with your code...
    
    #############################
    # End your code here ########
    #############################    
    
    return out_img<jupyter_output><empty_output><jupyter_text>Sample the given image for following values of k = 0.5, 0.51, 0.99, 2, 2.1 using both the methods. Plot the images using `cv2_imshow` and write your observation on the differences with an intuitive explanation.<jupyter_code>orig_img = np.copy(data) # Resample this image

#############################
# Start your code from here #
#############################

# Replace with your code...

#############################
# End your code here ########
#############################  
your_observation = """
Replace this with your observations.
"""

print(your_observation)<jupyter_output>Replace this text with your observations.
{'fraction_non_alphanumeric': 0.17900063251106893, 'fraction_numerical': 0.01549652118912081, 'mean_word_length': 3.644640234948605, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '341969', 'license': 'MIT', 'n_tokens_mistral': 913, 'n_tokens_neox': 850, 'n_words': 308, 'path': 'assignment_1/Task_2.ipynb', 'repo_name': 'utkarsh530/ee604_assignments', 'size': '3162'}