Gavin S Page OpenCV Tutorial Part II Loading Images and Using Histograms 29 November 2005.

Slides:



Advertisements
Similar presentations
Variables and Operators
Advertisements

Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin TECHNOLOGY PLUG-IN T2 BASIC SKILLS USING EXCEL.
Lab 8 printf() modular arithmetic how to read assignments
 2005 Pearson Education, Inc. All rights reserved Introduction.
Histograms and Matching 主講人:虞台文. Content Overview Basic Histogram Structure Accessing Histograms Basic Manipulations with Histograms Color Spaces Histogram.
Material Properties Repository ImageAnalyzer GUI (MATLAB)
Gavin S Page OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio.net November 2005.
Gavin S Page OpenCV Tutorial Part IV A Brief Guide to Memory Management (and other Miscellaneous Functions) 02 December 2005.
Contrast Enhancement Crystal Logan Mentored by: Dr. Lucia Dettori Dr. Jacob Furst.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Gavin S Page OpenCV Tutorial Part 3 Image Correlation.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Basic Elements of C++ Chapter 2.
1 An Introduction to TI SmartView Emulator Software (Version 2.0) Jim Eiting Developmental Mathematics Department Collin County Community College August.
L.
Spectral contrast enhancement
Gorman, Stubbs, & CEP Inc. Introduction to Operating Systems Lesson 5 Windows 2000 Professional.
COMPUTER SCIENCE I C++ INTRODUCTION
A Tutorial on Object Detection Using OpenCV
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Filtering (I) Dr. Chang Shu COMP 4900C Winter 2008.
OpenCV Open source C omputer V ision library By: Bahare Torkaman Fall 2010.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Adobe Photoshop CS Design Professional COLORS ADJUSTING.
© 2011 Delmar, Cengage Learning Chapter 11 Adjusting Colors.
Chapter 11 Adjusting Colors. Chapter Lessons Correct and adjust color Enhance colors by altering saturation Modify color channels using levels Create.
CP104 Introduction to Programming Modular Programming Lecture 16__ 1 Modular Programming II Functions with single output Functions with multiple outputs.
Chapter 9 Scripting RMAN. Background Authors felt that scripting was a topic not covered well Authors wanted to cover both Unix/Linux and Windows environments.
Detect Candle.  Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories  Choose "Show directories for: Include.
Topics: Statistics & Experimental Design The Human Visual System Color Science Light Sources: Radiometry/Photometry Geometric Optics Tone-transfer Function.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Gorman, Stubbs, & CEP Inc. 1 Introduction to Operating Systems Lesson 4 Microsoft Windows XP.
Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Refining Original Illustrations Lesson 9.
Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering yahoo. com Spring.
June 21, Objectives  Enable the Data Analysis Add-In  Quickly calculate descriptive statistics using the Data Analysis Add-In  Create a histogram.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline Introduction Arrays Declaring Arrays Examples Using Arrays.
CIS 3.5 Lecture 2.2 More programming with "Processing"
(6-3) Modular Programming H&K Chapter 6 Instructor - Andrew S. O’Fallon CptS 121 (October 2, 2015) Washington State University.
PROJECT#3(b) Astrocyte Analysis
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
Chapter 02 (Part II) Introduction to C++ Programming.
1 Berger Jean-Baptiste
You’ll Make a spreadsheet which will be like a Mad Libs Game. These Are The Directions.
XP New Perspectives on Creating Web Pages With Word Tutorial 1 1 Creating Web Pages With Word Tutorial 1.
Chapter Topics The Basics of a C++ Program Data Types
OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio .net November 2005 Gavin S Page
BASIC SKILLS USING EXCEL
Basic Elements of C++.
1-Introduction (Computing the image histogram).
JavaScript: Functions.
A Quick Introduction to the C Interface By David Johnston
Basic Elements of C++ Chapter 2.
Statistical Analysis with Excel
Variables and Arithmetic Operations
Statistical Analysis with Excel
Arrays Arrays A few types Structures of related data items
A Tutorial on Object Detection Using OpenCV
Finding Statistics from Data
Presentation transcript:

Gavin S Page OpenCV Tutorial Part II Loading Images and Using Histograms 29 November 2005

Gavin S Page 2 Tasks The first step after establishing a working environment is to begin manipulating images. This tutorial will give an introduction to the usage of some basic functions. Steps Performed Load an Image Calculate Histogram Values Calculate Basic Statistics Using Histogram Information For explanations on any functions used here see the OpenCV documentat.

29 November 2005Gavin S Page 3 Loading the Image //the name of the image being loaded char* imageName = "Critters_00005.JPG"; //Load the image and make sure that it loads correctly IplImage* im = cvLoadImage(imageName, -1); if( im == 0 ) { //Drop out if the image isn't found std::cerr << "Failed to load: " << imageName << std::endl; return 1; } OpenCV makes it relatively easy to load images. There are several syntax variations that simply take in the path/file name. One is presented here. Specify a File to be Loaded Load the File Use the cvLoadImage function to assign the image to an IplImage pointer OpenCV uses an IplImage to represent image internally.

29 November 2005Gavin S Page 4 Specifying a Working Region In order to work with a histogram the image will have to converted to a single plane. //Create a single planed image of the same size as the original IplImage* grayImage = cvCreateImage(cvSize(im->width,im->height), IPL_DEPTH_8U, 1); //convert the original image to gray cvCvtColor(im, grayImage, CV_BGR2GRAY); //create a rectangular area to evaluate CvRect rect = cvRect(0, 0, 500, 600 ); //apply the rectangle to the image and establish a region of interest cvSetImageROI(grayImage, rect); Create an Image of a Single Plane Create the Grayscale Image Convert the Image to Gray Specify a Rectangular Region of Interest (ROI) and apply it to the image The cvCvtColor function can be used to convert images to one of several color spaces. To restore the region of interest to the whole image the function cvResetImageROI is used

29 November 2005Gavin S Page 5 Perform Initial Histogram Calculations //create an image to hold the histogram IplImage* histImage = cvCreateImage(cvSize(320,200), 8, 1); //create a histogram to store the information from the image CvHistogram* hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1); //calculate the histogram and apply to hist cvCalcHist( &grayImage, hist, 0, NULL ); //grab the min and max values and their indeces cvGetMinMaxHistValue( hist, &min_value, &max_value, &min_idx, &max_idx); //scale the bin values so that they will fit in the image representation cvScale( hist->bins, hist->bins, ((double)histImage->height)/max_value, 0 ); //set all histogram values to 255 cvSet( histImage, cvScalarAll(255), 0 ); //create a factor for scaling along the width bin_w = cvRound((double)histImage->width/hist_size); OpenCV provides built-in functions to work with histograms. Create a Histogram Image and a Histogram Create the Histogram Data Calculate the Histogram Grab Min/Max Values Set Up Factors For Visualization

29 November 2005Gavin S Page 6 Prepare Visualization/Perform Calculations for( i = 0; i < hist_size; i++ ) { //draw the histogram data onto the histogram image cvRectangle( histImage, cvPoint(i*bin_w, histImage->height), cvPoint((i+1)*bin_w, histImage->height - cvRound(cvGetReal1D(hist->bins,i))), cvScalarAll(0), -1, 8, 0 ); //get the value at the current histogram bucket float* bins = cvGetHistValue_1D(hist,i); //increment the mean value mean += bins[0]; } //finish mean calculation mean /= hist_size; //go back through now that mean has been calculated in order to calculate variance for( i = 0; i < hist_size; i++ ) { float* bins = cvGetHistValue_1D(hist,i); variance += pow((bins[0] - mean),2); } //finish variance calculation variance /= hist_size; Here we will iterate across the histogram bins and apply the values to the image while calculating the statistics. Use cvRectangle to draw. Draw Values on Image Get Values/Perform Calculations

29 November 2005Gavin S Page 7 Display Results std::cout << "Histogram Mean: " << mean << std::endl; std::cout << "Variance: " << variance << std::endl; std::cout << "Standard Deviation: " << sqrt(variance) << std::endl; //display the 3 images cvNamedWindow("Original", 0); cvShowImage("Original", im ); cvNamedWindow("Gray", 0); cvShowImage("Gray", grayImage ); cvNamedWindow("Histogram", 0); cvShowImage("Histogram", histImage ); //hold the images until a key is pressed cvWaitKey(0); This segment displays the visual and textural results. Output Statistics Display Hold For Input. Passing the parameter “0” waits for a keypress. cvNamedWindow creates a container. The first parameter is the name and the second declares if the container is to expand to fit the contents. Show Images

29 November 2005Gavin S Page 8 Cleaning Up //clean up images cvReleaseImage(&histImage); cvReleaseImage(&grayImage); cvReleaseImage(&im); //remove windows cvDestroyWindow("Original"); cvDestroyWindow("Gray"); cvDestroyWindow("Histogram"); Release Images Destroy Containers It is very important to perform clean-up functions. It is easy for memory utilization to go out of control when multiple images are involved.

29 November 2005Gavin S Page 9 Results Here are the original image, the grayscale region, and the histogram of that region.

29 November 2005Gavin S Page 10 Other Histogram Functions OpenCV has several other functions for working with histograms. These include: cvNormalizeHist cvThreshHist cvCompareHist For more information about usage of these functions see the OpenCV documentation

29 November 2005Gavin S Page 11 Revision History Initial Creation: 28 November 2005