Question

In: Computer Science

Complete the class as specified to complete the linear interpolation algorithm in python. The comments within...

Complete the class as specified to complete the linear interpolation algorithm in python. The comments within the function definitions should specify what to do.

class interpolation:

def linear_interpolation(self, pt1, pt2, unknown):

"""Computes the linear interpolation for the unknown values using pt1 and pt2

take as input

pt1: known point pt1 and f(pt1) or intensity value

pt2: known point pt2 and f(pt2) or intensity value

unknown: take and unknown location

return the f(unknown) or intentity at unknown"""

#Write your code for linear interpolation here

return

def bilinear_interpolation(self, pt1, pt2, pt3, pt4, unknown):

"""Computes the linear interpolation for the unknown values using pt1 and pt2

take as input

pt1: known point pt1 and f(pt1) or intensity value

pt2: known point pt2 and f(pt2) or intensity value

pt1: known point pt3 and f(pt3) or intensity value

pt2: known point pt4 and f(pt4) or intensity value

unknown: take and unknown location

return the f(unknown) or intentity at unknown"""

# Write your code for bilinear interpolation here

# May be you can reuse or call linear interpolatio method to compute this task


return

Solutions

Expert Solution

class interpolation:

    def linear_interpolation(self, pt1, pt2, unknown):
        """Computes the linear interpolation for the unknown values using pt1 and pt2
        take as input
        pt1: known point pt1 and f(pt1) or intensity value
        pt2: known point pt2 and f(pt2) or intensity value
        unknown: take and unknown location
        return the f(unknown) or intentity at unknown"""

        #Write your code for linear interpolation here
        #pt1,pt2,unknown hold two pieces of data, first we have the coordinate and second we have the intensity of the pixel
        #returns the intensity of the pixel
        #formula from lecture notes of linear interpolation

        intensity = (pt1[1] * (pt2[0] - unknown[0])) / (pt2[0] - pt1[0]) + (pt2[1] * (unknown[0] - pt1[0])) / ( pt2[0] - pt1[0])

        return intensity

    def bilinear_interpolation(self, pt1, pt2, pt3, pt4, unknown):
        """Computes the linear interpolation for the unknown values using pt1 and pt2
        take as input
        pt1: known point pt1 and f(pt1) or intensity value
        pt2: known point pt2 and f(pt2) or intensity value
        pt1: known point pt3 and f(pt3) or intensity value
        pt2: known point pt4 and f(pt4) or intensity value
        unknown: take and unknown location
        return the f(unknown) or intentity at unknown"""

        # Write your code for bilinear interpolation here
        # May be you can reuse or call linear interpolatio method to compute this task
        #pt1,pt2,pt3,pt4,unknown hold 3 pieces of data, first/second we have the coordinates and last we have the intensity of the pixel
        #returns the intensity of the unknown pixel
        if pt1[0] == pt3[0]:
            return self.linear_interpolation((pt1[1],pt1[2]),(pt2[1],pt2[2]),(unknown[1],unknown[2]))
        elif pt1[1] == pt3[1]:
            return self.linear_interpolation((pt1[0],pt1[2]),(pt3[0],pt3[2]),(unknown[0],unknown[2]))

        R1 = self.linear_interpolation((pt1[0], pt1[2]), (pt3[0], pt3[2]), (unknown[0], unknown[2]))
        R2 = self.linear_interpolation((pt2[0], pt2[2]), (pt4[0], pt4[2]), (unknown[1],unknown[2]))


        P = self.linear_interpolation((pt1[1],R1),(pt2[1],R2),(unknown[1],unknown[2]))
        return P

Related Solutions

1. Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your...
1. Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code. While you are coding, it is helpful to break up your code into sub-functions and test the sub-functions as you go along.
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code....
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code. While you are coding, it is helpful to break up your code into sub-functions and test the sub-functions as you go along.
Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and...
Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and methods for holding the information for a document and write a program to test the class. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Document that has the following attributes and methods and is saved in the file Document.py. Attributes __title is a...
Factor Values Find the numerical value of the following factors using (a) linear interpolation (b) the...
Factor Values Find the numerical value of the following factors using (a) linear interpolation (b) the appropriate formula 1. (F/P,18%,33) 2. (A/G,12%,54)
Determine the numerical value of the following factors using (a) linear interpolation, (b) the formula 1....
Determine the numerical value of the following factors using (a) linear interpolation, (b) the formula 1. (P/F,8.4%,15) 2. (A/F,17%,10)
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial...
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial P1(x) using the nodes x0= -1 and x1 = 0 b) Find the quadratic interpolation polynomial P2(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 c) Find the cubic interpolation polynomial P3(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 and x3=2 d) Find the linear interpolation polynomial P1(x) using the nodes x0= 1...
Question 1: Using Python 3 Create an algorithm The goal is to create an algorithm that...
Question 1: Using Python 3 Create an algorithm The goal is to create an algorithm that can sort a singly-linked-list with Merge-sort. The program should read integers from file (hw-extra.txt) and create an unsorted singly-linked list. Then, the list should be sorted using merge sort algorithm. The merge-sort function should take the head of a linked list, and the size of the linked list as parameters. hw-extra.txt provided: 37 32 96 2 25 71 432 132 76 243 6 32...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
In Java: Complete the following methods in the template by adhering to the comments: // TO...
In Java: Complete the following methods in the template by adhering to the comments: // TO DO: add your implementation and JavaDoc public class BetterArray<T> { private static final int DEFAULT_CAPACITY = 2; //default initial capacity / minimum capacity private T[] data; //underlying array, you MUST use this for full credit // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! @SuppressWarnings("unchecked") public BetterArray() { //constructor //initial capacity of the array should be DEFAULT_CAPACITY } @SuppressWarnings("unchecked") public BetterArray(int initialCapacity) { // constructor...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT