예제 #1
0
_myfloat* read_image_to_gray(char* fname, int *pw, int *ph)
{
    size_t w, h;
    _myfloat* imf32 = io_png_read_f32_rgb(fname, &w, &h);
    _myfloat* x = xmalloc(w*h*sizeof(_myfloat));
    for(unsigned int i = 0; i < w*h; i++)
        x[i] = (_myfloat)((0.299*imf32[i] + 0.587*imf32[w*h+i] + 0.1140*imf32[2*w*h+i])/256.); //RGB2GRAY
    xfree(imf32);
    *pw = w;
    *ph = h;
    return x;
}
예제 #2
0
double* read_image_to_gray(char* fname, int *pw, int *ph)
{
    size_t w, h;
    float* imf32 = io_png_read_f32_rgb(fname, &w, &h);
    double* x = (double*)malloc(w*h*sizeof(double));
    for(int i = 0; i < w*h; i++)
        x[i] = (double)((0.299*imf32[i] + 0.587*imf32[w*h+i] + 0.1140*imf32[2*w*h+i])); //RGB2GRAY
    free(imf32);
    *pw = w;
    *ph = h;
    return x;
}
/// Load color image
Image loadImage(const char* name) {
    size_t width, height;
    float* pix = io_png_read_f32_rgb(name, &width, &height);
    if(! pix) {
        std::cerr << "Unable to read file " << name << " as PNG" << std::endl;
        std::exit(1);
    }
    const int w=static_cast<int>(width), h=static_cast<int>(height);
    Image im(w, h, 3);
    const float *r=pix, *g=r+w*h, *b=g+w*h;
    for(int y=0; y<h; y++)
        for(int x=0; x<w; x++) {
            im(x,y,0) = *r++;
            im(x,y,1) = *g++;
            im(x,y,2) = *b++;
        }
    std::free(pix);
    return im;
}