Esempio n. 1
0
void difference_of_gaussians(double sigma_first, double sigma_second,
                             unsigned char dst[], unsigned char src[],
                             int h, int s, int n_chans)
{
    int x, y, channel, offset, size;
    unsigned char *first, *second;


    size = h * s;
    first = (unsigned char*) malloc(size * sizeof(unsigned char*));
    second = (unsigned char*) malloc(size * sizeof(unsigned char*));
    memcpy(first, src, size);
    memcpy(second, src, size);

    gaussian_blur(sigma_first, sigma_first, first, first, h, s, n_chans);
    gaussian_blur(sigma_second, sigma_second, second, second, h, s, n_chans);

    for (channel = 0; channel < MIN(3, n_chans); channel++) {
        for (y = 0; y < h; y++) {
            for (x = 0; x < s; x += n_chans) {
                offset = y * s + x + channel;

                dst[offset] = MIN(MAX(first[offset] - second[offset], 0), 0xFF);
            }
        }
    }

    free(first);
    free(second);
}
Esempio n. 2
0
 void
 bc2s_feature<A>::update(const I& in, const cuda_gpu&)
 {
   SCOPE_PROF(bc2s_feature::update);
   gaussian_blur(in, s1_, tmp_, kernel_2_);
   //copy(in, s1_);
   gaussian_blur(s1_, s2_, tmp_, kernel_1_);
   fill_border_clamp(s1_);
   fill_border_clamp(s2_);
 }
int main(int argc, char* argv[]) {
    assert(argc>3);

    Bayesian bayesian(256, 256);

    std::string output_folder = argv[1];
    std::string train_folder = argv[2];
    std::string filename = argv[3];

    fs::path path_to_output_folder(output_folder);
    path_to_output_folder/=filename;
    fs::path path_to_train_folder(train_folder);

    bayesian.train_from_folder<0,1>(path_to_train_folder);

    auto bayesian_m = bayesian.model();

    std::ofstream file(path_to_output_folder.string());
    bayesian_m.save_to_file(file);
    bayesian_m.gaussian_blur(5,5,1,1);
    cv::Mat color_map = bayesian_m.representation();
    cv::imwrite(path_to_output_folder.string() + ".jpg",color_map);

    cv::imshow("color map",color_map);
    cv::waitKey(0);

    return 0;
}
Esempio n. 4
0
int
main(int argc, char* argv[])
{
    image* im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}
int main(int argc, char *argv[]) {
    const int w = 20;
    const int h = 20;
    int i;

    float *src =  (float*)_mm_malloc(w*h*sizeof(float),16);
    float *dst1 =  (float*)_mm_malloc(w*h*sizeof(float),16);
    float *dst2 =  (float*)_mm_malloc(w*h*sizeof(float),16);
    for(i=0; i<w*h; i++) {
        src[i] = i;
    }

    gaussian_blur(src, dst1, w, h, 1.0f, 1);
    gaussian_blur(src, dst2, w, h, 1.0f, 4);
    int error = compare(dst1, dst2, w*h);
    printf("error %d\n", error);
    _mm_free(src);
    _mm_free(dst1);
    _mm_free(dst2);

    return 0;
}
Esempio n. 6
0
void Window::create_actions()
{
    open_action = new QAction(QIcon(":/fileopen.ico"), tr("Open"), this);
    open_action->setShortcuts(QKeySequence::Open);
    connect(open_action, SIGNAL(triggered()), this, SLOT(open()));

    save_as_action = new QAction(QIcon(":/filesaveas.ico"), tr("Save As"), this);
    save_as_action->setShortcuts(QKeySequence::SaveAs);
    connect(save_as_action, SIGNAL(triggered()), this, SLOT(save_as()));
    save_as_action->setEnabled(false);

    exit_action = new QAction(QIcon(":/exit.ico"), tr("Quit"), this);
    exit_action->setShortcuts(QKeySequence::Quit);
    connect(exit_action, SIGNAL(triggered()), this, SLOT(close()));

    zoom_in_action = new QAction(QIcon(":/zoom_in.ico"),tr("Zoom &In (25%)"), this);
    zoom_in_action->setShortcuts(QList<QKeySequence>() << QKeySequence::ZoomIn << QKeySequence(tr("Ctrl++")));
    zoom_in_action->setEnabled(false);
    connect(zoom_in_action, SIGNAL(triggered()), this, SLOT(zoom_in()));

    zoom_out_action = new QAction(QIcon(":/zoom_out.ico"),tr("Zoom &Out (25%)"), this);
    zoom_out_action->setShortcuts(QList<QKeySequence>() << QKeySequence::ZoomOut << QKeySequence(tr("Ctrl+-")));
    zoom_out_action->setEnabled(false);
    connect(zoom_out_action, SIGNAL(triggered()), this, SLOT(zoom_out()));

    zoom_original_action = new QAction(QIcon(":/zoom_original.ico"),tr("&Normal Size"), this);
    zoom_original_action->setShortcut(tr("Ctrl+S"));
    zoom_original_action->setEnabled(false);
    connect(zoom_original_action, SIGNAL(triggered()), this, SLOT(zoom_original()));

    zoom_fit_action = new QAction(QIcon(":/zoom_fit_best.ico"),tr("&Fit to Window"), this);
    zoom_fit_action->setShortcut(tr("Ctrl+F"));
    zoom_fit_action->setEnabled(false);
    zoom_fit_action->setCheckable(true);
    connect(zoom_fit_action, SIGNAL(triggered()), this, SLOT(zoom_fit()));

    gaussian_blur_action = new QAction(tr("Gaussian blur"), this);
    gaussian_blur_action->setShortcut(tr("Ctrl+g"));
    gaussian_blur_action->setEnabled(false);
    connect(gaussian_blur_action, SIGNAL(triggered()), this, SLOT(gaussian_blur()));
}
Esempio n. 7
0
int main(int argc, char **argv) {
    char *input_img1 = NULL, *input_img2 = NULL;
    double deg = 0.0, scale_fac = 0.0, sigma = 0.0;
    int num_threads = 1, chunk_size = 1;
    
    // check input parameters
    if (argc <= 6){
        if (argc < 2){
            printUsage();
            exit(1);
        }            
        // parse the input parameters
        if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "-mp")){
            printf("Motion Estimation in process ...\n");
            if (argc < 4 || argc > 6){
                printUsage();
                exit(1);
            }
            // assign parameters
            input_img1 = argv[2];
            input_img2 = argv[3];
            if(strcmp(argv[1], "-m") == 0)
			{
				motion_estimation(input_img1, input_img2);
			}
			else
			{
				num_threads = 8;
                if (argc == 5){
                    num_threads = atoi(argv[4]);
                }
				motion_estimation_parallel(input_img1, input_img2, num_threads);
			}
            
        }
        else if (!strcmp(argv[1], "-c") || !strcmp(argv[1], "-cp")){
            printf("Corner Detection in process ...\n");
            if (argc < 3 || argc > 5){
                printUsage();
                exit(1);
            }
            // assign parameters
            input_img1 = argv[2];
            
			 if(strcmp(argv[1], "-c") == 0)
			{
				cornerDetectionSequential(input_img1);
			}
			else
			{
				num_threads = 8;
                if (argc == 4){
                    num_threads = atoi(argv[3]);
                }
				cornerDetectionParallel(input_img1, num_threads);
			}

            
        }
        else if (!strcmp(argv[1], "-r") || !strcmp(argv[1], "-rp")){
            printf("Rotation in process ...\n");
            if (argc < 4 || argc > 6){
                printUsage();
                exit(1);
            }
            // assign parameters
            input_img1 = argv[2];
            deg = atof(argv[3]);
            
            if (!strcmp(argv[1], "-r")){
                rotation(input_img1, deg);
            }
            else {
                // assigne the number of threads and chunk size
                if (argc == 5){
                    num_threads = atoi(argv[4]);
                }
                else {
                    num_threads = atoi(argv[4]);
                    chunk_size = atoi(argv[5]);
                }
                rotation_parallel(input_img1, deg, num_threads, chunk_size);
            }
        }
        else if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "-sp")){
            printf("Scaling in process ...\n");
            if (argc < 4 || argc > 6){
                printUsage();
                exit(1);
            }
            
            // --------------------Done by Mengyi Zhu----------------------------------
            //---------------------Here is scaling operation---------------------------
            //--------------------it will store the scaled version into scaling.bmp----
            // assign parameters
            input_img1 = argv[2];
            scale_fac = atof(argv[3]);
            num_threads = 1;
            
            //---------------------implemention the operation--------------------------
            if (!strcmp(argv[1], "-s"))
            	image_scaling(scale_fac, input_img1,"scaling.bmp");
            else if(!strcmp(argv[1], "-sp"))
            {
            	if (argc == 5)
            		num_threads = atoi(argv[4]);	
            	image_scaling_parallel(scale_fac, input_img1,"scaling.bmp", num_threads);
            }
            //-------------------------------------------------------------------------
            //-------------------------------------------------------------------------
            
        }
        else if (!strcmp(argv[1], "-g") || !strcmp(argv[1], "-gp")){
            printf("Gasussian Blur in process ...\n");
            if (argc < 4 || argc > 6){
                printUsage();
                exit(1);
            }
            // assign parameters
            input_img1 = argv[2];
            sigma = atof(argv[3]);
            
            if (!strcmp(argv[1], "-g")){
                gaussian_blur(input_img1, sigma);
            }
            else {
                // assigne the number of threads and chunk size
                if (argc == 5){
                    num_threads = atoi(argv[4]);
                }
                else {
                    num_threads = atoi(argv[4]);
                    chunk_size = atoi(argv[5]);
                }
                gaussian_blur_parallel(input_img1, sigma, num_threads, chunk_size);
            } 
            
        }
        else if (!strcmp(argv[1], "-o") || !strcmp(argv[1], "-op")){
            printf("Outline Detection in process ...\n");
            if (argc < 3 || argc > 5){
                printUsage();
                exit(1);
            }
            // assign parameters
            input_img1 = argv[2];
            
            // TODO: Ali, add your code here
            
        }
        else {
            if (argc == 6){
                printf("All-in-one in process ...\n");
                
                // assign parameters
                input_img1 = argv[1];
                input_img2 = argv[2];
                deg = atof(argv[3]);
                scale_fac = atof(argv[4]);
                sigma = atof(argv[5]);
                
                // Ding, add your sequential code here
                motion_estimation(input_img1, input_img2);
                // Michael's sequential code here
				cornerDetectionSequential(input_img1);
                // Haokun, add your sequential code here
                rotation(input_img1, deg);
                // --------------------Done by Mengyi Zhu---------------------------------
                //---------------------Here is scaling operation--------------------------
                //--------------------it will store the scaled version into scaling.bmp---
                image_scaling(scale_fac, input_img1,"scaling.bmp");
                //------------------------------------------------------------------------
                //------------------------------------------------------------------------
                // Xin, add your sequential code here
                gaussian_blur(input_img1, sigma);
                // TODO: Ali, add your sequential code here
            }
            else if (argc >= 7 && argc <= 9 && !strcmp(argv[1], "-p")){
                // assign parameters
                input_img1 = argv[2];
                input_img2 = argv[3];
                deg = atof(argv[4]);
                scale_fac = atof(argv[5]);
                sigma = atof(argv[6]);
                
                if (argc == 8){
                    num_threads = atoi(argv[7]);
                }
                else if (argc == 9){
                    num_threads = atoi(argv[7]);
                    chunk_size = atoi(argv[8]);
                }
                
                // Ding, add your parallel code here
                motion_estimation_parallel(input_img1, input_img2, num_threads);
                // Michael, add your parallel code here
				cornerDetectionParallel(input_img1,num_threads);
                // Haokun, add your parallel code here
                rotation_parallel(input_img1, deg, num_threads, chunk_size);
                // --------------------Done by Mengyi Zhu---------------------------------
                //---------------------Here is scaling operation-------------------------
                //--------------------it will store the scaled version into scaling.bmp----
                image_scaling_parallel(scale_fac, input_img1,"scaling.bmp", num_threads);
                //----------------------------------------------------------------------
                //----------------------------------------------------------------------
                // Xin, add your parallel code here
                gaussian_blur_parallel(input_img1, sigma, num_threads, chunk_size);
                // TODO: Ali, add your parallel code here
            }
            else {
                printf("Wrong option passed in or not enough parameters. Please refer the following usage.\n");
                printUsage();
                exit(1);
            }
        }
    }
    else {
        printUsage();
        exit(1);
    }
    
    return 0;   
}
void
detect_edges(Image *img, float sigma, float threshold, \
             unsigned char *edge_pix, PList *edge_pts)
{
	int x, y;
	int w = img->w;
	int h = img->h;

	// convert image to grayscale
	float **gray = array_create(w, h);
	convert_grayscale(img, gray);

	// blur grayscale image
	float **gray2 = array_create(w, h);
	gaussian_blur(gray, gray2, w, h, sigma);

	// compute gradient of blurred image
	float **g_mag = array_create(w, h);
	float **g_ang = array_create(w, h);
	compute_gradient(gray2, w, h, g_mag, g_ang);

	// mark edge pixels
	#define PIX(y,x) edge_pix[(y)*w+(x)]
#pragma omp parallel 
{
#pragma omp for private(x) nowait
	for (y = 0; y < h; y++)
	for (x = 0; x < w; x++)
	{
		PIX(y,x) = is_edge(g_mag,g_ang,threshold,x,y,w,h) ? 255 : 0;
	}

	// connect horizontal edges
#pragma omp for private(x) nowait
	for (y = 0; y < h  ; y++)
	for (x = 1; x < w-1; x++)
	{
		if (!PIX(y,x) && PIX(y,x+1) && PIX(y,x-1))
			PIX(y,x) = 255;
	}

	// connect vertical edges
#pragma omp for private(y) nowait
	for (x = 0; x < w  ; x++)
	for (y = 1; y < h-1; y++)
	{
		if (!PIX(y,x) && PIX(y+1,x) && PIX(y-1,x))
			PIX(y,x) = 255;
	}
#pragma omp for private(x) 
	// connect diagonal edges
	for (y = 1; y < h-1; y++)
	for (x = 1; x < w-1; x++)
	{
		if (!PIX(y,x) && PIX(y-1,x-1) && PIX(y+1,x+1))
			PIX(y,x) = 255;
		if (!PIX(y,x) && PIX(y-1,x+1) && PIX(y+1,x-1))
			PIX(y,x) = 255;
	}
}
	// add edge points to list
	if (edge_pts)
	{
		for (y = 0; y < h; y++)
		for (x = 0; x < w; x++)
		{
			if (PIX(y,x)) PList_push(edge_pts, x, y);
		}
	}

	// cleanup
	array_free(g_mag, h);
	array_free(g_ang, h);
	array_free(gray2, h);
	array_free(gray, h);
}
Esempio n. 9
0
int main(void)
{
    unsigned error;
    unsigned char* image;
    unsigned width, height;
    unsigned char* png;
    size_t pngsize;
    LodePNGState state;
    char filename[] = "handmaze.png";  /* NAME OF INPUT IMAGE */

    lodepng_state_init(&state);
    /*optionally customize the state*/
    state.info_raw.colortype = LCT_GREY;

    lodepng_load_file(&png, &pngsize, filename);
    error = lodepng_decode(&image, &width, &height, &state, png, pngsize);
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));

    free(png);

    /*use image here*/
    //printf("Width=%d Height=%d\n", width, height);
    
    //FILE * fp;
    //fp = fopen("imgout.txt", "w");
    //fp = fopen("imgout.ram", "wb");
    //int i,x,y;
    //char * ramimg = (char*) calloc(2*width*height, sizeof(char));
    //for(i = 0; i < 2*width*height; i++){
        //fprintf(fp, "%d (%d,%d)=%d\n", i, i%width, i/width, image[i]);
    //    if(i%2 == 0)
    //        ramimg[i] = image[i/2];
    //    else
    //        ramimg[i] = 0;
    //}
    //fwrite(ramimg, sizeof(unsigned char), 2*width*height, fp);
    //free(ramimg);
    //fclose(fp);
    //for(y = 0; y < height; y++) {
    //    for(x = 0; x < width; x++) {
    //        fprintf(fp, "(%d,%d)=%d\n", x, y, image[coords(x,y,width,height)]);
    //    }
    //}
    
    unsigned char * gaussimg = (unsigned char*) calloc(width*height, sizeof(char));
    unsigned char * outimg = (unsigned char*) calloc(width*height, sizeof(char));
    gaussian_blur(width, height, image, gaussimg);
    sobel_filtering(width, height, gaussimg, outimg);
    
    int right_coord, startx, starty, index1=6, index2=5;
    int block_size =blocksize(width, height, image, &startx, &starty, 7, &right_coord, index1, index2);
    //printf("blocksize = %d\n", block_size);
    
    int solver;
    unsigned char path[144];
    int *size=(int *) malloc(sizeof(int));
    *size = 0;

    solver = dfs(width,height,image, startx, starty, startx, starty, block_size, path, size);
    
    //printf("size = %d\n", *size);
    int i1;
    for(i1 = *size; i1 >= 0; i1--)
    {
        printf("%c\n", path[i1]);
    }
    
    //int x, y;
    //for(x = 0; x < width; x++)
    //{
    //    for(y = 0; y < height; y++)
    //    {
    //        outimg[coords(x,y,width,height)] = image[coords(x,y,width,height)];
    //    }
    //}
    
    unsigned char* outpng;
    error = lodepng_encode(&outpng, &pngsize, outimg, width, height, &state);
    if(!error) lodepng_save_file(outpng, pngsize, "sobel.png");  /* NAME OF OUTPUT IMAGE */
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
    
    
    
    /* CLEANUP */
    lodepng_state_cleanup(&state);
    free(image);
    free(outimg);
    
    return 0;
}