aihot  2017-06-02 18:58:34  OpenCV |   查看评论   

 (坐标是从0开始的,并且是相对图像原点的位置。图像原点或者是左上角 (img->origin=IPL_ORIGIN_TL) 或者是左下角 (img->origin=IPL_ORIGIN_BL) )

 
假设有 8-bit 1-通道的图像 I (IplImage* img):
 
---------------------------------------------------------------------
 
I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
 
---------------------------------------------------------------------
 
假设有 8-bit 3-通道的图像 I (IplImage* img):
 
---------------------------------------------------------------------
 
I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
 
I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
 
I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
 
------------------------------------------------------------------------------
 
例如,给点 (100,100) 的亮度增加 30 ,那么可以这样做:
 
------------------------------------------------------------------------------
 
CvPoint pt = {100,100};
 
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3] += 30;
 
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+1] += 30;
 
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+2] += 30;
 
-----------------------------------------------------------------------------
 
或者更高效地:
 
-----------------------------------------------------------------------------
 
CvPoint pt = {100,100};
 
uchar* temp_ptr = &((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3];
 
temp_ptr[0] += 30;
 
temp_ptr[1] += 30;
 
temp_ptr[2] += 30;
 
-----------------------------------------------------------------------------
 
假设有 32-bit 浮点数, 1-通道 图像 I (IplImage* img):
 
-----------------------------------------------------------------------------
 
I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
 
-----------------------------------------------------------------------------
 
现在,一般的情况下,假设有 N-通道,类型为 T 的图像:
 
-----------------------------------------------------------------------------
 
I(x,y)c ~ ((T*)(img->imageData + img->widthStep*y))[x*N + c]
 
-----------------------------------------------------------------------------
 
你可以使用宏 CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )
 
-----------------------------------------------------------------------------
 
I(x,y)c ~ CV_IMAGE_ELEM( img, T, y, x*N + c )
 
-----------------------------------------------------------------------------
 
也有针对各种图像(包括 4 通道图像)和矩阵的函数(cvGet2D, cvSet2D), 但是它们非常慢。
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自五、怎么访问图像像素(OpenCV学习笔记)

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]