Python Programming in Context Chapter 6. Objectives To understand pixel based image processing To use nested iteration To use and understand tuples To.

Slides:



Advertisements
Similar presentations
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Advertisements

TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
Digital Imaging and Image Analysis
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
DIGITAL IMAGE PROCESSING CMSC 150: Lecture 14. Conventional Cameras  Entirely chemical and mechanical processes  Film: records a chemical record of.
CS 102 Computers In Context (Multimedia)‏ 02 / 06 / 2009 Instructor: Michael Eckmann.
CS 102 Computers In Context (Multimedia)‏ 02 / 18 / 2009 Instructor: Michael Eckmann.
HW 3: Problems 2&3. HW 3 Prob 2:Encipher encipher( S, n ) takes as input a string S and a non-negative integer n between 0 and 25. This function returns.
Connecting with Computer Science, 2e
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
Fundamentals of Python: From First Programs Through Data Structures
CS 102 Computers In Context (Multimedia)‏ 02 / 25 / 2009 Instructor: Michael Eckmann.
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Bitmapped Images 27 th November 2014 With Mrs
Spring  Evolving Lists & Lights On!  Caesar Cipher  Looks Good!
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
Chapter 5 Using Classes and Objects in Media Computing
COSC 1P02 Intro. to Computer Science 6.1 Cosc 1P02 Week 6 Lecture slides "To succeed, jump as quickly at opportunities as you do at conclusions." --Benjamin.
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Images Data Representation. Objectives  Understand the terms bitmap & pixel  Understand how bitmap images are stored using binary in a computer system.
Guilford County SciVis V Applying Pixel Values to Digital Images.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
COSC 1P02 Introduction to Computer Science 7.1 Cosc 1P02 Week 7 Lecture slides "There are two ways of constructing a software design; one way is to make.
Jeopardy Heading1Heading2Heading3Heading4 Heading5 Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Introduction to Image processing using processing.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Day 8: Fruit Loops: Color. Loop Review What does the following loop print? for (int i= 0; i
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
CS 102 Computers In Context (Multimedia)‏ 02 / 09 / 2009 Instructor: Michael Eckmann.
` Tracking the Eyes using a Webcam Presented by: Kwesi Ackon Kwesi Ackon Supervisor: Mr. J. Connan.
CS 101 – Sept. 14 Review Huffman code Image representation –B/W and color schemes –File size issues.
Computer Science 121 Scientific Computing Winter 2014 Chapter 14 Images.
Applying Pixel Values to Digital Images
PART TWO Electronic Color & RGB values 1. Electronic Color Computer Monitors: Use light in 3 colors to create images on the screen Monitors use RED, GREEN,
More Digital Representation Discrete information is represented in binary (PandA), and “continuous” information is made discrete.
I MAGE P ROCESSING IN CS1 Brad Miller David Ranum Luther College.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 CS 177 Week 4 Recitation Slides for Loop if statement and range.
Test 2 on Wed, 11/9 On image processing
(Project) by:- ROHAN HIMANSHU ANUP 70282
Image Processing Objectives To understand pixel based image processing
Python/JES JES IDE (Integrated Development Environment)
Spring 2010 EECS 110: Homework III.
Image Processing CS177.
Image Processing & Perception
Week 13 - Monday CS 121.
Fundamentals of Programming I Introduction to Digital Image Processing
Color Values All colors in computer images are a combination of red, green and blue Each component is encoded as a number means the color is.
Histogram Histogram is a graph that shows frequency of anything. Histograms usually have bars that represent frequency of occuring of data. Histogram has.
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Lecture 26: Lists of Lists
Multidimensional Arrays and Image Manipulation
Fundamentals of Programming I Introduction to Digital Image Processing
Spring 2015.
Python Practice !!!.
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 6
Digital Image Processing
CS 177 Week 3 Recitation Slides
Multimedia Summer Camp
Non-numeric Data Representation
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

Python Programming in Context Chapter 6

Objectives To understand pixel based image processing To use nested iteration To use and understand tuples To implement a number of image processing algorithms To understand passing functions as parameters

Digital Image Processing Editing and manipulating digital images A digital image is a collection of pixels A pixel is the smallest amount of information available in a digital picture Each pixel represents a single color Pixels are organized in a grid

RGB Color Model RGB means RED, GREEN, BLUE Each color is made up from amounts of red, green and blue Color intensities range from a minimum of 0 to a maximum of 255

cImage module Pixel ImageWin EmptyImage FileImage

Pixel objects getRed getGreen getBlue setRed setGreen setBlue

FileImage and EmptyImage getWidth getHeight getPixel setPixel draw

Negative Image Reverse the colors in each pixel

Listing 6.1 def negativePixel(oldPixel): newred = oldPixel.getRed() newgreen = oldPixel.getGreen() newblue = oldPixel.getBlue() newPixel = Pixel(newred, newgreen, newblue) return newPixel

Figure 6.1

Figure 6.2

Listing 6.2 def makeNegative(imageFile): myimagewindow = ImageWin("Image Processing",600,200) oldimage = FileImage(imageFile) oldimage.draw(myimagewindow) width = oldimage.getWidth() height = oldimage.getHeight() newim = EmptyImage(width,height) for row in range(height): for col in range(width): originalPixel = oldimage.getPixel(col,row) newPixel = negativePixel(originalPixel) newim.setPixel(col,row,newPixel) newim.setPosition(width+1,0) newim.draw(myimagewindow) myimagewindow.exitOnClick()

Figure 6.3

Figure 6.4

Grayscale Image Convert each pixel to a shade of gray Use average of RGB values

Listing 6.3 def grayPixel(oldpixel): intensitySum = oldpixel.getRed() + oldpixel.getGreen() + oldpixel.getBlue() aveRGB = intensitySum // 3 newPixel = Pixel(aveRGB,aveRGB,aveRGB) return newPixel

Listing 6.4 def makeGrayScale(imageFile): myimagewindow = ImageWin("Image Processing",600,200) oldimage = FileImage(imageFile) oldimage.draw(myimagewindow) width = oldimage.getWidth() height = oldimage.getHeight() newim = EmptyImage(width,height) for row in range(height): for col in range(width): originalPixel = oldimage.getPixel(col,row) newPixel = grayPixel(originalPixel) newim.setPixel(col,row,newPixel) newim.setPosition(width+1,0) newim.draw(myimagewindow) myimagewindow.exitOnClick()

Figure 6.5

Generalize Pixel Mapping Create a function that takes a pixel manipulation function as a parameter

Figure 6.6

Figure 6.7

Figure 6.8

Listing 6.5 def pixelMapper(oldimage,rgbFunction): width = oldimage.getWidth() height = oldimage.getHeight() newim = EmptyImage(width,height) for row in range(height): for col in range(width): originalPixel = oldimage.getPixel(col,row) newPixel = rgbFunction(originalPixel) newim.setPixel(col,row,newPixel) return newim

Listing 6.6 def generalTransform(imageFile): myimagewindow = ImageWin("Image Processing",600,200) oldimage = FileImage(imageFile) oldimage.draw(myimagewindow) newimage = pixelMapper(oldimage,grayPixel) newimage.setPosition(oldimage.getWidth()+1,0) newimage.draw(myimagewindow) myimagewindow.exitOnClick()

Namespaces Parameters, Parameter Passing, and Scope How are the names and object organized in Python Builtin Main Local

Listing 6.7 import math def hypotenuse(a,b): c = math.sqrt(a**2 + b**2) return c

Figure 6.9

Figure 6.10

Figure 6.11

Figure 6.12

Figure 6.13

Enlarging an Image Stretching an image Mapping pixels from original to enlargement

Figure 6.14

Figure 6.15

Figure 6.16

Listing 6.8 def double(oldimage): oldw = oldimage.getWidth() oldh = oldimage.getHeight() newim = EmptyImage(oldw*2,oldh*2) for row in range(oldh): for col in range(oldw): oldpixel = oldimage.getPixel(col,row) newim.setPixel(2*col,2*row,oldpixel) newim.setPixel(2*col+1,2*row,oldpixel) newim.setPixel(2*col,2*row+1,oldpixel) newim.setPixel(2*col+1,2*row+1,oldpixel) return newim

Figure 6.17

Figure 6.18

Listing 6.9 def double(oldimage): oldw = oldimage.getWidth() oldh = oldimage.getHeight() newim = EmptyImage(oldw*2,oldh*2) for row in range(newim.getHeight()): for col in range(newim.getWidth()): originalCol = col//2 originalRow = row//2 oldpixel = oldimage.getPixel(originalCol,originalRow) newim.setPixel(col,row,oldpixel) return newim

Figure 6.19

Flipping an Image Moving pixels to a new location Flip axis

Figure 6.20

Listing 6.10 def verticalFlip(oldimage): oldw = oldimage.getWidth() oldh = oldimage.getHeight() newim = EmptyImage(oldw,oldh) maxp = oldw -1 for row in range(oldh): for col in range(oldw): oldpixel = oldimage.getPixel(maxp-col,row) newim.setPixel(col,row,oldpixel) return newim

Figure 6.21

Edge Detection Convert to grayscale Look for changes from light to dark or dark to light

Figure 6.22

Figure 6.23

Figure 6.24

Listing 6.11 def convolve(anImage,pixelRow,pixelCol,kernel): kernelColumnBase = pixelCol - 1 kernelRowBase = pixelRow - 1 sum = 0 for row in range(kernelRowBase,kernelRowBase+3): for col in range(kernelColumnBase,kernelColumnBase+3): kColIndex = col-kernelColumnBase kRowIndex = row-kernelRowBase apixel = anImage.getPixel(col,row) intensity = apixel.getRed() sum = sum + intensity * kernel[kRowIndex][kColIndex] return sum

Listing 6.12 import math def edgeDetect(theImage): grayImage = pixelMapper(theImage,grayPixel) newim = EmptyImage(grayImage.getWidth(), grayImage.getHeight()) black = Pixel(0,0,0) white = Pixel(255,255,255) xMask = [ [-1,-2,-1],[0,0,0],[1,2,1] ] yMask = [ [1,0,-1],[2,0,-2],[1,0,-1] ] for row in range(1,grayImage.getHeight()-1): for col in range(1,grayImage.getWidth()-1): gx = convolve(grayImage,row,col,xMask) gy = convolve(grayImage,row,col,yMask) g = math.sqrt(gx**2 + gy**2) if g > 175: newim.setPixel(col,row,black) else: newim.setPixel(col,row,white) return newim

Figure 6.25