CPSC 535 Assignment 1: Introduction to Matlab and Octave

Similar documents
Exercises: Instructions and Advice

GNU OCTAVE BEGINNER'S GUIDE BY JESPER SCHMIDT HANSEN DOWNLOAD EBOOK : GNU OCTAVE BEGINNER'S GUIDE BY JESPER SCHMIDT HANSEN PDF

Image Compression With Haar Discrete Wavelet Transform

Getting started with MATLAB

n! = 1 * 2 * 3 * 4 * * (n-1) * n

Why Use Graphs? Test Grade. Time Sleeping (Hrs) Time Sleeping (Hrs) Test Grade

Image Manipulation in MATLAB Due Monday, July 17 at 5:00 PM

Table of Laplace Transforms

APPM 2360 Project 2 Due Nov. 3 at 5:00 PM in D2L

Relationship between Fourier Space and Image Space. Academic Resource Center

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Fourier Transforms and Signal Analysis

MATH STUDENT BOOK. 12th Grade Unit 4

Programming Exercise 1: Linear Regression

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss

Mathematics and Symmetry: A Bridge to Understanding

Curriculum Map: Mathematics

CSE 547: Machine Learning for Big Data Spring Problem Set 2. Please read the homework submission policies.

Mathematics 350 Section 6.3 Introduction to Fractals

EE 301 Lab 1 Introduction to MATLAB

AREA Judo Math Inc.

7 Control Structures, Logical Statements

A quick Matlab tutorial

Vocabulary: Bits and Pieces II

CS1114 Section 8: The Fourier Transform March 13th, 2013

Measuring Parts of Units, Fraction Arithmetic with ½!! Mathematical Understandings

Figure 1. Figure 2. The BOOTSTRAP

Lab 1: Elementary image operations

Bar Graphs and Dot Plots

AMS 27L LAB #2 Winter 2009

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

Fractals: Self-Similarity and Fractal Dimension Math 198, Spring 2013

Here is the probability distribution of the errors (i.e. the magnitude of the errorbars):

Appendix E: Software

Topic C. Communicating the Precision of Measured Numbers

Lossy Compression of Scientific Data with Wavelet Transforms

Making Science Graphs and Interpreting Data

Machine Problem 8 - Mean Field Inference on Boltzman Machine

RECURSION 7. 1 Recursion COMPUTER SCIENCE 61A. October 15, 2012

LARP / 2018 ACK : 1. Linear Algebra and Its Applications - Gilbert Strang 2. Autar Kaw, Transforming Numerical Methods Education for STEM Graduates

MATLAB/Octave Tutorial

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

I. This material refers to mathematical methods designed for facilitating calculations in matrix

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

General Instructions. Questions

6.001 Notes: Section 8.1

Optimised corrections for finite-difference modelling in two dimensions

The Cascading Haar Wavelet algorithm for computing the Walsh-Hadamard Transform

Grade 6 Math Circles. Spatial and Visual Thinking

1. Let n be a positive number. a. When we divide a decimal number, n, by 10, how are the numeral and the quotient related?

Dynamics and Vibrations Mupad tutorial

Math Fundamentals for Statistics (Math 52) Unit 3: Addition and Subtraction. Scott Fallstrom and Brent Pickett The How and Whys Guys.

Algebra 2 Semester 1 (#2221)

Matlab Introduction. Scalar Variables and Arithmetic Operators

[1] CURVE FITTING WITH EXCEL

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

6.001 Notes: Section 4.1

Implementation of Integer-Based Wavelets Using Java Servlets

Math 3820 Project. 1 Typeset or handwritten? Guidelines

AMS 148: Chapter 1: What is Parallelization

8.4 Graphs of Sine and Cosine Functions Additional Material to Assist in Graphing Trig Functions

Survey of the Mathematics of Big Data

1 Introduction to Matlab

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Equations of planes in

Edge Detections Using Box Spline Tight Frames

Practice Exam Sample Solutions

Discovering. Algebra. An Investigative Approach. Condensed Lessons for Make-up Work

HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression

Application of Daubechies Wavelets for Image Compression

In this lesson, students build fractals and track the growth of fractal measurements using tables and equations. Enduring Understanding

(Refer Slide Time 04:53)

Madison County Schools Suggested 4 th Grade Math Pacing Guide

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

STAT 20060: Statistics for Engineers. Statistical Programming with R

Transformations. Write three rules based on what you figured out above: To reflect across the y-axis. (x,y) To reflect across y=x.

!"!!!"!!"!! = 10!!!!!(!!) = 10! = 1,000,000

LAB 2 VECTORS AND MATRICES

A Brief Introduction to Matlab for Econometrics Simulations. Greg Fischer MIT February 2006

Mississippi College and Career Readiness Standards for Mathematics Scaffolding Document. Grade 4

Teaching Math thru Big Ideas Focusing on Differentiation. Marian Small April 2017 San Diego, CA

Lab # 2 - ACS I Part I - DATA COMPRESSION in IMAGE PROCESSING using SVD

School District of Marshfield Mathematics Standards

Course: Programming 101 Introduction to Python. CIP Course Title / Code: Computer Programming / Duration: Part one of a two-semester series

Chapter 4: Linear Relations

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

MERGING POINT CLOUDS FROM MULTIPLE KINECTS. Nishant Rai 13th July, 2016 CARIS Lab University of British Columbia

Graduate Topics in Biophysical Chemistry CH Assignment 0 (Programming Assignment) Due Monday, March 19

Answer Key Lesson 5: Area Problems

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

CoE4TN3 Image Processing. Wavelet and Multiresolution Processing. Image Pyramids. Image pyramids. Introduction. Multiresolution.

Curriculum Connections (Fractions): K-8 found at under Planning Supports

CITS2401 Computer Analysis & Visualisation

USING LINEAR FUNCTIONS TO MODEL MATH IDEAS

System Design S.CS301

Linear algebra deals with matrixes: two-dimensional arrays of values. Here s a matrix: [ x + 5y + 7z 9x + 3y + 11z

Inf2B assignment 2. Natural images classification. Hiroshi Shimodaira and Pol Moreno. Submission due: 4pm, Wednesday 30 March 2016.

Transcription:

CPSC 535 Assignment 1: Introduction to Matlab and Octave The goal of this assignment is to become familiar with Matlab and Octave as tools for scientific investigation. Matlab, a product of Mathworks, is an interpreted language whose singular feature is that its basic data type is an array. Even a scalar value in Matlab is represented as a 1 1 array. This feature reduces the lines of code required to implement many numerical algorithms and thus makes scientific programming easier (and more fun). Matlab also features an extensive function library of numerical algorithms to solve most common problems and some that are not so common. Octave is a program that imitates Matlab and is distributed under the Gnu Public License (see www.gnu.org). This means Octave is free. Octave development is generally a few versions behind Matlab and does not have many of the new features in the latest version of Matlab. Also, Octave libraries are not as extensive as those for Matlab. Still, its price makes it attractive and we can use it to learn about computer vision. This assignment takes you through several examples that show how Matlab/Octave style programming can really save you a great deal of time and effort for certain kinds of programming: time that you will hopefully save on the other assignments for this course. As such, code-efficiency is a large component of this assignment. Parallelise your code and do array operations whenever possible. AVOID FOR LOOPS AT ALL COSTS. The results are quite astounding: for example, in previous years, some part-2 submissions took more than 20 minutes to compute, while the TA s version takes less than 0.5s. There are three pieces to this assignment: the cornsweet effect, a fractal Koch curve, Haar wavelets. The fractal concepts are taken from Smith [4]. Haar wavelets are described in detail in [1, 2]. Purves et al. [3] describe the Cornsweet effect. Note that this assignment describes tasks in mathematical terms throughout. It is up to you to translate the mathematics into efficient Octave code. Furthermore, you can treat some of this as a mathematical review. The Haar wavelets in particular leverage linear algebra, skills you will need for the rest of the course. 1 Warming up with Images Since this is a computer vision course it is necessary to acquire and display images. In this part of the assignment you will create an image that illustrates the Cornsweet effect. I highly recommend researching this effect on the internet, as in the past students often hand-in incorrect results that are easy to fix. Write an Octave script to do the following: 1. create a row vector of 50 elements using the following equation { 0 i 25 x i = ( i 25 25 )2 i > 25 2. from the previous step, build a 100-element row vector in which the first 50 elements are the x i and the second 50 elements are the x i negated and in reverse order. 3. create an array that consists of 50 duplicate rows, each identical to the 100-element row vector. Display this array as an image using a 256-value gray scale. Use the colormap and image commands to do this. Hand in your script and a copy of the resulting image.

(a) (b) Figure 1: Construction of Koch (or snowflake) curves. 2 The Koch Curve The Koch curve, also known as the snowflake curve, appears often in computer science instruction because it makes pretty pictures while demonstrating concepts in recursion. Figure 1(a) shows pictorially how to construct Koch curves. To move from K n to K n+1, take each straight line segement in K n, divide it into thirds, and replace the middle section with two segments one third of the length of the original segment. To aid the implementation of Koch curve computations consider Figure 1(b). Suppose X 0 and X 1 are segment end points on K n. Then X 0, X 1, X 2, X 3, and X 4 are all segment end points on K n+1. If X i = (x i, y i ), then X 2 = 2 3 X 0 + 1 3 X 1 X 3 = 1 2 X 0 + 1 2 X 1 + X 4 = 1 3 X 0 + 2 3 X 1 3 6 (y 0 y 1, x 1 x 0 ) Write an Octave function called koch that computes K n+1 from K n. Put this in its own koch.m file; you can find details on this on-line in the octave or Matlab documentation. I recommend that you represent the curves as an array with two columns. Each row in the array will correspond to a segment end point with the x-coordinate in the first column and y-coordinate in the second column. If you order the end point correctly, this representation will allow you to plot the Koch curves easily using the plot command. You can save this plot to disk using the print command. e.g., print -dpng foo.png after showing a plot to screen. Write a script that generates K 10 and plots it. For K 0 use a line segment from (0, 0) to (1, 0). For this section hand in your code for koch, the script, and your plot of K 10. 3 Haar Wavelets Part 1 Wavelets are tools that aid in frequency analysis by dividing a given function or signal into different frequency components. You will learn more about frequency analysis later in the course. For now, given a set of data, visualise the high-frequency data as the rapid changes, or detail, of the data. The low-frequency data is the slow changes, or the general trend, of the data. In Figure 2(a), the low-frequency data is the general shape of the sine curve. The high-frequency detail is the noise, or the fuzz on the sine curve. The Haar wavelet is the simplest possible wavelet and splits data into its high and low frequency components. A single application of Haar decomposition does a frequency cut at f/2 where f is the frequency of the original data. Using Figure 2, notice that there are 1024 samples of data in Figure 2(a). After one Haar decomposition, the

(a) (b) Figure 2: Haar decomposition of a noisy sine curve: (a) a noisy sine curve, and (b) the first Haar decomposition (resulting curve is on the left, the detail data is on the right). sine curve in Figure 2(b) has half the data points (half the frequency) at 512, and also has 512 points of the removed high-frequency data. k successive applications, then, does a frequency cut at f/2 k. The Haar wavelet is a very simple operation that works on pairs of the input discrete data (for continuous data, this works on windows, or regions). The low-frequency component is the average of the two samples and the highfrequency component is half the difference. That is: ψ(t) = φ(t) = f(2t 1) + f(2t) 2 f(2t 1) f(2t) 2 Where ψ(t) is the low-frequency data and φ(t) is the high-frequency data. To reconstruct the data, { ψ( t+1 t+1 f(t) = 2 ) + φ( 2 ) t odd ψ( t 2 ) φ( t 2 ) t even In this assignment, you will be removing the high-frequency noise from the sine curve and will add the noise to a cosine curve. First, generate a noisy sine curve with 1024 samples using the octave command sin(0:2*pi/(1024-1):2*pi)+randn(1,1024)/10 then do five consecutive Haar decompositions, resulting in a high-frequency cutoff at f/2 5, meaning the low-frequency data will only have 32 data points. For each consecutive iteration only operate on the remaining low-frequency data. Plot the resulting data in a similar fashion to Figure 2(b) (32-data-point sine + 992 data points of detail) and attach it to your assignment. Take special notice how the detail changes on each iteration. Following, apply this high-frequency data to a cosine curve. Start with a 32-data-point cosine curve and do a five-level haar composition using the detail extracted from your noisy sine. Plot the result and hand it in with your assignment. HINT: This entire question (Haar) can be done using linear algebra. Setup the pair-wise decomposition as a matrix operation, with the data being a vector. Multiplying the data vector by this matrix will perform a haar decomposition of the entire dataset in a single operation. For successive decompositions, work on a subset of the data, leaving the previously-removed detail untouched. If you manage this, then your five Haar decomposition matrices can be multiplied together, and then applied to your data in one step! Further, you can do the inverse (recomposition) by using the inverse of this matrix (inv(matrix)) for free. If you instead do this with for loops, it is much more work and computation will take much longer. For this section hand in all plots as specified above and all code.

Part 2: Moving to Images Haar decomposition on images provides several gains including progressive resolution zoom and advantages in compression techniques. Moving from the 1D case in Part 1 to the 2D case is actually quite simple: 1. Do 1D decompositions on each row of the image data. 2. Following, do 1D decompositions on each column of the resulting data. Note that this step and the previous one can be reversed. The result of this is that you get a low-frequency version of the image separated from large amounts of detail. Please do a 3-level haar decomposition on the attached cat.png file (you can choose your own image, but be careful that the image size has a factor of 2 3 to allow for even decomposition). For this section, hand in your code and the resulting image, and answer the following questions: What does the removed high-frequency data look like? What is the range, min, max, and how does this affect how it looks when you draw it with image? Discuss how Haar decomposition can be useful for image compression. What are the limits of Haar decomposition? Why and when would you decompose to this limit? HINT: Don t over-complicate this. Part 2 is a trivial (one line) extension over Part 1 once the image is loaded. Again, think of this in terms of linear algebra operations. Further, use the pngload.m script provided on the professor s website to get the image data loaded and use the double function to cast the data to the double datatype for use in your operations. Fast Octave Code The Octave manual contains several tips for writing fast Octave programs. I recommend that you read it. The biggest problem that I have observed when students learn Octave is that they tend to rely on their C/C++ knowledge too much. If you write in Octave by translating from C/C++ directly into Octave, it is likely that your program will be painfully slow. When marking assignments in the past I have been able to tell with a second or two of starting a students program whether or not they have grasped Octave. The difference in execution speed is very obvious, and your resulting mark will reflect this. Hand In Hard copy and electronic copy (email to TA): 1. Cover sheet with your name, course number, and assignment number only. 2. Name and student ID number inside the cover sheet. 3. All plots, images, and source code. Make sure you label the plots to indicate what they are. Marking Assignment grades will be based on 1. the correctness of the plots and images, and 2. the quality and depth of your written answers, and 3. the quality of your Octave code. Your code should be correct, readable, well-documented, and modular. Octave and Matlab are not very readable languages, but you should still be able to produce good-quality code that is maintainable.

Collaboration The assignment must be done individually so everything that you hand in must be your original work, except for the code copied from a cited source or that supplied by your instructor. When someone else s code is used like this, you must acknowledge the source explicitly. Copying work that is not your own without acknowledgement is academic misconduct. Contact your instructor if you have problems or questions regarding this. References [1] Charles K. Chui. An Introduction to Wavelets. Academic Press, San Diego, US, 1992. [2] A. Haar. Zur theorie der orthogonalen funktionensysteme. Mathematische Annalen, 69:331 371, 1910. [3] D. Purves, R. B. Lotto, and S. Nundy. Why we see what we do. American Scientist, 90(3):236 243, 2002. [4] P. Smith. Explaining Chaos. Cambridge University Press, Cambridge, UK, 1998.