Question

In: Computer Science

how to write a function that clears every pixel and sets it to the Red color....

how to write a function that clears every pixel and sets it to the Red color. similarly, we have to open the image including height and width and use while loop that accesses each pixel in Python

Solutions

Expert Solution

Code:

#Load and show an image with Pillow
from PIL import Image

'''
THE FUNCTION
It takes an image convert to red and returns the image
'''
def toRed(img):
width, height = img.size
i,j = 0,0
  
while(i<width):
j=0
while(j<height):
img.putpixel((i,j),(255,0,0))
j+=1
i+=1
return img
#TESTING THE FUNCTION
img = Image.open('Lenna.png')
redImg = toRed(img)
redImg.show()

Here is the result before and after:

Hope this helps.


Related Solutions

How is color used in the film The Red Shoes?
How is color used in the film The Red Shoes?
(Using Matlab) Write a function to "smooth" a black-and-white image by replacing each pixel by the...
(Using Matlab) Write a function to "smooth" a black-and-white image by replacing each pixel by the average of itself and its neighbors. In MATLAB a black-and-white image is just a matrix of 1s and 0s - 1 represents white, and 0 represents black. To keep the algorithm simple, ignore the edges of the image - that is, do not change the first and last rows and columns. function name = smooth_image() input argument = input matrix output argument = output...
Write a rule for a class selector named heading. Setthe color property to red and...
Write a rule for a class selector named heading. Set the color property to red and the font-family property to arial. Apply the heading class to theelement in the document
Write every answer in Probability Notation, for example: Event: one marble selected is Red: P(Red) =...
Write every answer in Probability Notation, for example: Event: one marble selected is Red: P(Red) = 12/33 = .3636 For each problem below, we use the following: A bag contains 33 marbles each with a color and a number. 12 Red labeled 1 – 12, 8 blue labeled 1-8, and 13 whites labeled 1-13. 1. A single marble is drawn from the bag:Event: The marble selected is white Event:The marble selected is odd Event: The marble meets both of the...
Write an application with three buttons labeled “Red”, “Green”, and “Blue” that changes the background color...
Write an application with three buttons labeled “Red”, “Green”, and “Blue” that changes the background color of a panel in the center of the frame to red, green, or blue. Add icons to the buttons of Exercise E19.1. Use a JButton constructor with an Icon argument and supply an ImageIcon. this is the code that I already wrote that I need to do the above to. import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame;...
A population of ants has a body color that is either red or black. The color...
A population of ants has a body color that is either red or black. The color is a result of one gene, with two alleles: The "B" allele (dominant) produces the black color, while the "b" allele (recessive) produces the red color. The gene system demonstrates complete dominance. The population is in HardyWeinberg equilibrium. In this population there are 38 black ants while there are 162 red ones. Determine the following genotypic and allele frequencies: Genotypic frequencies : Freq *...
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array...
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array to the sum of the corresponding elements in two other arrays. That is, if array 1 has the values 2,4, 5, and 8 and array 2 has the values 1, 0, 4, and 6, the function assigns array 3 the values 3, 4, 9, and 14. The function should take three array names and an array size as arguments. Test the function in a...
In the shrub Ixococ meloites, red flower color is incompletely dominant to white flower color. If...
In the shrub Ixococ meloites, red flower color is incompletely dominant to white flower color. If a true-breeding plant with red flowers is crossed to a true breeding plant with white flowers, what would be the phenotype of the F1 plants? a. The plants will all have red flowers. b. The plants will all have white flowers. c. The some of the flowers on an F1 plant will be red and other flowers on the same plant will be white....
In the fruit fly Drosophila melanogaster, wild type eye color is a brick red color and...
In the fruit fly Drosophila melanogaster, wild type eye color is a brick red color and is produced by the action of two genes, one producing red color, the other brown. Vermilion is an X-linked recessive mutation that results in a bright red eye. Brown is an autosomal recessive mutation that results in a brown eye. Flies carrying both the vermilion and brown mutations produce no pigment and have white eyes. True breeding Vermilion eyed females are crossed to brown...
Oxygenated hemoglobin absorbs weakly in the red (hence its red color) and strongly in the near...
Oxygenated hemoglobin absorbs weakly in the red (hence its red color) and strongly in the near infrared, whereas deoxygenated hemoglobin has the opposite absorption. This fact is used in a "pulse oximeter" to measure oxygen saturation in arterial blood. The device clips onto the end of a person's finger and has two light-emitting diodes—a red (632 nm) and an infrared (930 nm)—and a photocell that detects the amount of light transmitted through the finger at each wavelength. (a) Determine the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT