25
Programming Assignment 3 CS 302 - Data Structures Dr. George Bebis

Programming Assignment 3

Embed Size (px)

DESCRIPTION

Programming Assignment 3. CS 302 - Data Structures Dr. George Bebis. Goal: Represent image regions using lists and perform galaxy classification. Builds on previous two programming assignments. (1) Represent image regions in a list for easier processing. (2) Compute region features. - PowerPoint PPT Presentation

Citation preview

Page 1: Programming Assignment 3

Programming Assignment 3

CS 302 - Data Structures

Dr. George Bebis

Page 2: Programming Assignment 3

Goal: Represent image regions using lists and perform galaxy classification

• Builds on previous two programming assignments.

(1) Represent image regions in a list for easier processing.

(2) Compute region features.

Page 3: Programming Assignment 3

Project Objectives

• Improve your skills with manipulating unsorted/sorted lists

• Improve your skills with using templates

• Learn about feature extraction and classification.

Page 4: Programming Assignment 3

Region Features

• Image regions can be characterized using various features: – Geometric

– Photometric

Page 5: Programming Assignment 3

Geometric Features

• The geometry of a region can be characterized using:– Size

– Position

– Orientation

– Shape (e.g., circular,

elliptical)

• Many of these features could be computed using a family of functions called moments.

Page 6: Programming Assignment 3

Moments

• The moments of order (p,q) of a region R are:

Rji

qpqp jiM

,,

(i,j) є R

Note: moments have their roots in probability theory and are used to characterize probability density functions (pdfs).

- Mean (i.e., first order moment) - Variance (i.e., second order central moments).

Page 7: Programming Assignment 3

Region Area (i.e., size)

• The area of a region is defined by the number of pixels in the region (i.e., size).

• Can be computed using zero order moments (i.e., p=q=0) :

0,0M (i,j) є R

Rji

qpqp jiM

,,

Page 8: Programming Assignment 3

Region Center (i.e., centroid)

• The centroid of a region (i.e., center coordinates) can be computed using first order moments (p=1 or q=1):

0,0

0,1

M

Mx

0,0

1,0

M

My

Rji

qpqp jiM

,,

Page 9: Programming Assignment 3

Central Moments

• To make region descriptors invariant with respect to location, moments can be calculated with respect to the centroid of the region (i.e., central moments):

Rji

qpqp yjxi

,, )()(

Rji

qpqp jiM

,,

Page 10: Programming Assignment 3

Principal Axes

• The principal axes of a region can be used to characterize the

shape and orientation of a region.

Amin and Amax

Page 11: Programming Assignment 3

Principal Axes (cont’d)

• The principal axes, Amin and Amax, of a region can be computed using the principal moments λmin, λmax:

• The principal moments involve first and second order central moments:

21,10,22,0

22,0

20,22,00,2max 42

2

1)(

2

1

21,10,22,0

22,0

20,22,00,2min 42

2

1)(

2

1

0,0maxmax MA 0,0minmin MA

Page 12: Programming Assignment 3

Region Orientation

• The direction of the largest principal axis can be used to specify the orientation of a region:

)(tan1,1

0,2max1

Page 13: Programming Assignment 3

Region Eccentricity (i.e., Elongatedness)

• A useful measure of a region’s circularity is its eccentricity (i.e., elongatedness).

• Can be easily computed using the ratio between the principal axes:

max max

min min

Aeccentricity

A

Page 14: Programming Assignment 3

Example

Page 15: Programming Assignment 3

Photometric Properties

• Measures characterizing region intensity, for example:– Mean and median of the gray-levels.

– Minimum and maximum intensity values.

Page 16: Programming Assignment 3

Object Classification - Example

• Objects could be classified in different categories using various region properties, for example:

– Large/Small/Medium

– Elongated/Circular

Page 17: Programming Assignment 3

Represent regions in a sorted list: listOfRegions

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

listOfRegion:sorted with respectto “size”

listOfPixels:unsorted

• Nodes store info about each region (i.e., “RegionType”)• Sub-lists store the coordinates of pixels in each region - i.e., “PixelType” -- unsorted

Page 18: Programming Assignment 3

Extra credit: template lists

template<class ItemType>

struct NodeType {

ItemType info;

NodeType<ItemType>* next;

};

listOfRegions: ItemTypeshould be “RegionType”

listOfPixels: ItemType should be “PixelType”

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

you needto definethem!

This is object

composition!

Page 19: Programming Assignment 3

Extend computeComponents

int computeComponents(inputImage, outputImage, listOfRegions)

• computeComponents should return the following info:– the labeled image (same as before)

– the number of regions (same as before)

– a list of regions (new)

• Modify BFS or DFS– Use one of them in this assignment

Page 20: Programming Assignment 3

int computeComponents(inputImage, outputImage, listOfRegions)

outputImage --> whiteconnComp=0;

for (i=0; i<N; i++) for(j=0; j<M; j++) if(inputImage[i][j] == 255 && outputImage[i][j]==255) { ++connComp; label = connComp; findComponentDFS(inputImage, outputImage, i, j, label, regionregion); // or findComponentBFS(inputImage, outputImage, i, j, label, regionregion); INSERT region into “listOfRegions”INSERT region into “listOfRegions” }return connComp;

(client function)

type“RegionType”

Page 21: Programming Assignment 3

findComponentDFS(inputImage, outputImage, i, j, label, region)

Stack.MakeEmpty();

Stack.Push((i,j)); // initialize stackwhile(!Stack.IsEmpty()) { Stack.Pop((pi,pj)); INSERT (pi,pj) into “listOfPixels” of “region”INSERT (pi,pj) into “listOfPixels” of “region” outputImage[pi][pj] = label * 10; for each neighbor (ni,nj) of (pi,pj) // push neighbors if(inputImage[ni][nj] == 255 && outputImage[ni][nj] == 255) { outputImage[ni][nj] = -1; // mark this pixel Stack.Push((ni,nj)); }}COMPUTE geometric and photometric propertiesCOMPUTE geometric and photometric propertiesand populate “region” and populate “region”

type RegionType

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Page 22: Programming Assignment 3

void deleteSmallComponents(listOfRegions, threshold)

• Step through the list nodes and delete all the regions whose size is less than a user-specified threshold (e.g., 20-30 pixels).

(client function)

Hint: You would not have to visit all the nodes since the list

will be sorted from the smallest to the largest region!

“deleteSmallComponents”will be useful for debuggingyour program (i.e., keep largeregions only)

Page 23: Programming Assignment 3

Classify regions• Add a new option in the driver called “classify regions”

– Given an input image (i.e., from Image Gallery 2Image Gallery 2), your program should extract and represent the regions as described.

– Prints a summary of the regions found and their properties (e.g., position, size, orientation, eccentricity, mean intensity etc.)

– Prints min/max values of size, eccentricity, and mean intensity.

Page 24: Programming Assignment 3

Classify regions (cont’d)

• Then, your program should print the following sub-menu:

(1) display regions with size between values A and B

(2) display regions with orientation between values A and B

(3) display regions with eccentricity between A and B

(4) display regions with mean intensity between A and B

(5) back to the main menu

Page 25: Programming Assignment 3

Display your results• Traverse listOfRegionslistOfRegions

• Find the nodes satisfying the constraint chosen by the user– For each such node, traverse its listOfPixelslistOfPixels

– For each pixel, copy its original value in a new image

• Display the resulted image! original image

output image

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Geometric properties

Intensity properties

List of pixels

x,y

x,y

x,y

Example: