CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.

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
Digital Color 24-bit Color Indexed Color Image file compression
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
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.
Computer Systems Nat 4.5 Computing Science Data Representation Lesson 4: Storing Graphics EXTENSION.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
Image Processing & Perception Sec 9-11 Web Design.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
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.
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
Computer Graphics Bitmaps & Sprites CO2409 Computer Graphics Week 3.
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.
Agenda Last class: Memory, Digitizing Numbers Today: Digitizing: Text
Compsci 06/101, Fall What will you do in Compsci 6 Today? l Learn about selection and if/else statements  In context of solving problems  Understanding.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Built-in Data Structures in Python An Introduction.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Compsci 101.2, Fall Plan for October l Review Catchup and Midterm and Future  Make sure everyone understand options l Review Assignment.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
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 October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
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 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
More Digital Representation Discrete information is represented in binary (PandA), and “continuous” information is made discrete.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
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.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science
Images Data Representation.
Pixels, Colors and Shapes
CompSci 101 Introduction to Computer Science
Tuples and Lists.
CompSci 101 Introduction to Computer Science
Reading Netpbm Images.
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
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CS190/295 Programming in Python for Life Sciences: Lecture 6
Topics Sequences Introduction to Lists List Slicing
CS 177 Week 3 Recitation Slides
Computer Systems Nat 4.5 Computing Science Data Representation
CISC101 Reminders Assignment 2 due today.
Topics Sequences Introduction to Lists List Slicing
CMPT 120 Machine that can see! Lecture 21 – Unit 4 – Computer Vision
Tuple.
Introduction to Computer Science
Presentation transcript:

CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger

Announcements Reading and RQ13 due next time Assignment 5 due Thursday APT 5 due on today, APT 6 out and due after spring break This week: –Nested loops, tuples, images and more with sets

Problem: Given list of words, find word with most vowels Example: –Given [‘dog’, ‘cat’, ‘gerbil’, ‘elephant’] –‘elephant’ has 3 vowels, the most To solve – nested loops: –Loop over words in list For each word: Loop over characters in word

Bit.ly/101sp a

Problem 2 – Given two lists of names, print a list of pairs of names in which the two names are the same length A = [‘mo’,’ted’,’bill’] B = [‘billie’, ‘jes’, ‘bo’] To solve –for name in A: for name in B: Check length print pair mo, bo ted jes

bitly/101sp a

Tuples Like a list, but cannot change them –Define them with “,” (5, 7, 8) or 5, 7, 8 Use most list operations on them – they are a type of list –But immutable Examples compsci101 spring157

Example x = (4, 6, 8) y = 9, 5, 6 print x print y print x[1] print y[1] y[0] = 2 z = ([5,6], [7,8]) print z z[0][1] = 12 print z z[0].append(4) print z z[0].remove(5) z[0].remove(12) z[0].remove(4) print z compsci101 spring158

Crossword Plagiarism bit.ly/crossword from fivethirtyeight.com

Crossword Plagiarism

Puzzles with at least 25% similarity to previous puzzle since May 2003

Image Processing What's real, what's Photoshopped – from 2008http://bit.ly/1Kj0Kn6 –Learn more at we'll do very basic stuff in class and lab, next assignment too!

Example: convert color to gray scale Process each pixel Convert to gray

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

Need new concepts and Image library Red, Green, Blue color model –Triples of (R,G,B) are processed as Python tuples. –Let's study tuples! Images can be very big, what's 4K display? –4,096 x 2,160 = 8,847,360 pixels, 8Mb at least –Creating huge lists takes up memory –Sometimes only need one pixel at-a-time –Let's study generators!

Need new concepts and Image library Red, Green, Blue color model –Additive model, each pixel specified by (r,g,b) triple, values of each between – –White is (255,255,255) and Black is (0,0,0) Images stored as sequence of (r,g,b) tuples, typically with more data/information too –256 values, represented as 8 bits, 2 8 = 256 –32 bits per pixel (with alpha channel) –In Python we can largely ignore these details!

Image library: Two ways to get pixels Each pixel is a tuple in both models –Like a list, indexable, but immutable –pix = (255,0,0) What is pix?, pix[0]? What is pix[5] ? Invert a pixel: by subscript or named tuple –Access by assignment to variables! npx = (255-pix[0],255-pix[1],255-pix[2]) (r,g,b) = pix npx = (255-r,255-g,255-b)

Let's look at GrayScale.py Key features we see –Import Image library, use API by example –Image.open creates an image object 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 collection Let's look at two ways to process pixels!

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() These belong to Image package

im.getdata(), accessing pixels 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 See usage in GrayScale.py, note how used in list comprehension, like a list!

Alternate : Still 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)

Making Tuples and Generators Overuse and abuse of parentheses –To create a tuple, use parentheses –To create a generator use parentheses as though creating a list comprehension! 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))

Questions about Image Code bit.ly/101sp

im.load(), accessing pixels 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 Note: this is NOT a generator pix = im.load() tup = pix[0,0] pix[1,1] = (255,255,0)

Lab 7 You’ll create new images –Invert –Solarize –Darken –Brighten –etc