Question

Python3

Write a program to apply a 'negative' filter on a greyscale image. The program should ask the user to enter a filename, open this file, perform the transformation (as described below) and then save the negative version of the image to the file 'output.png'.

To perform the negative effect, set each pixel in the output image to the opposite colour value than the corresponding pixel in the input image. For example, a colour value of 0 would become 255, 1 would become 254, 253 would become 2, and so on.

Here is an example of the effect your program should produce: astronaut.png Enter a filename: astronaut.png output.png

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def displayImageFileOnLCD(filename):
print 'displays ', filename
title = 'Review Mode'
# resize/dither to screen resolution and send to LCD
image = Image.open(filename)
im_width, im_height = image.size
if im_width < im_height:
image = image.rotate(90)
image.thumbnail(S_SIZE, Image.ANTIALIAS)
image_sized = Image.new('RGB', S_SIZE, (0, 0, 0))
image_sized.paste(image,((S_SIZE[0] - image.size[0]) / 2, (S_SIZE[1] - image.size[1]) / 2))
# draw filename
draw = ImageDraw.Draw(image_sized)
font = ImageFont.truetype('arial.ttf', 18)
draw.rectangle([(0, 0), (115, 22)], fill=(255,255,255), outline=(0,0,0))
draw.text((2, 2), title, fill='black', font=font)
draw.rectangle([(279, 217), (399, 239)], fill=(255,255,255), outline=(0,0,0))
draw.text((290, 218), filename, fill='black', font=font)
# display on LCD
image_sized = ImageOps.invert(image_sized)
image_sized = image_sized.convert('1') # convert image to black and white
lcd.write(image_sized.tobytes())

Add a comment
Know the answer?
Add Answer to:
Python3 Write a program to apply a 'negative' filter on a greyscale image. The program should ask the user to enter a filename, open this file, perform the transformation (as described below)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON3 Write a program to apply a 'negative' filter on a greyscale image. The program should...

    PYTHON3 Write a program to apply a 'negative' filter on a greyscale image. The program should ask the user to enter a filename, open this file, perform the transformation (as described below) and then save the negative version of the image to the file 'output.png'. To perform the negative effect, set each pixel in the output image to the opposite colour value than the corresponding pixel in the input image. For example, a colour value of 0 would become 255,...

  • in java Original: Sound Visualization Write a program that uses StdAudio and Picture to create an...

    in java Original: Sound Visualization Write a program that uses StdAudio and Picture to create an interesting two-dimensional color visualization of a sound file while it is playing. Be creative! Additional Notes: double[] data = StdAudio.read(<filename>); -> Takes a sound file and store it as a 2D array of real numbers. Picture pic = new Picture(300,200); -> Creates a picture 300 pixels wide and 200 pixels high Color c= new Color(<red>,<green>,<blue>); -> Each value of <red>, <green>, <blue> is between...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT