Image Operations Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Slides:



Advertisements
Similar presentations
CS2984: Introduction to Media Computation Drawing directly on images.
Advertisements

Digital Art and Creativity  3D Image and Animation Software  Used to make Movies  Pixar  Dreamworks  Large and Complicated Program.
My Penguin Math Book By:. I see How many penguins do you see? Count them & type the number in the box penguins.
Images Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
You can insert graphics onto your page by clicking on the Picture Frame Tool icon and then drawing a frame for your graphic. Double click in the frame.
I-SOBOT SOCCER Padmashri Gargesa Intelligent Robotics I I (Winter 2011)
First Bytes - LabVIEW. Today’s Session Introduction to LabVIEW Colors and computers Lab to create a color picker Lab to manipulate an image Visual ProgrammingImage.
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Skip Counting Counting by 2, 5, and 10.
Eleven colors and rasters. Color objects Meta represents colors with color objects You can create a color by saying: [color r g b] r: amount of red (0-255)
Working with Graphics. Objectives Understand bitmap and vector graphics Place a graphic into a frame Work with the content indicator Transform frame contents.
IMAGE PROCESSING LIBRARY (PIL) This is a package that you can import into python and it has quite a few methods that you can process image files with.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Lesson Two: Creating Sprites. What Are Sprites? Two-dimensional Image that is integrated into a larger graphics area. Sprites are everything that is visual.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
Steganography Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Color Correct and Remove Keystoning A minimalist approach to photographing your art By Paul Marley.
Creating Special Effects
Fixtures Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Studying a Reflection. Create a reflection Place the Communicator ® on top of the Transformation Grid and Chart template Locate the three vertices: A(1,0),
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
1 After completing this lesson, you will be able to: Identify the key differences between analog and digital technologies. Define digital camera terms,
Creating a Logo – Lesson 3 1 Creating a Logo Lesson 3.
Copyright 2002, Paradigm Publishing Inc. CHAPTER 14 BACKNEXTEND 14-1 LINKS TO OBJECTIVES Border Concepts Creating a Border Adding Shading Horizontal Lines.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Invasion Percolation: Assembly Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
Vector Graphics Multimedia Technology. Object Orientated Data Types Created on a computer not by sampling real world information Details are stored on.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Editing Graphics Effects and Improvements. Editing Graphics Graphics editors have features for changing the sizes of images as well as their colors and.
…and how to do stuff with them Copyright © The University of Southampton 2011 This work is licensed under the Creative Commons Attribution License See.
Processing Workshop. What is processing? “Processing is an open source programming language and environment for people who want to program images, animation,
Python Programming in Context Chapter 6. Objectives To understand pixel based image processing To use nested iteration To use and understand tuples To.
FRACTIONS & SHAPES BY:. How many of these are colored red? * out of *.
Translations Lesson 9-8.
= 5 = 2 = 4 = 3 How could I make 13 from these shapes? How could I make 19 from these shapes? STARTER.
Click on this button to move to the previous slide of your notebook. Click on this button to move to the next slide of your notebook. Click on this button.
Exceptions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
 2.3: Reflections. What is a Reflection?  Reflection or flip is a transformation in which a figure is reflected on a line called the line of reflection.
Counting Stars Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Web and Multimedia Development Copyright © Genetic Computer School 2007WM LESSON OVERVIEW  Use of Tables  Creating Tables  Try It – 1  Creating.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 5.
2.2: Translations.
Program Design Invasion Percolation: Testing
Lab 9 Intro to Robots.
Program Design Invasion Percolation: Neighbors
Chapter 5 Working with Images
Basic Graphics Drawing Shapes 1.
Skip Counting Counting by 2, 5, and 10.
Putting Images on Your Web Page
Effects and Improvements
A movement of a figure in a plane.
Skip Counting Counting by 2, 5, and 10.
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
BEGINNER PROGRAMMING LESSON
Version Control Basic Operation Copyright © Software Carpentry 2010
Version Control Introduction Copyright © Software Carpentry 2010
Digital Image Processing
Tuesday, June 22, Reflections 11.3 Reflections
A puzzule of the keV lines
Draw the new square in the space to the right.
Multimedia Summer Camp
Color Box Button - Gray Type : object Type : object Type : object
Translate 5 squares left and 4 squares up.
Fig. 4 3D reconfiguration of liquid metals for electronics.
Python – May 25 Quiz Python’s imaging library Lab
Fig. 1 Distribution of deformation and aqueous alteration in MIL
Fig. 2 Imaging blood vessel before and after closure.
Presentation transcript:

Image Operations Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information. Multimedia Programming

Image Operations Most operations built into the library

Multimedia ProgrammingImage Operations Most operations built into the library import sys from PIL import Image, ImageFilter filename = sys.argv[1] p = Image.open(filename) p.filter(ImageFilter.BLUR).save('blur-' + filename) p.filter(ImageFilter.CONTOUR).save('contour-' + filename) p.filter(ImageFilter.EMBOSS).save('emboss-' + filename) p.transpose(Image.FLIP_LEFT_RIGHT).save('flip-' + filename)

Multimedia ProgrammingImage Operations blur emboss contour flip

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations Basic image editing is mostly about coordinates original = Image.open(sys.argv[1]) x_size, y_size = original.size x_half, y_half = x_size / 2, y_size / 2 half = original.resize((x_half, y_half)) x_double, y_double = x_size * 2, y_size * 2 double = Image.new('RGB', (x_double, y_double)) for x in range(4): for y in range(4): box = (x * x_half, y * y_half, (x+1) * x_half, (y+1) * y_half) double.paste(half, box) double.save(sys.argv[2])

Multimedia ProgrammingImage Operations

Multimedia ProgrammingImage Operations Draw on images import sys from PIL import Image, ImageDraw BORDER = 10 GRAY = (128, 128, 128) pic = Image.open(sys.argv[1]) xsize, ysize = pic.size draw = ImageDraw.Draw(pic) draw.rectangle((0, 0, xsize, BORDER), fill=GRAY) draw.rectangle((0, 0, BORDER, ysize), fill=GRAY) draw.rectangle((0, ysize-BORDER, xsize, ysize), fill=GRAY) draw.rectangle((xsize-BORDER, 0, xsize, ysize), fill=GRAY) pic.save('border-' + sys.argv[1])

Multimedia ProgrammingImage Operations Draw on images import sys from PIL import Image, ImageDraw BORDER = 10 GRAY = (128, 128, 128) pic = Image.open(sys.argv[1]) xsize, ysize = pic.size draw = ImageDraw.Draw(pic) draw.rectangle((0, 0, xsize, BORDER), fill=GRAY) draw.rectangle((0, 0, BORDER, ysize), fill=GRAY) draw.rectangle((0, ysize-BORDER, xsize, ysize), fill=GRAY) draw.rectangle((xsize-BORDER, 0, xsize, ysize), fill=GRAY) pic.save('border-' + sys.argv[1])

Multimedia ProgrammingImage Operations Draw on images import sys from PIL import Image, ImageDraw BORDER = 10 GRAY = (128, 128, 128) pic = Image.open(sys.argv[1]) xsize, ysize = pic.size draw = ImageDraw.Draw(pic) draw.rectangle((0, 0, xsize, BORDER), fill=GRAY) draw.rectangle((0, 0, BORDER, ysize), fill=GRAY) draw.rectangle((0, ysize-BORDER, xsize, ysize), fill=GRAY) draw.rectangle((xsize-BORDER, 0, xsize, ysize), fill=GRAY) pic.save('border-' + sys.argv[1])

Multimedia ProgrammingImage Operations Draw on images Exercise: put frame around entire image

Multimedia ProgrammingImage Operations Work with color bands import sys from PIL import Image filename = sys.argv[1] pic = Image.open(filename) pic.load() bands = pic.split() for (i, name) in enumerate('rgb'): bands[i].save(filename.replace('.', '-%s.' % name))

Multimedia ProgrammingImage Operations Work with color bands import sys from PIL import Image filename = sys.argv[1] pic = Image.open(filename) pic.load() bands = pic.split() for (i, name) in enumerate('rgb'): bands[i].save(filename.replace('.', '-%s.' % name)) (red[], green[], blue[])

Multimedia ProgrammingImage Operations Work with color bands import sys from PIL import Image filename = sys.argv[1] pic = Image.open(filename) pic.load() bands = pic.split() for (i, name) in enumerate('rgb'): bands[i].save(filename.replace('.', '-%s.' % name)) workaround

Multimedia ProgrammingImage Operations Work with color bands redgreenblue

Multimedia ProgrammingImage Operations Use point functions to manipulate pixel values R, G, B = 0, 1, 2 SCALE = 0.5 def decrease(x): return x * SCALE pic = Image.open(sys.argv[1]) pic.load() bands = pic.split() bands = (bands[R].point(decrease), bands[G], bands[B]) more_red = Image.merge('RGB', bands) more_red.save('bluegreen-' + sys.argv[1])

Multimedia ProgrammingImage Operations Work with color bands and point functions R, G, B = 0, 1, 2 SCALE = 0.5 def decrease(x): return x * SCALE pic = Image.open(sys.argv[1]) pic.load() bands = pic.split() bands = (bands[R].point(decrease), bands[G], bands[B]) more_red = Image.merge('RGB', bands) more_red.save('bluegreen-' + sys.argv[1])

Multimedia ProgrammingImage Operations Work with color bands and point functions R, G, B = 0, 1, 2 SCALE = 0.5 def decrease(x): return x * SCALE pic = Image.open(sys.argv[1]) pic.load() bands = pic.split() bands = (bands[R].point(decrease), bands[G], bands[B]) more_red = Image.merge('RGB', bands) more_red.save('bluegreen-' + sys.argv[1])

Multimedia ProgrammingImage Operations Work with color bands and point functions R, G, B = 0, 1, 2 SCALE = 0.5 def decrease(x): return x * SCALE pic = Image.open(sys.argv[1]) pic.load() bands = pic.split() bands = (bands[R].point(decrease), bands[G], bands[B]) less_red = Image.merge('RGB', bands) less_red.save('bluegreen-' + sys.argv[1])

Multimedia ProgrammingImage Operations Less red makes the image look more blue/green

Multimedia ProgrammingImage Operations Less red makes the image look more blue/green What happens if you increase blue and green instead?

Multimedia ProgrammingImage Operations Highlight a region in an image

Multimedia ProgrammingImage Operations Highlight a region in an image Option 1: recolor the pixels

Multimedia ProgrammingImage Operations Highlight a region in an image Option 1: recolor the pixels Option 2: blend with a square of desired size –New pixel = (left pixel + right pixel) / 2

Multimedia ProgrammingImage Operations Figure out the coordinates major_x major_y highlight_x highlight_y Low x=(major_x / 2) – (highlight_x / 2) =(major_x – highlight_x) / 2 High x=(major_x / 2) + (highlight_x / 2) =(major_x + highlight_x) / 2

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations BLEND = 0.5 major_name, highlight_name = sys.argv[1:3] major, major_x, major_y = get(major_name) highlight, highlight_x, highlight_y = get(highlight_name) box = ((major_x - hl_x) / 2, (major_y - hl_y) / 2, (major_x + hl_x) / 2, (major_y + hl_y) / 2) middle = major.crop(box) middle = Image.blend(middle, highlight, BLEND) major.paste(middle, box) major.save('higlight-' + major_name)

Multimedia ProgrammingImage Operations PIL provides basic image processing

Multimedia ProgrammingImage Operations PIL provides basic image processing OpenCV ( is a complete image processing library

Multimedia ProgrammingImage Operations PIL provides basic image processing OpenCV ( is a complete image processing library Have to convert images…

Multimedia ProgrammingImage Operations PIL provides basic image processing OpenCV ( is a complete image processing library Have to convert images… …but it's worth it

November 2010 created by Greg Wilson Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information.