Ejemplo n.º 1
0
void printrgb(const _myfloat *rgb, int w, int h, const char *name)
{
    float* rgbtmp = (float *)malloc(3*w*h*sizeof(float));
    for (int i = 0; i < 3*w*h; i++) {
        rgbtmp[i] = (float) rgb[i];
    }
    io_png_write_f32(name, rgbtmp, w, h, 3);
    free(rgbtmp);
}
Ejemplo n.º 2
0
void printImage(double *imageIn, int w, int h, char *name)
{
    float *imf32 = (float *) malloc(w * h * sizeof(float));
    for (int i = 0; i < w * h; i++) {
        imf32[i] =  (float) imageIn[i];
    }
    io_png_write_f32(name, imf32, w, h, 1);
    free(imf32);
}
/// Main Program
int main(int argc, char *argv[])
{
	CmdLine cmd;

    std::string combine;
    ParamDisparity p; // Parameters for adaptive weights
    cmd.add( make_option('R',p.radius) );
    cmd.add( make_option(0,p.gammaCol,"gcol") );
    cmd.add( make_option(0,p.gammaPos,"gpos") );
	cmd.add( make_option('c', combine) );

	try {
		cmd.process(argc, argv);
	} catch(std::string str) {
		std::cerr << "Error: " << str << std::endl<<std::endl;
        argc = 1; // To display usage
	}
	if(argc!=5 && argc!=7) {
		usage(argv[0]);
		return 1;
	}

    // Load images
    Image im1 = loadImage(argv[1]);
    Image im2;
    if(argc>5)
        im2 = loadImage(argv[5]);

	int x,y;
	if(! ((std::istringstream(argv[2])>>x).eof() &&
		  (std::istringstream(argv[3])>>y).eof())) {
        std::cerr << "Error reading x or y" << std::endl;
        return 1;
	}

	int disp=0;
	if(argc>6 && !((std::istringstream(argv[6])>>disp).eof()) ) {
        std::cerr << "Error reading disparity" << std::endl;
        return 1;
	}

    Comb* comb=0;
    if(cmd.used('c') && im2.channels()!=0) {
        if(combine == "left")
            comb = new Comb(left);
        else if(combine == "max")
            comb = new Comb(max);
        else if(combine == "min")
            comb = new Comb(min);
        else if(combine == "mult")
            comb = new Comb(mult);
        else if(combine == "plus")
            comb = new Comb(plus);
        else {
            std::cerr << "Unrecognized option for weights combination "
                      << "(should be left,max,min,mult or plus)" << std::endl;
            return 1;
        }
    }

    Image w = show_weights(im1, im2, x, y, x+disp, comb,
                           p.radius, p.gammaCol, p.gammaPos);
    rescale(w);
    if(io_png_write_f32(argv[4], &w(0,0), w.width(), w.height(), 1) != 0) {
        std::cerr << "Unable to write file " << argv[4] << std::endl;
        return 1;
    }

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {


    if (argc < 5) {
        printf("usage: nlmeans_ipol image sigma noisy denoised \n");
        exit(-1);
    }
    
    // read input
    size_t nx,ny,nc;
    float *d_v = NULL;
    d_v = io_png_read_f32(argv[1], &nx, &ny, &nc);
    if (!d_v) {
        printf("error :: %s not found  or not a correct png image \n", argv[1]);
        exit(-1);
    }
    
    // variables
    int d_w = (int) nx;
    int d_h = (int) ny;
    int d_c = (int) nc;
    if (d_c == 2) {
        d_c = 1;    // we do not use the alpha channel
    }
    if (d_c > 3) {
        d_c = 3;    // we do not use the alpha channel
    }
    int d_wh = d_w * d_h;
    int d_whc = d_c * d_w * d_h;
    
    // test if image is really a color image even if it has more than one channel
    if (d_c > 1) {

        // dc equals 3
        int i=0;
        while (i < d_wh && d_v[i] == d_v[d_wh + i] && d_v[i] == d_v[2 * d_wh + i ])  {
            i++;
        }

        if (i == d_wh) d_c = 1;

    }

    // add noise
    float fSigma = atof(argv[2]);
    float *noisy = new float[d_whc];

    for (int i=0; i < d_c; i++) {
        fiAddNoise(&d_v[i * d_wh], &noisy[i * d_wh], fSigma, i, d_wh);
    }

    // denoise
    float **fpI = new float*[d_c];
    float **fpO = new float*[d_c];
    float *denoised = new float[d_whc];
    for (int ii=0; ii < d_c; ii++) {

        fpI[ii] = &noisy[ii * d_wh];
        fpO[ii] = &denoised[ii * d_wh];

    }
    int bloc, win;
    float fFiltPar;

    if (d_c == 1) {

        if (fSigma > 0.0f && fSigma <= 15.0f) {
            win = 1;
            bloc = 10;
            fFiltPar = 0.4f;

        } else if ( fSigma > 15.0f && fSigma <= 30.0f) {
            win = 2;
            bloc = 10;
            fFiltPar = 0.4f;

        } else if ( fSigma > 30.0f && fSigma <= 45.0f) {
            win = 3;
            bloc = 17;
            fFiltPar = 0.35f;

        } else if ( fSigma > 45.0f && fSigma <= 75.0f) {
            win = 4;
            bloc = 17;
            fFiltPar = 0.35f;

        } else if (fSigma <= 100.0f) {

            win = 5;
            bloc = 17;
            fFiltPar = 0.30f;

        } else {
            mexPrintf("error :: algorithm parametrized only for values of sigma less than 100.0\n");
            exit(-1);
        }

    } else {


        if (fSigma > 0.0f && fSigma <= 25.0f) {
            win = 1;
            bloc = 10;
            fFiltPar = 0.55f;

        } else if (fSigma > 25.0f && fSigma <= 55.0f) {
            win = 2;
            bloc = 17;
            fFiltPar = 0.4f;

        } else if (fSigma <= 100.0f) {
            win = 3;
            bloc = 17;
            fFiltPar = 0.35f;

        } else {
            printf("error :: algorithm parametrized only for values of sigma less than 100.0\n");
            exit(-1);
        }



    }



    nlmeans_ipol(win, bloc, fSigma, fFiltPar, fpI,  fpO, d_c, d_w, d_h);

    // save noisy and denoised images
    if (io_png_write_f32(argv[3], noisy, (size_t) d_w, (size_t) d_h, (size_t) d_c) != 0) {
        printf("... failed to save png image %s", argv[3]);
    }
    
    if (io_png_write_f32(argv[4], denoised, (size_t) d_w, (size_t) d_h, (size_t) d_c) != 0) {
        printf("... failed to save png image %s", argv[4]);
    }



}
Ejemplo n.º 5
0
/// Usage: siftMatch imgIn imgIn2 fileOut [imgOut]
/// Output in text file fileOut the matches evaluated by SIFT method between
/// the images imgIn and imgIn2 (PNG format). If imgOut is in the argument list,
/// this is an image file where matches will be shown (PNG format).
int main(int argc, char **argv)
{	
    if(argc != 4 && argc != 5) {
        std::cerr << "Usage: " << argv[0] << " imgIn imgIn2 fileOut [imgOut]"
                  << std::endl;
        return 1;
    }

	//////////////////////////////////////////////// Input
	int w1, h1;
    float* ipixels1;
    if(! load(argv[1], ipixels1, w1, h1))
        return 1;

	//////////////////////////////////////////////// Input
    int w2, h2;
    float* ipixels2;
    if(! load(argv[2], ipixels2, w2, h2))
        return 1;

	///////////////////////////////////////// Applying Sift
	siftPar siftparameters;
	default_sift_parameters(siftparameters);
    siftparameters.DoubleImSize=0;

	keypointslist keyp1, keyp2;
	compute_sift_keypoints(ipixels1,keyp1,w1,h1,siftparameters);
    std::cout<< "siftMatch:: 1st image: " << keyp1.size() << " keypoints"<<std::endl;
	compute_sift_keypoints(ipixels2,keyp2,w2,h2,siftparameters);
    std::cout<< "siftMatch:: 2nd image: " << keyp2.size() << " keypoints"<<std::endl;

	matchingslist matchings;
	compute_sift_matches(keyp1,keyp2,matchings,siftparameters);	
    std::cout << "siftMatch:: matches: " << matchings.size() <<std::endl;

	//////////////////////////////////////////////////////////////// Save file with matches
    saveMatch(argv[3], matchings);

	//////////////////////////////////////////////// Output image containing line matches
    if(argc > 4) {
        int wo =  std::max(w1,w2);
        int ho = h1+h2;

        float *opixels = new float[wo*ho];
        for(int j = 0; j < h1; j++)
            for(int i = 0; i < w1; i++)  opixels[j*wo+i] = ipixels1[j*w1+i];
        for(int j = 0; j < h2; j++)
            for(int i = 0; i < w2; i++)  opixels[(h1 + j)*wo + i] = ipixels2[j*w2 + i];	

        //////////////////////////////////////////////////////////////////// Draw matches
        matchingslist::iterator ptr = matchings.begin();
        for(; ptr != matchings.end(); ++ptr)
            draw_line(opixels,
                      (int) ptr->x1, (int) ptr->y1,
                      (int) ptr->x2, (int) ptr->y2 + h1,
                      255.0f, wo, ho);

        ///////////////////////////////////////////////////////////////// Save imgOut	
        io_png_write_f32(argv[4], opixels, (size_t)wo, (size_t)ho, 1);
        delete[] opixels;
	}

	/////////////////////////////////////////////////////////////// Delete memory
	free(ipixels1);
	free(ipixels2);
    return 0;
}