You Know More Than You Think ;) 3/6/18 Matni, CS8, Wi18 1

Similar documents
Image Representation and Processing

Combinatorial Logic Design Multiplexers and ALUs CS 64: Computer Organization and Design Logic Lecture #14

4/9/2015. Simple Graphics and Image Processing. Simple Graphics. Overview of Turtle Graphics (continued) Overview of Turtle Graphics

CS101 Lecture 19: Digital Images. John Magee 18 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Lecture #2: Digital Images

Digital Images: A Technical Introduction

MOTION GRAPHICS BITE 3623

Section 1. Adobe Photoshop Elements 15

What You ll Learn Today

Computer Graphics Si Lu Fall /25/2017

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

CS 100 Introduction to Computer Science Solutions to Final Sample Questions, Fall 2015

DSP First Lab 06: Digital Images: A/D and D/A

CS 100 Introduction to Computer Science Final Sample Questions, Fall 2015

INTRODUCTION TO COMPUTER GRAPHICS

Specific structure or arrangement of data code stored as a computer file.

Digital Images. Digital Images. Digital Images fall into two main categories

Graphics for Web. Desain Web Sistem Informasi PTIIK UB

CS 262 Lecture 01: Digital Images and Video. John Magee Some material copyright Jones and Bartlett

RGB COLORS. Connecting with Computer Science cs.ubc.ca/~hoos/cpsc101

Unit 4.4 Representing Images

OSA Sponsorship Order Form

Objective Explain design concepts used to create digital graphics.

1. Describe how a graphic would be stored in memory using a bit-mapped graphics package.

ADOBE PHOTOSHOP CS 3 QUICK REFERENCE

1. Using Images on Web Pages 2. Image Formats 3. Bitmap Image Formats

Section 7: Using the Epilog Print Driver

PENGENALAN TEKNIK TELEKOMUNIKASI CLO

Finite State Machines CS 64: Computer Organization and Design Logic Lecture #16

ITP 140 Mobile App Technologies. Images

Activity Graphics: Image Processing

Sampling Rate = Resolution Quantization Level = Color Depth = Bit Depth = Number of Colors

Lab S-4: Convolution & FIR Filters. Please read through the information below prior to attending your lab.

Indexed Color. A browser may support only a certain number of specific colors, creating a palette from which to choose

Positive & Negative Space = the area around or between a design. Asymmetrical = balanced but one part is small and one part is large

Mathematics Success Grade 8

Photoshop 01. Introduction to Computer Graphics UIC / AA/ AD / AD 205 / F05/ Sauter.../documents/photoshop_01.pdf

Digital Imaging & Photoshop

Digital Imaging - Photoshop

CMPSC 390 Visual Computing Spring 2014 Bob Roos Review Notes Introduction and PixelMath

This assignment is worth 75 points and is due on the crashwhite.polytechnic.org server at 23:59:59 on the date given in class.

ADOBE 9A Adobe Photoshop CS3 ACE.

Modifying pictures with loops

Session 1. by Shahid Farid

BRUSHES AND LAYERS We will learn how to use brushes and illustration tools to make a simple composition. Introduction to using layers.

PB Works e-portfolio Optimizing Photographs using Paintshop Pro 9

Adobe Fireworks CS4 Kalamazoo Valley Community College February 25, 2010

Image Optimization for Print and Web

CPSC 217 Assignment 3

Photoshop 1. click Create.

Computer Graphics and Image Editing Software

Prof. Feng Liu. Fall /02/2018

MEM455/800 Robotics II/Advance Robotics Winter 2009

CS101 Lecture 12: Digital Images. What You ll Learn Today

Corporate Logo Guidelines

Computer Graphics (CS/ECE 545) Lecture 7: Morphology (Part 2) & Regions in Binary Images (Part 1)

Computer Graphics. Si Lu. Fall er_graphics.htm 10/02/2015

Output Model. Coordinate Systems. A picture is worth a thousand words (and let s not forget about sound) Device coordinates Physical coordinates

Computing for Engineers in Python

EXHIBIT. Call or Visit

Adobe Photoshop CS5 Tutorial

CSE1710. Big Picture. Reminder

Working with Photos. Lesson 7 / Draft 20 Sept 2003

Chapter 7 Image Processing

General Checklist: How To Use Our Templates: How To Outline Fonts: How To Embed Images: Custom Order Artwork Specs SETTING UP PDF PRINT FILES

CS 51 Homework Laboratory # 7

Homework 7: Subsets Due: 10:00 PM, Oct 24, 2017

Programming Languages and Techniques Homework 3

6. Graphics MULTIMEDIA & GRAPHICS 10/12/2016 CHAPTER. Graphics covers wide range of pictorial representations. Uses for computer graphics include:

Adobe Illustrator CS6

Tutorial Version 5.1.xx March 2016 John Champlain and Jeff Woodcock

IMAGE SIZING AND RESOLUTION. MyGraphicsLab: Adobe Photoshop CS6 ACA Certification Preparation for Visual Communication

7.0 - MAKING A PEN FIXTURE FOR ENGRAVING PENS

Tutorial 1 is an introduction to vector software and assumes no previous knowledge of vector-based

Application Notes Textile Functions

Vector VS Pixels Introduction to Adobe Photoshop

Exercise NMCGJ: Image Processing

Math 3012 Applied Combinatorics Lecture 2

II. Basic Concepts in Display Systems

The Problem. Tom Davis December 19, 2016

A raster image uses a grid of individual pixels where each pixel can be a different color or shade. Raster images are composed of pixels.

Photoshop Domain 2: Identifying Design Elements When Preparing Images

Cards: Virtual Playing Cards Library

Photoshop CS6. Table of Contents. Image Formats! 3. GIF (Graphics Interchange Format)! 3. JPEG or JPG (Joint Photographic Experts Group)!

Image Forgery. Forgery Detection Using Wavelets

QUICKSTART COURSE - MODULE 7 PART 3

Dr. Shahanawaj Ahamad. Dr. S.Ahamad, SWE-423, Unit-06

Prof. Feng Liu. Winter /09/2017

Lab P-8: Digital Images: A/D and D/A

Announcements 9 Dec 2014

Bit Depth. Introduction

Picture Encoding and Manipulation. We perceive light different from how it actually is

MATLAB Image Processing Toolbox

Elements of Design. Basic Concepts

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

Inserting and Creating ImagesChapter1:

Photoshop (Image Processing)

Final Project: Reversi

WordPress Users Group Manchester, NH July 13, Preparing Images for the Web. Daryl Johnson SvenGrafik

In the following sections, if you are using a Mac, then in the instructions below, replace the words Ctrl Key with the Command (Cmd) Key.

Transcription:

You Know More Than You Think ;) 3/6/18 Matni, CS8, Wi18 1

Digital Images in Python While Loops CS 8: Introduction to Computer Science, Winter 2018 Lecture #13 Ziad Matni Dept. of Computer Science, UCSB

Administrative Homework #7 is due ON MONDAY 3/12 Lab #5 due ON FRIDAY 3/9 (EXTENDED) Remaining on the calendar This supersedes anything on the syllabus DATE TOPIC ASSIGNED DUE Mon. 3/5 Wed. 3/7 File I/O ; Formats for Outputs Digital Images ; While-Loops Hw #7 Lab #5 Mon. 3/12 Recursive Functions Hw #8 Wed. 3/14 Review for the Final Exam Lab #6 Hw #6 Lab #5 Hw #7, Hw #8 Lab #6 Proj #2 3/6/18 Matni, CS8, Wi18 3

Lecture Outline Chapter 6 Digital Images on Computers Indexed Color Schemes The cimage Module While-Loops 3/6/18 Matni, CS8, Wi18 4

Starting Chapter 6 Digital Images on Computers Two types of images: raster vs. vector Raster (a.k.a bit-map ) images Most picture formats from photos, paint/shop programs Typically JPEG (.jpg,.jpeg) types Made of a finite number of pixels (or dots) Quality of picture is measured in dots per inch (dpi) Close-ups look blurry or pixelated The higher the resolution, the more pixels are needed More pixels mean larger file sizes to store the image Raster images are a great choice for photographic pictures 3/6/18 Matni, CS8, Wi18 5

JPEG Example with Different Quality Settings Lower dpi Higher dpi 3/6/18 6

Digital Images on Computers Vector (a.k.a object-based ) images Most picture formats that come from drawing programs Typically SVG (.svg) types Not pixel representation uses mathematical formulae to represent shapes Close-ups or pull-backs look smooth and clean Resolution is always good File size is constant (usually small) Great for logos, simple representations of real objects Isn t very good for exact photographic representations 3/6/18 Matni, CS8, Wi18 7

Examples of Raster vs Vector Raster (bit-map) Vector 3/6/18 Matni, CS8, Wi18 8

Same Examples (zoomed in) Raster (bit-map) Vector Shows pixilation Shows perfect reproduction 3/6/18 Matni, CS8, Wi18 9

Indexed Colors in Images Colors on a monitor are represented by the RGB scheme 256 variations on each of Red, Green, and Blue palates Mixing gives a full palate of colors (per projected, not reflected light) Giving you a combination of over 16 million colors Are there more than 16 million colors in the real world? 3/6/18 Matni, CS8, Wi18 10

Indexed Colors in Images Q: Are there more than 16 million colors in the real world? A: Yes! (well, probably, not that I can tell :\) A fixed scheme, like RGB, is necessary because: 1. It puts an upper limit (on colors, on file sizes, on time to render pictures onto a screen, etc ) 2. It accommodates display technologies (they re really advanced, but they re not limitless in their capabilities!) 3. It is good enough for 99.99% of computer (esp. Web) users! 3/6/18 Matni, CS8, Wi18 11

The RGB Scale 256 settings for Red è 8 bits (why?) 256 settings for Green è 8 bits 256 settings for Blue è 8 bits 1 bit = 2 combinations (0 or 1) 2 bits = 4 combinations (00, 01, 10, or 11) N bits = 2 N combinations RGB has 24 bits (8 for each R,G,B) to use to define a color 2 24 is approximately 16 million 3/6/18 Matni, CS8, Wi18 12

3/6/18 Matni, CS8, Wi18 13

The number of bits used to describe a color pallet exponentially raises the number of colors used in a computer graphic 1 BIT 2 BITS 4 BITS 16 BITS 24 BITS Wikipedia.com

Image Processing with the cimage Module Textbook s cimage module processes raster data Designed to work with.gif and.ppm formats only Can install a library for.jpg format, but not available in lab Chapter 6 uses objects of the module s Pixel, FileImage, EmptyImage and ImageWin classes 3/6/18 Matni, CS8, Wi18 15

Using cimage Import cimage like this: from cimage import * This allows you to use cimage methods/functions without having to say cimage. first Example: Instead of: im = cimage.fileimage( x.jpg ), you could just say: im = FileImage( x.jpg ) 3/6/18 Matni, CS8, Wi18 16

Construct a Window To construct a window, use this: title = "My Picture" width = 300 # units is pixels height = 300 # units is pixels mywin = ImageWin(title, width, height) 3/6/18 Matni, CS8, Wi18 17

3/6/18 Matni, CS8, Wi18 18

3/6/18 Matni, CS8, Wi18 19

A Pixel class A way to manage the color of one pixel A color = amounts of (red, green, blue) When coded by the RGB color model Range of each part: 0 to 255 whitepixel = cimage.pixel(255,255,255) blackpixel = cimage.pixel(0,0,0) purplepixel = cimage.pixel(255,0,255) yellowpixel = cimage.pixel(255,255,0) The mixes don t always work like, say, mixing paints do Methods: getred(), setblue(value), some others 3/6/18 Matni, CS8, Wi18 20

Image Classes in cimage: EmptyImage and FileImage Create a new (empty) image with dimensions: Create new: img = EmptyImage(cols, rows) Use an existing image to get Or use existing: img = FileImage(filename) # Careful of where the file is How to manage a set of pixels, organized by rows and columns x denotes the column leftmost x is 0 y denotes the row topmost y is 0 Methods: getwidth(), getheight(), getpixel(x, y), setpixel(x, y, pixel), save(filename), and draw(window) 3/6/18 Matni, CS8, Wi18 21

ImageWin class A window frame that displays itself on-screen window = cimage.imagewin(title, width, height) image.draw(window) Mostly just used to hold (new or existing) images, but also has some methods of its own e.g., getmouse() returns (x,y) tuple where mouse is clicked (in window, not necessarily same as image) exitonclick() closes window and exits program on mouse click 3/6/18 Matni, CS8, Wi18 22

Demo! from cimage import * im = FileImage('./leo.gif') # load an existing image title = "My Friend Leo" width = 600 # units is pixels height = 600 # units is pixels mywin = ImageWin(title, width, height) # Define mywin im.draw(mywin) # Draws the image in mywin im.getwidth() im.getheight() # Report on the height of the existing image # Report on the width of the existing image whitepix = Pixel(255,255,255) im.setpixel(150, 100, Pixel(255,255,255)) for x in range(500): im.setpixel(x, 100, whitepix) im.setpixel(150, x, whitepix) 3/6/18 Matni, CS8, Wi18 23

Negative Images & Grayscale Negative images flip each pixel color for row in range(height): for col in range(width): # get r, g, b from old image here negpixel = Pixel(255 - r, 255 - g, 255 - b) newimage.setpixel(col, row, negpixel) Listings 6.1 and 6.2 in textbook negimage.py Grayscale similar (Listings 6.3 and 6.4): #... as above through get r, g, b avg = (r + g + b) // 3 graypixel = Pixel(avg,avg,avg) Listings 6.3 and 6.4 grayimage.py 3/6/18 Matni, CS8, Wi18 24

3/6/18 Matni, CS8, Wi18 25

Flow of an Iteration Structure Start here EXAMPLE: for x in range(1, 10): print (x) Ask: Is this condition True? F? T Do something Ask: is 1 <= x < 10? If True, the do the following: print x, then make x = x + 1 Quit the loop If False, then quit the loop 3/6/18 Matni, CS8, Wi18 26

Review: 3 Control Structure Types Sequence Selection If-else statements? T Iteration Loops F? T F? T F 3/6/18 Matni, CS8, Wi18 27

Repetition with a while loop while condition: # executes over and over until a condition is False Used for indefinite iteration When it isn t possible to predict how many times a loop needs to execute, unlike with for loops We use for loops for definite iteration (e.g., the loop executes exactly n times) 3/6/18 Matni, CS8, Wi18 28

Applying while Can be used for counter-controlled loops: n = 500 counter = 0 # (1) initialize while counter < n: # (2) check condition print(counter * counter) counter = counter + 1 # (3) change state But NOTE that this is a definite loop easier to use for loop 3/6/18 Matni, CS8, Wi18 29

Repetition with a while loop While loops won t run at all if condition starts out as false While loops run forever if condition never becomes false (i.e. if it always stays true) 3/6/18 Matni, CS8, Wi18 30

Applying while Better application example unlimited data entry: # (1) initialize AllGrades = 0 grade = input("enter grade or q to quit: ") # (2) check condition while grade!= "q": # process grade here, then get next one AllGrades = AllGrades + int(grades) # (3) change states grade = input("enter grade or q to quit: ") # While loop has ended, now do other stuff print("you're all done now!") 3/6/18 Matni, CS8, Wi18 31

Top-Design of Programs: Step 1 Think of the simplest flowchart for your problem and think of the big picture Very general; top-level algorithm Example: I want to print all numbers between 1 and 100 Notice: just one rectangle in representation 3/6/18 Matni, CS8, Wi18 32

Step 2: Replace Any Rectangle By Two Rectangles In Sequence Step 2 This stacking rule can apply repeatedly For example: 1. Get data 2. Process 3. Show results 3/6/18 Matni, CS8, Wi18 33

Step 3: Replace Any Rectangle By Any Control Structure Step 3 if, if/else, for, while This nesting rule also applies repeatedly each control structure has its own rectangles e.g., nest a while loop in an if structure: if n > 0: while i < n: print(i) i = i + 1 3/6/18 Matni, CS8, Wi18 34

Step 4: Apply Steps #2 And #3 Repeatedly, And In Any Order Stack, nest, stack, nest, nest, stack, gets more and more detailed as one proceeds Think of control structures as building blocks that can be combined in two ways only. Overall process is known as top-down design by stepwise refinement Fact: any algorithm can be written as a combination of sequence, selection, and iteration structures. 3/6/18 Matni, CS8, Wi18 35

3/6/18 Matni, CS8, Wi18 36