Question

In: Computer Science

Part 1: Image effects Your first task is to write two functions that manipulate digital images....

Part 1: Image effects

Your first task is to write two functions that manipulate digital images.

    

You will write two functions that take an image object, create a copy, perform a pixel-by-pixel manipulation, and return the manipulated copy. We have provided three helper functions (open_image, display_image, and save_image) that you can use to test your code. You may write any additional helper functions that you find useful. Below there are descriptions and sample images for each of the required manipulations.

The best way to test your image functions is to modify the main function at the bottom of hw7_images.py. You can add calls to the various image functions and use the helper functions to display and save the new/modified image.

The code for an example function, red_filter, is provided in hw7_images.py; images to show the effect of this filter are shown below.

  

The two functions you must write are as follows:

1. negative

Create a negative of the image by inverting all of the color values. Recall that the minimum color value is 0 and the maximum is 255. So a color value of 255 becomes 0 and a value of 33 becomes 222.

Solutions

Expert Solution

SOLUTION

This is the required function:

def negative(image_obj):

#copying the image

img_copy = image_obj.copy()

h,w,_ = img_copy.shape

for i in range(h):

for j in range(w):

pixel_value = list(img_copy[i,j])

#negating all chanel values

pixel_value[0] = abs(255-pixel_value[0])

pixel_value[1] = abs(255-pixel_value[1])

pixel_value[2] = abs(255-pixel_value[2])

img_copy[i,j] = pixel_value

return img_copy

________________________________________________________________________________

here is the total code and the sample output:

Left side is the inverted image and the right side is the actual image

Comment if any doubts


Related Solutions

Create two new images by applying a threshold first to various colors in the image. In...
Create two new images by applying a threshold first to various colors in the image. In practice, applying a threshold means that you zero out (set to zero) any value above or below a specified limit. For the first image (im1mod1), zero out all pixels that are below the value 128. For the second image (im1mod2), zero out all red pixels entirely, zero out all green pixels ABOVE 128, and zero out all blue pixels BELOW 128. Use the command...
Consider two Images of same dimensions where one image is an original image and other should...
Consider two Images of same dimensions where one image is an original image and other should be a degraded image.    Write a matlab program to measure picture quality using objective assessment validation criteria for the degraded image and original image. Calculate MSE, PSNR, Normalized absolute error, Maximum Difference, Structural content, Average difference, Normalized cross correlation for the images.    Explain the importance of Objective assessment in Image processing
AM REALLY IN NEED OF THE NARRATIVE ANALYSIS PART Question 1: Your first task is to...
AM REALLY IN NEED OF THE NARRATIVE ANALYSIS PART Question 1: Your first task is to determine whether your firm is in a competitive industry. Based on the following demand function for the firm's product, what would you answer? Q = 50,000 – 25*P Q is the amount produced and P is the price. . Submit your Competitive Industry Report and Calculations to the dropbox below. Be sure to show your calculations in Excel and provide a narrative analysis in...
JavaScript Task Load three images of colorful fall leaves and using functions with parameters do the...
JavaScript Task Load three images of colorful fall leaves and using functions with parameters do the following. (Remember you can call the same function multiple times sending the function different values.) When you move the mouse over the first image, have the second image change to a pumpkin. When you move the mouse off of the first image, have the second image change back to the original leaves. When you move the mouse over the second image, have the third...
python: modify an image (just show me how to write the two functions described below) 1.One...
python: modify an image (just show me how to write the two functions described below) 1.One way to calculate the contrast between two colours is to calculate the brightness of the top pixel (the average of the red, green and blue components, with all three components weighted equally), and subtract the brightness of the pixel below it. We then calculate the absolute value of this difference. If this absolute value is greater than a threshold value, the contrast between the...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
In each part below, a task is described. Your job is to write one or more...
In each part below, a task is described. Your job is to write one or more JAVA statements which will accomplish this task. Assume that all variables have data type int. If you need other variables you may declare them and use them. a. 6 pts Assume that variables x, y, and z have values. Print all the values from x to y that are evenly divisible by z. For example, if x is 6, y is 18, and z...
1: Your first task is to determine whether your firm is in a competitive industry.
  Question 1: Your first task is to determine whether your firm is in a competitive industry. Based on the following demand function for the firm's product, what would you answer? Q = 50,000 – 25*P Q is the amount produced and P is the price. . Submit your Competitive Industry Report and Calculations to the dropbox below. Be sure to show your calculations in Excel and provide a narrative analysis in PowerPoint. Your narrative analysis should summarize the results...
MCS 5 Transforming IT at Global Digital Imaging “We are your images!” proclaimed the various posters...
MCS 5 Transforming IT at Global Digital Imaging “We are your images!” proclaimed the various posters showing different types of uses for images—from personal to professional photos, x-rays to ultrasound, brain scans to jaw scans—down the long hallway away from the boardroom. As Ray Henderson strode out to the elevator, the tagline evoked many images in his own head—images of the proud company he had joined as a fresh-faced university grad that had ranked high in the Fortune 1000 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT