Update to 2.0.0 tree from current Fremantle build
[opencv] / doc / plastex / faq_technical.rst
1
2 FAQ Technical Questions on Library Use
3 --------------------------------------
4
5 How to access image pixels
6 ^^^^^^^^^^^^^^^^^^^^^^^^^^
7
8 (The coordinates are 0-based and counted from image origin, either top-left (img->origin=IPL_ORIGIN_TL) or bottom-left (img->origin=IPL_ORIGIN_BL)
9
10     * Suppose, we have 8-bit 1-channel image I (IplImage* img)::
11
12         I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
13
14     * Suppose, we have 8-bit 3-channel image I (IplImage* img)::
15
16         I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
17         I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
18         I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
19
20       e.g. increasing brightness of point (100,100) by 30 can be done this way::
21
22         CvPoint pt = {100,100};
23         ((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3] += 30;
24         ((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+1] += 30;
25         ((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+2] += 30;
26
27       or more efficiently::
28
29         CvPoint pt = {100,100};
30         uchar* temp_ptr = &((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3];
31         temp_ptr[0] += 30;
32         temp_ptr[1] += 30;
33         temp_ptr[2] += 30;
34
35     * Suppose, we have 32-bit floating point, 1-channel image I (IplImage* img)::
36
37         I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
38
39     * Now, the general case: suppose, we have N-channel image of type T::
40
41         I(x,y)c ~ ((T*)(img->imageData + img->widthStep*y))[x*N + c]
42
43       or you may use macro CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )::
44
45         I(x,y)c ~ CV_IMAGE_ELEM( img, T, y, x*N + c )
46
47 There are functions that work with arbitrary (up to 4-channel) images and matrices (cvGet2D, cvSet2D), but they are pretty slow. 
48