next up previous contents index
Next: The module Up: imageLoader Previous: imageLoader   Contents   Index


Image and pixels

When implementing libGOCR, the question arised: should we use grayscale? Is black and white enough? What about colors? We decided to use black and white only, since it seemed more than enough, and saved memory. Later, it was realized that color would be essential to some recognition systems -- specially if you want to use libGOCR to recognize something other than plain text. The design was changed, and now libGOCR support these image types3.4:



Type Symbol Pixel size
Black & white GOCR_BW 1
Grayscale GOCR_GRAY 2
Color GOCR_COLOR 4
User-defined GOCR_OTHER -



You may only access the image indirectly.

The whole point of using an image is that you can access pixels individually, so, after several conferences and hundreds of emails, we decided that yes, we would have pixels in our images. Ok, the joke was not funny.

To support the different image types, a slight hack was done in the gocrImageData structure, which contains the individual pixel data (section 3.2.3 has info about it, but you definitely don't need to know). In fact, you only won: you can access any image type just as if it's the type you want; that is, suppose the image loaded is in color, but you want to work in black and white: you can. The functions are:

void gocr_imagePixelSetBW ( gocrImage *image 
int x, int y, unsigned char data ); 
unsigned char gocr_imagePixelGetBW ( gocrImage *image, 
int x, int y ); 
void gocr_imagePixelSetGray ( gocrImage *image, 
int x, int y, unsigned char data ); 
unsigned char gocr_imagePixelGetGray ( gocrImage *image, 
int x, int y ); 
void gocr_imagePixelSetColor ( gocrImage *image, 
int x, int y, unsigned char data[3] ); 
unsigned char *gocr_imagePixelGetColor ( gocrImage *image, 
int x, int y );
Examples:

if ( gocr_imagePixelGetBW(img,0,0) == GOCR_WHITE )
gocr_pixelPixelSetBW(img,0,0,GOCR_BLACK);
 

for ( i = 0; i < img->width; i++ )

for ( j = 0; j < img->height; j++ )
if ( gocr_imagePixelGetGray(img,i,j) > threshold )
gocr_imagePixelSetBW(img,i,j, GOCR_WHITE);
else
gocr_imagePixelSetBW(img,i,j, GOCR_BLACK);
The only thing to note is that, if you provide (x,y) coordinates out of bounds, the functions will return 0, which is also a valid value for a pixel.

Each pixel has three fields that may be used as flags. They are boolean variables, and to access them use:

int gocr_pixelGetMark1 ( gocrImage *image, int x, int y ); 

int gocr_pixelSetMark1 ( gocrImage *image, int x, int y, 

char value ); 
int gocr_pixelGetMark2 ( gocrImage *image, int x, int y ); 

int gocr_pixelSetMark2 ( gocrImage *image, int x, int y, 

char value ); 
int gocr_pixelGetMark3 ( gocrImage *image, int x, int y ); 

int gocr_pixelSetMark3 ( gocrImage *image, int x, int y, 

char value );
They are pretty clear, and return -1 in case of error.


next up previous contents index
Next: The module Up: imageLoader Previous: imageLoader   Contents   Index
root 2002-02-17