Compsci 101.2, Fall 2015 16.1 Plan for October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples.

Slides:



Advertisements
Similar presentations
Digital Images in Java Java’s imaging classes. Java imaging library  Java has good support for image processing  Must master a handful of classes and.
Advertisements

Container Types in Python
Sections of Ch. 12, 13, 14 Prof. V. Norman PhD, MS, BS, DDS, Esq.
Photoshop Lab colorspace A quick and easy 26 step process for enhancing your photos.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae & david streader, VUW Images and 2D Graphics COMP.
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
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.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
Moodle (Course Management Systems). Assignments 1 Assignments are a refreshingly simple method for collecting student work. They are a simple and flexible.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
Introduction. 2COMPSCI Computer Science Fundamentals.
Compsci 101.2, Fall PFTT (plan for this Thursday) l What is a Python program?  In the context of what we do in Compsci 101  In a neuroscience.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Compsci 06/101, Fall What will we do today? l Practice solving problems  Solving problems without a computer  Is this different than solving.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
1 DIG 3134 – Lecture 11: Two Dimensional Arrays And Dynamic Controls AND CONSTANTS Michael Moshell University of Central Florida Internet Software Design.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Make a blank window This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In script mode create a file.
Built-in Data Structures in Python An Introduction.
CSC1401. Learning Goals Understand at a conceptual level What is media computation? How does color vision work? How can you make colors with red, green,
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Compsci 06/101, Fall Vocabulary l What's the Spanish word for 'boy'? 'eat'?  How do you know? l What about the Turkish equivalents?  How do.
Compsci 101.2, Fall #TBT l Finish some Python concepts and questions from earlier  Review for midterm exam l Strategies for success in 101 assignments.
Compsci 101.2, Fall Plan for October l Review Catchup and Midterm and Future  Make sure everyone understand options l Review Assignment.
Compsci 101.2, Fall Plan for TDAFB (after fall break) l Hear via about plans to catch-up and stay-ahead  Profs. Rodger and Astrachan to.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Compsci 101.2, Fall Plan for FWON l Review current assignments and APTs  Review Dictionaries and how to use them  Code and APT walk-through.
Compsci 101.2, Fall Plan for 11/9 and 11/11 l Reviewing Concepts for test  Loops: index and by element  Strings, Lists, Sets, Dictionaries.
Compsci 101, Fall Plan For The Day (PFTD) l Practice solving problems  Some solved with a computer, some with Python  Differences in solving.
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
Compsci 101.2, Fall Plan for October 29 l Review dictionaries and their use  Very efficient, easy to use  Efficiency doesn't matter much for.
Review of Previous Classes Declaring Variables - var myVar:DataType = value Data Types – Number, uint, String, Boolean Functions – parameters, return.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science
Pixels, Colors and Shapes
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CSC 108H: Introduction to Computer Programming
CompSci 101 Introduction to Computer Science
CISC101 Reminders Slides have changed from those posted last night…
Topics Sequences Introduction to Lists List Slicing
Topics Sequences Introduction to Lists List Slicing
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
Python – May 25 Quiz Python’s imaging library Lab
Presentation transcript:

Compsci 101.2, Fall Plan for October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples and generators  Image processing with pixels and filters l Review problem-solving with sets, list comprehensions, and thinking  Toward reveling in APT quests and adventures

Compsci 101.2, Fall Near-term Administrivia and Due Dates l Midterm regrade:  Review rubric, ask Prof in your section l Mastery APTs for mid-term catchup  October 23 and October 30 l Programming Assignments: Four left  10/29, 11/5, 11/19, 12/3 l APTs and APT Quizzes  Quizzes: 11/2, 11/16, 11/30 (moved by one week) l Midterm exam and final  November 12, December 9 and 13

Compsci 101.2, Fall Image Processing l What's real, what's Photoshopped  from  Learn more at we'll do very basic stuff in class and lab, next assignment too!

Compsci 101.2, Fall Example: convert color to gray scale Process each pixel Convert to gray

Compsci 101.2, Fall Let's look at GrayScale.py l Key features we see  Import Image library, use API by example  Image.open creates an image object l Image functions for Image object im  im.show(), displays image on screen  im.save("xy"), saves with filename  im.copy(), returns image that's a copy  im.load(), [x,y] indexable pixel collection  im.getdata(), iterable pixel generator l Let's look at two ways to process pixels!

Compsci 101.2, Fall Image Library: open, modify, save Image.open can open most image files .png,.jpg,.gif, and more  Returns an image object, so store in variable of type Image instance  Get pixels with im.getdata() or im.load() Image.new can create a new image, specify color model "RGB" and size of image  Add pixels with im.putdata() l These belong to Image package

Compsci 101.2, Fall im.getdata(), accessing pixels l Returns something like a list  Use: for pix in im.getdata():  Generates pixels on-the-fly, can't slice or index unless you use list(im.getdata())  Structure is called a Python generator!  Saves on storing all pixels in memory if only accessed one-at-a-time l See usage in GrayScale.py, note how used in list comprehension, like a list!

Compsci 101.2, Fall Generator: Tuples and Pixels The im.getdata() function returns list- like iterable  Can use in list comprehension, see code  Use.putdata() to store again in image pixels = [makeGray(pix) for pix in im.getdata()] def makeGray(pixel): r,g,b = pixel gray = (r+g+b)/3 return (gray,gray,gray)

Compsci 101.2, Fall Making Tuples and Generators l Overuse and abuse of parentheses  To create a tuple, use parentheses  To create a generator use parentheses as though creating a list comprehension! l See this in PyDev console for pix in im.getdata(): (r,g,b) = pix npx = (255-r,255-g,255-b) [2*n for n in range(10000)] (2*n for n in range(10000))

Compsci 101.2, Fall Questions about Image Code

Compsci 101.2, Fall Example: convert blue to green Process each pixel Convert blue ones to green Is this like red-eye removal?

Compsci 101.2, Fall Making blue things green l How do we identify blue pixels?  In the blue devil image it's easy, not white  (R,G,B) triple for white? (255,255,255). So not white? l Not sure about B value, but perhaps R value is low, at least lower than 255  Let's try changing based on R < 200  See Colorme.py  l Tuples are immutable, so examine tuple  Return a new tuple, function makeGreen

Compsci 101.2, Fall Code in GrayScale.py and Colorme.py l Very similar! Loop over pixels, change each  Capture the similarity by parameterizing what changes, common way to solve-problems  Pass in the function makeGray or makeGreen  This is what happens in lab this week! See ColorAnyway.py l What's a green-screen technique?

Compsci 101.2, Fall im.load(), accessing pixels l Returns something that can be indexed [x,y]  Only useful for accessing pixels by x,y coords Object returned by im.load() is …  Use pix[x,y] to read and write pixel values l Note: this is NOT a generator pix = im.load() tup = pix[0,0] pix[1,1] = (255,255,0)

Compsci 101.2, Fall Set, List, Join, and APT Review l Sets don't contain duplicates  Simple to create from a list,.add for more  Not accessible by index, can iterate over elts  Very, very fast: x in SET, compare list l Look at WordCompositionGame APT  How to think about solving this?  mposition.html mposition.html

Compsci 101.2, Fall Can you solve this with paper/pencil? l Conceptually, in words, how to find words worth 3 points for listA player?  Describe how you determine this (English, not Python)  What about three points for player listB, listC? l How do you find words that score 2?  Can you express in terms of set operations? Like the previous example?

Compsci 101.2, Fall APT WordCompositionGame l Using sets and set operations can help  Set intersection and set union  Other set operations l A | B, set union, A & B, set intersection l B – A, set difference, B ^ A, symmetric diff

Compsci 101.2, Fall Answer Questions

Compsci 101.2, Fall Code smells you start understanding l If you wrote code to score for player listA  How to use code for player listB and listC?  Would the code fragments be similar? l Capture differences via parameters when there's lots of duplication in code  See the example in GrayScale and Colorme

Compsci 101.2, Fall APT AnagramFree l How do you know "spear" and "pears" are anagrams?  Sort the words and see if sorted form the same  What is returned by sorted("spear")?  What type is ''.join(sorted("spear"))  Can we use '' or ' ' or ':' or '|' l How do you know whether there are many words that are anagrams? Can sets help?