ECE 661 HW6 Report. Lu Wang 10/28/2012

Similar documents
ECE 661 HW 1. Chad Aeschliman

OpenCV. Rishabh Maheshwari Electronics Club IIT Kanpur

OpenCV. OpenCV Tutorials OpenCV User Guide OpenCV API Reference. docs.opencv.org. F. Xabier Albizuri

ECE661 Computer Vision : HW1

IMAGE PROCESSING AND OPENCV. Sakshi Sinha Harshad Sawhney

ECE 661 HW_4. Bharath Kumar Comandur J R 10/02/2012. In this exercise we develop a Harris Corner Detector to extract interest points (such as

ECE661 Computer Vision : HW2

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

Filtering (I) Agenda. Getting to know images. Image noise. Image filters. Dr. Chang Shu. COMP 4900C Winter 2008

Filtering (I) Dr. Chang Shu. COMP 4900C Winter 2008

Intro to Multimedia Retrieval Exercise Course 3 Query by Example: Color Histogram Extraction

ECE661 Computer Vision HW 6

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

OpenCV Introduction. CS 231a Spring April 15th, 2016

OpenCV. Basics. Department of Electrical Engineering and Computer Science

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

Homework 3 Eye Detection

Project Report for EE7700

ECE 661: Homework #3

CS 490: Computer Vision Image Segmentation: Thresholding. Fall 2015 Dr. Michael J. Reale

Detection and Classification of Vehicles

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

Image Processing (1) Basic Concepts and Introduction of OpenCV

CSCI 512 / EENG 512 Computer Vision Spring Lab 6. February 17, 2016

RESTORATION OF DEGRADED DOCUMENTS USING IMAGE BINARIZATION TECHNIQUE

CSE/EE-576, Final Project

PROGRAMMING IN C++ CVIČENÍ

Image segmentation. Stefano Ferrari. Università degli Studi di Milano Methods for Image Processing. academic year

LAB SESSION 1 INTRODUCTION TO OPENCV

Introduction to OpenCV. Marvin Smith

Image Analysis Lecture Segmentation. Idar Dyrdal

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

Introduction to OpenCV

Homework 4: (GRADUATE VERSION)

Point Operations. Prof. George Wolberg Dept. of Computer Science City College of New York

Image Steganalysis Image Steganography

Lecture: Segmentation I FMAN30: Medical Image Analysis. Anders Heyden

XPM 2D Transformations Week 2, Lecture 3

Optical Verification of Mouse Event Accuracy

CITS 4402 Computer Vision

Image segmentation based on gray-level spatial correlation maximum between-cluster variance

XPM 2D Transformations Week 2, Lecture 3

An Efficient Character Segmentation Based on VNP Algorithm

Chapter 11 Representation & Description

Example 1: Color-to-Grayscale Image Processing

Ulrik Söderström 16 Feb Image Processing. Segmentation

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Binary Image Processing. Introduction to Computer Vision CSE 152 Lecture 5

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

CS 231A Computer Vision (Winter 2014) Problem Set 3

CS101 PLEDGED SPRING 2001

Chapter 6. Introduction to OpenCV

EECS490: Digital Image Processing. Lecture #22

Region-based Segmentation

Adaptive Local Thresholding for Fluorescence Cell Micrographs

CS 315 Data Structures Fall Figure 1

CHAPTER 4 SEMANTIC REGION-BASED IMAGE RETRIEVAL (SRBIR)

stanford hci group / cs377s Lecture 8: OpenCV Dan Maynes-Aminzade Designing Applications that See

Extracting Layers and Recognizing Features for Automatic Map Understanding. Yao-Yi Chiang

Homework 4 Computer Vision CS 4731, Fall 2011 Due Date: Nov. 15, 2011 Total Points: 40

a. a * c - 10 = b. a % b + (a * d) + 7 =

ECEN 447 Digital Image Processing

ViSP tracking methods overview

CHAPTER 6 IDENTIFICATION OF CLUSTERS USING VISUAL VALIDATION VAT ALGORITHM

SSRG International Journal of Computer Science and Engineering (SSRG-IJCSE) volume1 issue7 September 2014

Image Segmentation. Selim Aksoy. Bilkent University

C++ Structures Programming Workshop 2 (CSCI 1061U)

[10] Industrial DataMatrix barcodes recognition with a random tilt and rotating the camera

Image Segmentation. Selim Aksoy. Bilkent University

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

Real-time Background Subtraction in C++ Haotian Wu, Yifan Yu

Image Segmentation Based on Watershed and Edge Detection Techniques

The NAO Robot, a case of study Robotics Franchi Alessio Mauro

CSE 12 Spring 2016 Week One, Lecture Two

EN1610 Image Understanding Lab # 3: Edges

EE663 Image Processing Histogram Equalization I

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Eye Localization Using Color Information. Amit Chilgunde

Object Oriented Design

Histograms. h(r k ) = n k. p(r k )= n k /NM. Histogram: number of times intensity level rk appears in the image

A Fast Caption Detection Method for Low Quality Video Images

Motion Detection. Final project by. Neta Sokolovsky

MULTI ORIENTATION PERFORMANCE OF FEATURE EXTRACTION FOR HUMAN HEAD RECOGNITION

Example 2: Straight Lines. Image Segmentation. Example 3: Lines and Circular Arcs. Example 1: Regions

Robot vision review. Martin Jagersand

Example 1: Regions. Image Segmentation. Example 3: Lines and Circular Arcs. Example 2: Straight Lines. Region Segmentation: Segmentation Criteria

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

Laboratory of Applied Robotics

ECG782: Multidimensional Digital Signal Processing

Computer Vision. Image Segmentation. 10. Segmentation. Computer Engineering, Sejong University. Dongil Han

Binghamton University. CS-211 Fall Functions. The Basis of C

Types of image feature and segmentation

Real Time Image Processing Multimedia Skype Client

Android Automatic object detection - BGU CV 142

Image Segmentation. Segmentation is the process of partitioning an image into regions

Programming for Non-Programmers

PPKE-ITK. Lecture

Image Enhancement: To improve the quality of images

(10) Image Segmentation

Transcription:

ECE 661 HW6 Report Lu Wang 10/28/2012 1.Problem In this homework, we perform the Otsu s algorithm to segment out the interest region form a color image of the Lake Tahoe. Then extract the contour of the lake. 2. Otsu s algorithm in color space a. Split the R, G, and B channels Since the input is a color image, while the original Otsu s algorithm is implemented on a grayscale image, we first need to split the 3 channels out of the color image. This is done by calling cvsplit from opencv. b. Find out the best segmentation thresholds for the three channels respectively using Otsu s method. For a single channel, the optimal threshold that maximizes the between-class variance,, is selected. In this way, the two classes separated have the most significant distinguishes. We compute using the formulas below. First, define L to be the number of gray levels the image is represented in. The number of pixels at level I is donated by. The total number of pixels is N. The probability that a pixel is in gray level i is, The total mean level of the image is, If level k is the threshold, the between-class variance can be expressed as where Now, we construct the zeroth and first-order moment of the histogram up to level k. So that, Substitute all the parameters into then we have,

( ) [ ] The above equation is calculated for every gray level k, is the maximum among all the values.. We choose k as the one whose c. Merge the results of three channels together. For our given image, if all of the R, G, and B values of a pixel are smaller than their corresponding threshold, it is a pixel belongs to the lake region. Otherwise, it is the background. Since the lake is blue, the result of B channel is the closest to the merged result. d. Extract the contour of the lake. From step c, we are able to get a binary mask, which indicates the lake (pixel value 0) and the background (pixel value 255). We perform a 4-neighborhood boarder detector to capture the contour. The contour must belong to the lake, and connect to the background in 4-neighborhood. So the strategy is: for i = 1: number of pixels in the image if (the value of pixel i is 0 && at least one of the 4-neighborhood has pixel value 255) pixel i is on the contour; However, we detect a lot of noise pixels, the single dots, which should not belong to the contour. We further remove those noise pixels by checking whether the pixel is connected to other pixels in the lake region, and remove the single dots.

3. The segmented results with the binary image and the contour. (a) The original image (b) The lake region only (c) The binary image with the lake region. Merged results of the three channels (d) The contour of the lake (black line)

(e) R channel binary image (f) G channel binary image (g) B channel binary image

4. Code #include <cv.h> #include <highgui.h> #include <iostream> #include <opencv2/core/core.hpp> using namespace cv; using namespace std; #include "Otsu.h"; int main( int argc, char** argv) char* inimagename; inimagename = argv[1]; IplImage* inimage = cvloadimage(inimagename,1); int i,j,k; if(!inimage) cout<<"could not load image file!"<<endl; return 1; IplImage* lake_region = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,3); cvcopy(inimage,lake_region,null); uchar* data_region = (uchar *)lake_region->imagedata; IplImage* lake_contour = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,3); cvcopy(inimage,lake_contour,null); // cvzero(lake_contour); uchar* data_contour = (uchar *)lake_contour->imagedata; //split image into 3 color plans IplImage* r = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,1); IplImage* g = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,1); IplImage* b = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,1); cvsplit(inimage, r,g,b,null); // compute the otsu threshold int threshr,threshg,threshb; threshr = Otsu(r); threshg = Otsu(g); threshb = Otsu(b); //merge the three color plane together uchar* datar = (uchar *)r->imagedata; uchar* datag = (uchar *)g->imagedata; uchar* datab = (uchar *)b->imagedata; int width = inimage->width; int height = inimage->height; int step = r->widthstep; int Step = inimage->widthstep; //creat the binary mask and merge the 3 filtered color plane together IplImage* binary = cvcreateimage(cvgetsize(inimage),ipl_depth_8u,1); uchar* databinary = (uchar *)binary->imagedata;

cvzero(binary); for (i=0;i<width;i++) for(j=0;j<height;j++) //Merge the three channel together if(datar[j*step+i]>threshr datag[j*step+i]>threshg datab[j*step+i]>threshb) databinary[j*step+i] = 255; for(k=0;k<3;k++) data_region[j*step+i*3+k] = 0; //segment the three channels if(datar[j*step+i]>threshr) datar[j*step+i]=255; else datar[j*step+i]=0; if(datag[j*step+i]>threshg) datag[j*step+i]=255; else datag[j*step+i]=0; if(datab[j*step+i]>threshb) datab[j*step+i]=255; else datab[j*step+i]=0; //save the binary image for the three channels char rname [128]; sprintf(rname,"r.png"); cvsaveimage(rname,r); char gname [128]; sprintf(gname,"g.png"); cvsaveimage(gname,g); char bname [128]; sprintf(bname,"b.png"); cvsaveimage(bname,b); //save the output image char binaryname [128]; sprintf(binaryname,"binary.png"); cvsaveimage(binaryname,binary); // cvreleaseimage(&binary); char outname1 [128]; sprintf(outname1,"lake_region.png"); cvsaveimage(outname1,lake_region); // cvreleaseimage(&inimage); // cvnamedwindow("originalx",cv_window_autosize); // cvshowimage("originalx",binary); // cvwaitkey(-1); //extract the contour of the image for (i=0;i<width;i++)

for(j=0;j<height;j++) if(databinary[j*step+i]==0 ) //check the 4-neighborhood if (!(databinary[(j-1)*step+i]==255 && databinary[(j+1)*step+i]==255 && databinary[j*step+i+1]==255 && databinary[j*step+i-1]==255)) if (databinary[(j-1)*step+i]==255 databinary[(j+1)*step+i]==255 databinary[j*step+i+1]==255 databinary[j*step+i-1]==255) for(k=0;k<3;k++) data_contour[j*step+i*3+k] = 0; char outname2 [128]; sprintf(outname2,"lake_contour.png"); cvsaveimage(outname2,lake_contour); cvreleaseimage(&inimage); ///////////////////////////////////////// // // // The Otsu's algorithm // // // /////////////////////////////////////// #include <cv.h> #include <highgui.h> #include <iostream> #include <opencv2/core/core.hpp> using namespace cv; using namespace std; int Otsu(IplImage *image) int i,j; float width = image->width; float height = image->height; int numbins = 256; float range[] = 0, 255; float *ranges[] = range ; CvHistogram *hist = cvcreatehist(1, &numbins, CV_HIST_ARRAY, ranges, 1); cvclearhist(hist); // compute the histogram of the image cvcalchist(&image, hist, 0, 0);

// compute the ut float ut=0; for(j=0;j<256;j++) float histvalue = cvqueryhistvalue_1d(hist,j); ut = ut+histvalue*(float)j/width/height; // compute zeroth and first-order moment float m0, m1; float maxvb=0; float Vb; int thresh = 0; for (i = 1;i<255;i++) m0 =0; m1 = 0; Vb = 0; for(j=0;j<i+1;j++) float histvalue = cvqueryhistvalue_1d(hist,j); m0 = m0+histvalue/width/height; m1 = m1+histvalue*(float)j/width/height; Vb = m0*(1-m0)*pow((ut-m1)/(1-m0)-m1/m0,2); if (Vb>maxVb) maxvb = Vb; thresh = j; return thresh;