Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Now it\'s your turn to be that nameless technician! You are provided with zooman

ID: 3591989 • Letter: N

Question

Now it's your turn to be that nameless technician! You are provided with zoomandenhance.py. Fill in the following functions (a) zoom-This function will take a piece of a given image, blow it up, and return it as a new image. It takes as parameters a FileImage object and five numbers: upperLeftx, upperLeftY, lowerRightX, lowerRightY, and scalingFactor. The first four numbers represent the coordinates of the upper-left and lower-right corner of the portion of the original image to be blown up. You should create a new image that contains the specified portion of the image, but resized according to scalingFactor. So if scalingFactor is 2, the dimensions of the new image should be twice the dimensions of the specified region. If the scalingFactor is 3, they should be triple, and so on. Hint: Refer to the double and quadruple examples from class and lab 2. Before moving on, comment out the line in main: enhanced sharpen!mage(imageCopy) = and test to make sure that zoom works properly before moving on. (b) restrict - This function takes three numbers: num, minNum, and maxNum and restricts num to the range specified by minNum and maxNum. If num is at least minNum and at most maxNum, the function should just return num. If num is less than minNum, it should return minNum. If num is greater than maxNum, it should return maxNum.

Explanation / Answer

def       zoom(image, upperLeftX, upperLeftY, lowerRightX, lowerRightY, scalingFactor) :

            # add "from PIL import Image" in the beginning

            img = Image.open(image)

            img2 = img.crop((upperLeftX, upperLeftY, lowerRightX, lowerRightY)) // crop image

            img3 = scipy.ndimage.imread(img2, True) // read cropped image into img3

            newImage = scipy.ndimage.zoom(img3, scalingFactor) // scaling the image of given factor

            return newImage

def       restrict(num, minNum, maxNum):

            if num >=minNum and num <=maxNum

                        return num

            elif : num < minNum

                        return minNum

            elif: num > maxNum

                        return maxNum

def       sharpenImage(image) :

            im = Image.open(image)

            pxlMap = im.load()

            imgNew = Image.new( im.mode, im.size)

            newPxl = imgNew.load()

            rgb_im g = im.convert('RGB')

            # initialize first and last row in new image

            for i in range (0, imgNew.size[1]) :

                        newPxl [0, i] = pxlMap [0,i]

                        newPxl [imgNew.size[0] -1, i] = pxlMap [imgNew.size[0] -1,i]

            # initialize first and last cols in new image

            for i in range (0, imgNew.size[0]) :

                        newPxl [i, 0] = pxlMap [i,0]

                        newPxl [imgNew.size[1] -1, i] = pxlMap [imgNew.size[1] -1,i]

            # for loops to iterate over all the rows and cols except edges

            for i in range( 1, imgNew.size[0] -1 ):

                        for j in range(1, imgNew.size[1]-1):

                                    r, g, b = rgb_img.getpixel((i, j))                       # get RGB of current pixel

                                    # Get RGB of neighboring pixels

                                    r1,g1,b1 = rgb_img.getpixel((i-1,j-1))

                                    r2,g2,b2 = rgb_img.getpixel((i-1,j))

                                    r3,g3,b3 = rgb_img.getpixel((i-1,j+1))

                                    r4,g4,b4 = rgb_img.getpixel((i,j-1))

                                    r5,g5,b5 = rgb_img.getpixel((i,j+1))

                                    r6,g6,b6 = rgb_img.getpixel((i+1,j-1))           

                                    r7,g7,b7 = rgb_img.getpixel((i+1,j))

                                    r8,g8,b8 = rgb_img.getpixel((i+1,j+1))

                                    r = 9*r – (r1+r2+r3+r4+r5+r6+r7+r8)

                                    g = 9*g – (g1+g2+g3+g4+g5+g6+g7+g8)

                                    b = 9*b – (b1+b2+b3+b4+b5+b6+b7+b8)

                                    pxlMap [i, j] = (r,g,b)

                                    newPxl [I,j] = pxlMap [i, j]

            return imgNew

If this helps please give athumbs up. Happy Chegging !!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote