Programming Assignment 2 CS308 Fall 2001. Goals Improve your skills with using templates. Learn how to compile your code when using templates. Learn more.

Slides:



Advertisements
Similar presentations
Chapter 11 Separate Compilation and Namespaces. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Separate Compilation.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Programming Assignment 2 CS 302 Data Structures Dr. George Bebis.
Computational Biology, Part 23 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Chapter 10 Introduction to Arrays
Stacks CS 3358 – Data Structures. What is a stack? It is an ordered group of homogeneous items of elements. Elements are added to and removed from the.
電腦視覺 Computer and Robot Vision I Chapter2: Binary Machine Vision: Thresholding and Segmentation Instructor: Shih-Shinh Huang 1.
Programming Assignment 2 CS 308 Assignments 2&3: Build a Simple System to Recognize Coins labeled image original image quarters nickel pennies dime dollar.
Chapter 11 Separate Compilation and Namespaces Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12A Separate Compilation and Namespaces For classes this time.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
1 Pre-Exam Class CSIT121 Fall 2000 Exam-II (Final Examination) TUESDAY DECEMBER 19th 8:30AM.
1 Lab Session-XII CSIT121 Fall 2000 b Namespaces b Will This Program Compile ? b Master of Deceit b Lab Exercise 12-A b First Taste of Classes b Lab Exercise.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Programming Assignment 1 CS308 Data Structures. Goals Familiarize yourself with reading images from a file. Familiarize yourself with writing images to.
Programming Assignment 1 CS302 Data Structures. Goals Improve your skills with manipulating dynamic arrays. Improve your understanding of constructors,
Binary Image Analysis. YOU HAVE TO READ THE BOOK! reminder.
Programming Assignment 4 CS 308. Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar $1.67.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
1 CSC241: Object Oriented Programming Lecture No 07.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Data Structures Lecture-12 : STL Azhar Maqsood NUST Institute of Information Technology (NIIT)
Graph-based Segmentation. Main Ideas Convert image into a graph Vertices for the pixels Vertices for the pixels Edges between the pixels Edges between.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
CS 6825: Binary Image Processing – binary blob metrics
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Programming Assignment 4 CS 308 Fall Recognize Coins (Regions) labeled image original imagethresholded image quarters nickel pennies dime dollar.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Stacks CS 302 – Data Structures Sections 5.1, 5.2, 6.1, 6.5.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CLASSES : A DEEPER LOOK Chapter 9 Part I 1. 2 OBJECTIVES In this chapter you will learn: How to use a preprocessor wrapper to prevent multiple definition.
Computational Biology, Part 22 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
1 Regions and Binary Images Hao Jiang Computer Science Department Sept. 24, 2009.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
Nottingham Image Analysis School, 23 – 25 June NITS Image Segmentation Guoping Qiu School of Computer Science, University of Nottingham
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
CLASSES AND OBJECTS Chapter 3 : constructor, Separate files, validating data.
Graph-based Segmentation
TK1924 Program Design & Problem Solving Session 2011/2012
Histograms CSE 6363 – Machine Learning Vassilis Athitsos
C++ Templates.
Separate Compilation and Namespaces
Content-Based Image Retrieval
Content-Based Image Retrieval
Chapter 9 Classes: A Deeper Look, Part 1
Binary Image Analysis used in a variety of applications:
Introduction to Classes and Objects
More C++ Classes Systems Programming.
Classes and Objects Systems Programming.
Binary Image Analysis used in a variety of applications:
Introduction to Classes and Objects
Presentation transcript:

Programming Assignment 2 CS308 Fall 2001

Goals Improve your skills with using templates. Learn how to compile your code when using templates. Learn more about image processing. Learn to document and describe your programs.

Template the Image class Make the implementation general enough so it can handle both gray-level (PGM) and color (PPM) images. Download the code for reading/writing PPM image from the course’s webpage. template class Image { public: member functions … private: int N; // no of rows int M; // no of columns int Q; // no gray-levels PixelType **pixelVal; }; PixelType can be int or RGB

New class for color pixels Each color pixel is represented by three values: (r,g,b) struct RGB { int r; // red component int g; // green component int b; // blue component } ;

Important things to remember when using templates Your implementation should be as general as possible. Your code should not depend on gray-level/color images. If you have to use the Image class with a new type of images in the future, then you shouldn’t have to make any changes to the implementation of the class ! If you need to make changes, then your are not hiding the implementation details from the application ! This is bad programming strategy.

An example (without using templates) int Image::meanGray() { int i, j; int avg; avg = 0; for(I=0; I<N; I++) for(j=0; j<M; j++) avg = avg + pixelVal[I][j]; avg = avg / (N*M); return avg; }

An example (using templates) template PixelType Image::meanValue() { int i, j; PixelType avg; avg = 0; for(I=0; I<N; I++) for(j=0; j<M; j++) avg = avg + pixelVal[I][j]; avg = avg / (N*M); return avg; }

An example (cont’d) How does the function know how to initialize a variable of type PixelType to 0? Hoes does the function know how to add together two variables of type PixelType? How does it know how to implement assignment for PixelType variables? How does it know how to divide a variable of type PixelType by an integer?

An example (cont’d) Actually, it doesn’t until the user of the class has defined PixelType (i.e., by passing a parameter to the template) Image myGrayLevelImage; Image yourColorImage; Where does the function look for the definition of these operations? “You need to define these operations within the class RGB”

Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation should not affect the client (as long as the class’s interface has not been changed). Follow the following two principles: –Place the class declaration in a header file to be included by any client that wants to use the class (e.g., StackType.h). –Place the definition of the class member functions in a source file (e.g., StackType.cpp)

Multiple definitions When splitting a program into multiple files, the header file needs to be included in each file in which the class is used. To avoid multiple definitions of a class (or even functions), the class specification need to be enclosed in the following preprocessor code: #ifndef NAME #define NAME #endif

Multiple definitions (cont’d) #ifndef STACKTYPE_H #define STACKTYPE_H template class StackType { public: …….. void Push(ItemType); void Pop(ItemType&); private: int top; ItemType *items; }; #endif

Rules when using templates When working with templates, we change the ground rules regarding which file(s) we put the source code into. Previously (no templates) StackType.cpp could be compiled into object code independently of any client code. Using templates, the compiler cannot instantiate a function template unless it knows the argument to the template This information is found in the client code !!

Rules using templates (cont’d) Two possible solutions –Place the class definition and member function definitions into the same file (e.g., StatckType.h) –Or, give the include directive for the implementation file at the end of the header file

Rules when using templates (cont’d) template class StackType { public: …….. void Push(ItemType); void Pop(ItemType&); private: int top; ItemType *items; }; #include StatckType.cpp

Thresholding It computes a binary (black/white) image of the input.

threshold(image, thresh) Implement this as a client function (needs to be overloaded for int and RGB). Each pixel in the input image is compared against a threshold. Values greater than the threshold are set to 255, while values less than the threshold are set to 0. The same idea applies to color images (using up to three thresholds now)

Coin segmentation Separate the regions corresponding to the coins from the background. Useful for coin recognition: –collect all the pixels belonging to the same region –extract “features” useful for coin recognition

Character segmentation original thresholoded

Object counting Use up to three thresholds in this case: –a threshold for red –a threshold for green –a threshold for blue

Face segmentation originalthresholded candidate face regions

Important Issues Regarding Thresholding How to choose the threshold? How to improve the results of thresholding? How to segment specific objects only?

How to choose the threshold? originalgood threshold low threshold high threshold

displayHistogram(image) Implement this as a client function (needs to be overloaded for int and RGB). The histogram is a bar graph of the pixel value frequencies (i.e., the number of times each value occurs in the image)

displayHistogram(image) -- cont’d Use an array of counters to store the pixel frequencies. Display the histogram as another image. Draw a bar for every counter. Normalize counter values:

Face segmentation Find regions containing skin-color. In practice, we would have to estimate the skin-color distribution using statistical models and lots of images containing regions of skin-color. You will try a simpler approach here: –convert RGB values to HSV values (Hue-Saturation-Value) –threshold the HSV values

RGBtoHSV(RGB) Converts a pixel from RGB to HSV

faceThreshold(image) You should implement this as a separate client function since it is specific to face detection. This function should call RGBtoHSV first. Then, it will apply the thresholding shown below to compute a binary image (we do not use V):

How to improve the results of thresholding? In most cases, further processing is required to improve the results of thresholding. For example, some of the regions in the thresholded image might contain holes.

dilate(image) -- client If at least one neighbor is 255 if all 8 neighbors are 0

dilate(cont’d) Dilation “expands” the regions (i.e.,adds a layer of boundary pixels) originalthresholdeddilated

erode(image) -- client If all 8 neighbors are 255 if at least one neighbor is 0

erode(image) Erosion “shrinks” the regions (i.e., removes a layer of boundary pixels) originalthresholdederoded

Filling in the holes of regions Apply dilation to fill in the holes. Apply erosion to restore the size of the regions. originalthresholded dilated eroded

How to segment specific objects only? There are cases where we are interested in detecting some of the objects in the scene (e.g., just the key and the coin). Can you do this using the simple threshold function?