Ejemplo n.º 1
0
static bool ImageReadRGB(ImageOf<PixelRgb> &img, const char *filename)
{
    int width, height, color, num;
    FILE *fp=0;
    fp = fopen(filename, "rb");

    if(fp==0)
        {
            fprintf(stderr, "Error opening %s, check if file exists.\n", filename);
            return false;
        }

    if (!ReadHeader(fp, &height, &width, &color))
        {
            fclose (fp);
            fprintf(stderr, "Error reading header, is file a valid ppm/pgm?\n");
            return false;
        }

    if (!color)
        {
            ImageOf<PixelMono> tmp;
            tmp.resize(width,height);

            const int w = tmp.width() * tmp.getPixelSize();
            const int h = tmp.height();
            const int pad = tmp.getRowSize();
            unsigned char *dst = tmp.getRawImage ();

            num = 0;
            for (int i = 0; i < h; i++)
                {
                    num += (int)fread((void *) dst, 1, (size_t) w, fp);
                    dst += pad;
                }
            fclose(fp);
            img.copy(tmp);
            return true;
        }

    img.resize(width,height);

    const int w = img.width() * img.getPixelSize();
    const int h = img.height();
    const int pad = img.getRowSize();
    unsigned char *dst = img.getRawImage ();

    num = 0;
    for (int i = 0; i < h; i++)
        {
            num += (int)fread((void *) dst, 1, (size_t) w, fp);
            dst += pad;
        }

    fclose(fp);

    return true;
}
Ejemplo n.º 2
0
static bool ImageReadBGR(ImageOf<PixelBgr> &img, const char *filename)
{
    int width, height, color, num;
    FILE *fp=0;
    fp = fopen(filename, "rb");

    if(fp==0)
        {
            fprintf(stderr, "Error opening %s, check if file exists.\n", filename);
            return false;
        }

    if (!ReadHeader(fp, &height, &width, &color))
        {
            fclose (fp);
            fprintf(stderr, "Error reading header, is file a valid ppm/pgm?\n");
            return false;
        }
    if (!color)
        {
            fclose(fp);
            fprintf(stderr, "File is grayscale, conversion not yet supported\n");
            return false;
        }

    ImageOf<PixelRgb> tmpImg;
    tmpImg.resize(width, height);

    const int w = tmpImg.width() * img.getPixelSize();
    const int h = tmpImg.height();
    const int pad = tmpImg.getRowSize();
    unsigned char *dst = tmpImg.getRawImage ();

    num = 0;
    for (int i = 0; i < h; i++)
        {
            num += (int)fread((void *) dst, 1, (size_t) w, fp);
            dst += pad;
        }

    fclose(fp);

    return img.copy(tmpImg);
}
Ejemplo n.º 3
0
void DisparityTool::makeHistogram(ImageOf<PixelMono>& hImg) {
    int i,j;
    int height = hImg.height();
    int width = hImg.width();

    unsigned char bgColor = 0;
    unsigned char hColor = 190;
    unsigned char lineColor = 255;

    unsigned char * hist = new unsigned char [height*width*hImg.getPixelSize()];
    img2unpaddedVect(hist, hImg);

    int offset = (width - _shiftLevels + 1)/2;

    for (j = 0; j < height*width; j++)
        hist[j] = bgColor;

    //design the area
    for (i = 0; i < _shiftLevels-1; i++) {
    
        if ((i+offset >=_shiftMin)&&(i+offset< _shiftMax)) {

            for (j = height-(int)(height*_corrFunct[i]); j < height; j++)
                hist[(j*width+i+offset)] = hColor;
        }
    }
    //design the maxes
    for (i = 0; i < 3; i++) {
        if ((_maxShifts[i].index+offset >=_shiftMin)&&(_maxShifts[i].index+offset<_shiftMax)) {
            for (j = height-(int)(height*_corrFunct[_maxShifts[i].index]); j < height; j++)
                hist[(j*width+_maxShifts[i].index+offset)] = lineColor;
        }
    }

    //Drawing Zero Reference
    for (j = 0; j < height; j += height/9) {
        for (int k = 0; k < height/18; k++) {
    	    hist[((j+k)*width + _shiftLevels/2 + offset)] = lineColor;
        }
    }

    //Partially inverted color
    for (int y = 0; y < height; y++) {
        for (int x1 = 0; x1 < _shiftMin; x1++)
            hist[(y*width+x1+offset)] = hist[(y*width+x1+offset)]+100;
        for (int x2 = width - 1; x2 > _shiftMax; x2--)
            hist[(y*width+x2+offset)] = hist[(y*width+x2+offset)]+100;
    }

	//Drawing Limits (inverted colors sides)
    /*	for (int y = 0; y < height; y++)
	{
		for (int x1 = 0; x1 < _shiftMin; x1++)
			hist[(y*width+x1+offset)] = -hist[(y*width+x1+offset)]+255;
		for (int x2 = width - 1; x2 > _shiftMax; x2--)
			hist[(y*width+x2+offset)] = -hist[(y*width+x2+offset)]+255;
	}/***/

    unpaddedVect2img(hist, hImg);
    delete [] hist;
}