1 / 12

Digital Image Processing 數位影像處理

Digital Image Processing 數位影像處理. 江政杰. What’s An Image. 數位影像. Unit: Pixel. Image Type. Gray 灰階影像. Color 彩色影像. 800x600=480000 pixels. 每個 pixel 是由三個値組成 (R, G, B). 每個 pixel 是由一個値組成. Gray Image. Image I 可以表示成. or. double *Image=NULL;

eben
Download Presentation

Digital Image Processing 數位影像處理

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Digital Image Processing數位影像處理 江政杰

  2. What’s An Image 數位影像 Unit: Pixel

  3. Image Type • Gray 灰階影像 • Color 彩色影像 800x600=480000 pixels 每個pixel是由三個値組成 (R, G, B) 每個pixel是由一個値組成

  4. Gray Image Image I可以表示成 or double *Image=NULL; Image = (double *) malloc(width * height * sizeof(double)); // read a gray image file for (i = 0 ; i < height ; i++ ) for (j = 0 ; j < width ; j++){ fscanf(fpin, "%c", &pixel); *(Image+i*width+j)=(double)pixel; //the pixel at (i, j) }

  5. Color Image Image I可以表示成 or double *Image=NULL; Image = (double *) malloc(width * height * sizeof(double)*3); // read a gray image file for (i = 0 ; i < height ; i++ ) for (j = 0 ; j < width ; j++){ fscanf(fpin, "%c", &pixel); *(Image+i*width+j)=(double)pixel; //R at pixel (i, j) fscanf(fpin, "%c", &pixel); *(Image+i*width+j+1)=(double)pixel; //G at pixel (i, j) fscanf(fpin, "%c", &pixel); *(Image+i*width+j+2)=(double)pixel; //B at pixel (i, j) }

  6. Image Features • Feature: 特徵 影像的pixel一般都非常多, 我們要在其中找到可以代表不同影像的特徵 • 目前常見的影像特徵種類很多, 可分成 • Color: 以顏色為主 • Texture: 以材質為主 • Shape: 以形狀為主 • …

  7. Pixel Feature • 最簡單的特徵取法就是 把所有pixel排列出來 這種方式只適合在小的影像, 例如一個icon是32x32=1024 pixels目前在face detection上很多就是用pixel feature直接表示影像特徵

  8. Color Histogram pixel數量 0 255 亮度值 histogram 是最常用也是最簡單的影像特徵表示法 histogram 是一種統計的方式表示顏色變化與分佈狀況 以上面的例子看, color histogram會轉換成256維度的向量 在color image, 可以針對R, G, B 分別算histogram

  9. Color Moments • 因為color histogram的維度一般都很高, 所以用統計的計量再予以精簡 這480000個値可以計算其平均數與變異數, 用這兩個統計量代表一張影像 • Color Image • R, G, B channels, 各有平均數與變異數 • 共六個値代表, 所以是6維的向量

  10. OpenCV Setup in VC • Library: project->setting->link • cv.lib cvaux.lib highgui.lib cxcore.lib • Directories • Include • C:\PROGRAM FILES\OPENCV\CV\INCLUDE • C:\PROGRAM FILES\OPENCV\CVAUX\INCLUDE • C:\PROGRAM FILES\OPENCV\OTHERLIBS\HIGHGUI • C:\PROGRAM FILES\OPENCV\CXCORE\INCLUDE • Library • C:\PROGRAM FILES\OPENCV\LIB • FilePathName • C:\PROGRAM FILES\OPENCV\bin • Include in programs • #include "cv.h“, "cvaux.h“, "highgui.h“, "cxcore.h"

  11. #include <stdio.h> #include <cxcore.h> #include <highgui.h> #include <math.h> int main( int argc, char** argv ) { CvPoint center; double scale=-3; IplImage* image = cvLoadImage("Beach 2.jpg"); if(!image) return -1; /* 這一段程式將每個pixel逐一調整成整張圖有漸層 center = cvPoint(image->width/2,image->height/2); for(int i=0;i<image->height;i++) for(int j=0;j<image->width;j++) { double dx=(double)(j-center.x)/center.x; double dy=(double)(i-center.y)/center.y; double weight=exp((dx*dx+dy*dy)*scale); uchar* ptr = &CV_IMAGE_ELEM(image,uchar,i,j*3); ptr[0] = cvRound(ptr[0]*weight); ptr[1] = cvRound(ptr[1]*weight); ptr[2] = cvRound(ptr[2]*weight); } cvSaveImage("copy.png", image ); */ cvNamedWindow("test", 1 ); cvShowImage("test", image ); cvWaitKey(); return 0; } Including files 主程式開始 OpenCV內定的資料型態 可以直接用 讀取jpeg檔, 內定函數, 輸入參數是字串 產生一個新的視窗 將影像顯示在視窗內 等待按任一鍵

  12. 工 作 • 熟悉Visual C++ (or VC .net) • 將OpenCV安裝到可以執行 • 程式: 輸入一張影像, 然後秀出這張影像 • 研讀face detection與影片處理的相關資訊

More Related