int main(int argc, char *argv[]) {

    clock_t seq_clk = clock();

    int numberOfTrainingPictures = atoi(argv[1]);

    int ***trainingSet = (int ***)malloc(sizeof(int **) * NUM_PEOPLE);

    for (int i=0; i<NUM_PEOPLE; i++) {
        trainingSet[i] = alloc_2d_matrix(numberOfTrainingPictures, MAX_DECIMAL_VALUE);
    }
    //trainingSet is a 3d matrix now (person x image x histogramIndex )

    double seq_time = clock() - seq_clk;

    double parallel_clk = omp_get_wtime();

    #pragma omp parallel
    {
        #pragma omp for
        for (int i=0; i<NUM_PEOPLE; i++) {
            char filename[256];
            for (int j=0; j<numberOfTrainingPictures; j++) {
                sprintf(filename, "images/%d.%d.txt", i+1, j+1);
                int **image = read_pgm_file(filename, IMAGE_R, IMAGE_R);
                create_histogram(trainingSet[i][j], image, IMAGE_R, IMAGE_W);
                free(image);
            }
        }
    }

    int correct_answers = 0;
    #pragma omp parallel
    {
        #pragma omp for reduction(+:correct_answers)
        for (int i=0; i<NUM_PEOPLE; i++) {
            for (int j=numberOfTrainingPictures; j<NUM_PICS_PER_PERSON; j++) {
                int *test_histogram = (int *)malloc(sizeof(int) * MAX_DECIMAL_VALUE);
                char filename[256];
                sprintf(filename, "images/%d.%d.txt", i+1, j+1);
                int **image = read_pgm_file(filename, IMAGE_R, IMAGE_R);
                create_histogram(test_histogram, image, IMAGE_R, IMAGE_W);

                int predicted = find_closest(trainingSet, NUM_PEOPLE, numberOfTrainingPictures, MAX_DECIMAL_VALUE, test_histogram) + 1;

                printf("%s %d %d\n", filename+7, predicted, i+1);
                if(i+1 == predicted) {
                    correct_answers++;
                }
            }
        }
    }
    printf("Accuracy: %d correct answers for %d tests\n", correct_answers, NUM_PEOPLE * (NUM_PICS_PER_PERSON - numberOfTrainingPictures));
    printf("Parallel time: %lf\n", omp_get_wtime() - parallel_clk);
    printf("Sequential time: %lf\n", seq_time/CLOCKS_PER_SEC);
    return 0;
}
Example #2
0
//  BPW -- this really doesn't have anything to do with "edgemate" but
//  it's commonly called with check_symmetry_of_the_edge_mates(), and
//  they're both disabled.
//
void count_fragment_and_edge_labels(Tfragment frags[],
                                    Tedge     edges[],
                                    char      comment[]) {
  FILE *fout = stderr;

  fprintf(stderr, "count_fragment_and_edge_labels()--  Disabled.\n");
  return;

  const int nsample=500;
  const int nbucket=500;

  IntFragment_ID nfrag = GetNumFragments(frags);
  IntFragment_ID vid;
  Histogram_t *frag_lab_histogram = create_histogram(nsample,nbucket,TRUE,FALSE);

  fprintf(fout,"*** Histogram Fragment Labels <%s> ***\n",comment);

  for(vid=0; vid<nfrag; vid++) {
    const Tlab ilab = get_lab_fragment(frags,vid);
    add_to_histogram(frag_lab_histogram, (int)ilab, NULL);
  }

  fprintf(fout,"Histogram of the fragment label \n");
  print_histogram(fout,frag_lab_histogram, 0, 1);
  free_histogram(frag_lab_histogram);

  IntEdge_ID ie;
  IntEdge_ID nedge = GetNumEdges(edges);
  Histogram_t *inter_chunk_edge_nes_histogram = create_histogram(nsample,nbucket,TRUE,FALSE);
  Histogram_t *intra_chunk_edge_nes_histogram = create_histogram(nsample,nbucket,TRUE,FALSE);

  fprintf(fout,
          "*** Histogram Edge Labels (2 edges/overlap) <%s> ***\n",
          comment);

  for(ie=0; ie<nedge; ie++) {
    const Tnes nes = get_nes_edge(edges,ie);
    const IntFragment_ID avx = get_avx_edge(edges,ie);
    const IntFragment_ID bvx = get_bvx_edge(edges,ie);
    const IntChunk_ID a_cid = get_cid_fragment(frags,avx);
    const IntChunk_ID b_cid = get_cid_fragment(frags,bvx);
    if( a_cid == b_cid ) {
      add_to_histogram(intra_chunk_edge_nes_histogram, (int)nes, NULL);
    } else {
      add_to_histogram(inter_chunk_edge_nes_histogram, (int)nes, NULL);
    }
  }

  fprintf(fout,"Histogram of the inter-chunk overlap labels \n");
  print_histogram(fout,inter_chunk_edge_nes_histogram, 0, 1);
  free_histogram(inter_chunk_edge_nes_histogram);

  fprintf(fout,"Histogram of the intra-chunk overlap labels \n");
  print_histogram(fout,intra_chunk_edge_nes_histogram, 0, 1);
  free_histogram(intra_chunk_edge_nes_histogram);
}
Example #3
0
int detect_obstacles()
{
	CvCapture* capture = 0;
	capture = cvCaptureFromCAM(0);
	IplImage *frame, *imHSV;
    cvNamedWindow("result", 0);	
    int Hthresh = 0;
    int Vthresh = 0;
    cvCreateTrackbar("hue thresh", "result", &Hthresh, 10000, NULL);
    cvCreateTrackbar("value thresh", "result", &Vthresh, 100, NULL);
    IplImage* h_plane ;
    IplImage* s_plane ;
    IplImage* v_plane ;
	for(;;)
	{
		frame = cvQueryFrame( capture );
		if(frame){
		  cvSmooth(frame, frame, CV_GAUSSIAN, 25, 25, 0, 0);
		  cvSetImageROI(frame, cvRect(0,(frame->height/2),frame->width, (frame->height/2)));
		  
		  h_plane = cvCreateImage( cvGetSize(frame ), 8, 1 );
		  s_plane = cvCreateImage( cvGetSize( frame), 8, 1 );
		  v_plane = cvCreateImage( cvGetSize( frame ), 8, 1 );
		  imHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
		  cvCvtColor(frame,imHSV,CV_BGR2HSV);
		  cvCvtPixToPlane( imHSV , h_plane, s_plane, v_plane, 0 );
		  CvHistogram* hist_h,*hist_v;
		  int h_bins = H_BINS, v_bins = V_BINS;
		  
		  hist_h = create_histogram(h_plane, H_MAX, &h_bins);
		  hist_v = create_histogram(v_plane, V_MAX, &v_bins);
		  
		  if(process_frame(frame, h_plane, v_plane, hist_h, hist_v, Hthresh, Vthresh)==-1)
		    break;
		}
		cvReleaseImage(&imHSV );
		cvReleaseImage(&h_plane );
		cvReleaseImage(&v_plane );
	}

	cvReleaseCapture( &capture );
	cvDestroyWindow("Display");

	//  cvDestroyWindow("FinalDisplay");
	cvDestroyWindow("VDisplay");
	cvDestroyWindow("Result");
	cvDestroyWindow("Display1");
	return 0;
}
Example #4
0
std::vector<unsigned long> create_histogram(const cv::Mat& mat, int channel)
{
	assert(channel >= 0 && channel < mat.channels());
	assert(mat.depth() == CV_8U);

	return create_histogram(mat.data + channel, mat.total(), mat.channels());
}
Example #5
0
  void histogramWorker()
  {
    CreateHistogramFunc create_histogram;

    while(!shutdown_)
    {
        if(histogram_queue_.pop_back(&create_histogram))
        {
          create_histogram();

          if(save_)
          {
            std::string name = create_histogram.name + "__hist";

            if(image_sequence_lookup_.find(name) == image_sequence_lookup_.end())
            {
              image_sequence_lookup_[name] = 0;
            }

            std::stringstream filename;
            filename << create_histogram.name << "_" << image_sequence_lookup_[name] << ".txt";

            create_histogram.save(filename.str());

            image_sequence_lookup_[name] += 1;
          }
        }
    }
  }
Example #6
0
 /* Create Histogram from extended sample data, using min/max from sd data
  */
 void create_histogram( const extended_sample_data_t& sd, size_t num_buckets )
 {
   if ( sd.simple || sd.data().empty() )
     return;
   double min = *std::min_element( sd.data().begin(), sd.data().end() );
   double max = *std::max_element( sd.data().begin(), sd.data().end() );
   create_histogram( sd, num_buckets, min, max );
 }
Example #7
0
 /* Create Histogram from timeline, using min/max from tl data
  */
 void create_histogram( const timeline_t& tl, size_t num_buckets )
 {
   if ( tl.data().empty() )
     return;
   double min = *std::min_element( tl.data().begin(), tl.data().end() );
   double max = *std::max_element( tl.data().begin(), tl.data().end() );
   create_histogram( tl, num_buckets, min, max );
 }
Example #8
0
vector<TH1F * > * create_histograms(int layers, int bins) {
  vector<TH1F * > * histograms = new vector<TH1F * >();

  for(int i = 1; i <= layers; ++i) {
    histograms->push_back(create_histogram(i, bins));
  }

  return histograms;
}
Example #9
0
std::vector<size_t> create_histogram( iterator begin, iterator end, size_t num_buckets )
{
    typedef typename std::iterator_traits<iterator>::value_type value_t;
    if ( begin == end )
        return std::vector<size_t>();

    value_t min = *std::min_element( begin, end );
    value_t max = *std::max_element( begin, end );

    return create_histogram( begin, end, num_buckets, min, max );
}
Example #10
0
    // Analyze collected data
    void analyze_all()
    {
        // Sort Data
        sort();

        analyze_basics();

        // Calculate Variance
        analyze_variance();

        create_histogram();
    }
int		main(int ac, char **av)
{
  Image		*img;
  int		*histogram;

  InitializeMagick("./");
  img = get_image_from_path(av[1]);
  img = get_grayscale_image(img);
  histogram = create_histogram(img);
  dump_histogram(histogram, av[2]);
  dump_image(img, "./", "gray", "jpeg");
  return (0);
}
Example #12
0
HISTOGRAM *create_extended_histogram(
			    int nsample,
			    int nbucket,
			    int sync,
			    int logarithmic,
			    int datasize,
			    AggregateFn aggregate,
			    PrintFn printdata,
			    PrintAg printag){
  HISTOGRAM *h = create_histogram(nsample, nbucket, sync, logarithmic);
  assert(datasize > 0);
  extend_histogram(h, datasize, aggregate, printdata, printag);

  return h;
}
Example #13
0
int main(int argc, char *argv[])
{
  histogram_t *myhist;
  struct timeval start, stop;

  double min, max;

  /* <app> bin_count file-name */
  if (argc < 4) {
    fprintf(stderr, "Invalid number of parameters\n");
    exit(EXIT_FAILURE);
  }

  char *filename;
  size_t bin_count = strtol(argv[1], NULL, 10);
  filename = argv[2];
  thread_count = atoi(argv[3]);

  read_data(filename, &count, &min, &max);

  pthread_mutex_init(&mutexsum, NULL);

  gettimeofday(&start, NULL);
  myhist = create_histogram(min, max, bin_count, thread_count);
  gettimeofday(&stop, NULL);

  double t = (((double)(stop.tv_sec)*1000.0  + (double)(stop.tv_usec / 1000.0)) - \
                   ((double)(start.tv_sec)*1000.0 + (double)(start.tv_usec / 1000.0)));

  fprintf(stdout, "Time elapsed = %g ms\n", t);

  print_histogram(myhist);

  // missing: deallocate memory

  return 0;
}
Example #14
0
int main(int argc, char** argv){
	
	begin = clock();
	int i, j;
	int b; 
	num_files = atoi(argv[1]);

	// 4d array to have 2 layers for height and width and 2 layers for files and people
	int**** pre_training_set = (int****)malloc(num_people * sizeof(int***));
	for(i = 0; i < num_people; i++){
		pre_training_set[i] = (int***)malloc(num_files * sizeof(int**));
	}
	char filename[128];
	// printf("Hello\n");

	for(i = 0; i < num_people; i++){
		for(j = 0; j < num_files; j++){
			sprintf(filename, "/home/cagdas/Desktop/parallel-project-3/images/%d.%d.txt", i+1, j+1);
			// printf("%s\n", filename);
			pre_training_set[i][j] = read_pgm_file(filename, rows, cols);
		}
	}

	// printf("Creating the training set\n");
	// the actual training set where the histogram arrays will be held for each file for each person (3 layers!)
	int*** training_set = (int***)malloc(num_people * sizeof(int**));
	for(i = 0; i < num_people; i++){
		training_set[i] = (int**)malloc(num_files * sizeof(int*));
	}

	// create histograms for each person's each picture
	for(i = 0; i < num_people; i++){
		for(j = 0; j < num_files; j++){
			// printf("Onto it with i %d j %d\n", i, j);
			training_set[i][j] = (int*)malloc(sizeof(int) * 256);
			beginp = clock();
			#pragma omp parallel for schedule(static)
			for(b = 0; b < 256; b++){
				training_set[i][j][b] = 0;
			}
			endp = clock();
			time_spentp += (double)(endp - beginp);
			create_histogram(training_set[i][j], pre_training_set[i][j], rows, cols);

		}
	}
	// printf("created the training set\n");
	// test files
	int**** pre_test_set = (int****)malloc(num_people * sizeof(int***));
	for(i = 0; i < num_people; i++){
		pre_test_set[i] = (int***)malloc(sizeof(int**) * (total_num_files - num_files));
	}

	// printf("pre test set\n");


	for(i = 0; i < num_people; i++){
		for(j = 0; j < (total_num_files - num_files); j++){
			sprintf(filename, "/home/cagdas/Desktop/parallel-project-3/images/%d.%d.txt", i+1, j+1+num_files);
			// printf("Current name is %s\n", filename);
			pre_test_set[i][j] = read_pgm_file(filename, rows, cols);
		}
	}
	
	// printf("created pre test set\n");
	int*** test_set = (int***)malloc(num_people * sizeof(int**));
	for(i = 0; i < num_people; i++){
		test_set[i] = (int**)malloc((total_num_files - num_files) * sizeof(int*));
		for(j = 0; j < total_num_files - num_files; j++){
			test_set[i][j] = (int*)malloc(sizeof(int) * 256);
			for(b = 0; b < 256; b++){
				test_set[i][j][b] = 0;
			}
			create_histogram(test_set[i][j], pre_test_set[i][j], rows, cols);
		}
	}
	// printf("np abi\n");
	int totalCount = 0;
	int falseCount = 0;
	for(i = 0; i < num_people; i++){
		for(j = 0; j < total_num_files - num_files; j++){
			int cur = find_closest(training_set, num_people, num_files, 256, test_set[i][j]);

			// test the file with file name "%d.%d.txt\t\t%d\t\t%d\n", i+1, j+1+num_files
			totalCount++;	// a judgment is made
			if(cur != i+1){ // a false judgment is made
				printf("%d.%d.txt\t\t%d\t\t%d\n", i+1, j+1+num_files, i+1, cur);
				falseCount += 1;
			}
		}
	}
	printf("Accuracy: %d correct answers for %d tests Parallel\n", totalCount - falseCount, totalCount);

	// TODO:: deallocate the allocated memory space

	int a;

	beginp = clock();
	#pragma omp parallel for schedule(static) private(j,a)
	for(i = 0; i < num_people; i++){
		for(j = 0; j < num_files; j++){
			for(a = 0; a < rows; a++){
				free(pre_training_set[i][j][a]);
			}
			free(pre_training_set[i][j]);
		}
		free(pre_training_set[i]);
	}
	endp = clock();
	time_spentp += (double)(endp - beginp);
	free(pre_training_set);
	// printf("free pre training set\n");

	#pragma omp parallel for schedule(static) private(j,a)
	for(i = 0; i < num_people; i++){
		for(j = 0; j < total_num_files - num_files; j++){
			for(a = 0; a < rows; a++){
				free(pre_test_set[i][j][a]);
			}
			free(pre_test_set[i][j]);
		}
		free(pre_test_set[i]);
	}
	free(pre_test_set);
	// printf("free pre test set\n");

	beginp = clock();
	#pragma omp parallel for schedule(static) private(j)
	for(i = 0; i < num_people; i++){
		for(j = 0; j < num_files; j++){
			free(training_set[i][j]);
		}
		free(training_set[i]);
	}
	endp = clock();
	time_spentp += (double)(endp - beginp);
	free(training_set);

	// printf("free training set\n");

	beginp = clock();
	#pragma omp parallel for schedule(static) private(j)
	for(i = 0; i < num_people; i++){
		for(j = 0; j < total_num_files - num_files; j++){
			free(test_set[i][j]);
		}
		free(test_set[i]);
	}
	endp = clock();
	time_spentp += (double)(endp - beginp);
	free(test_set);
	// printf("free test set\n");

	end = clock();
	time_spent = (double)(end-begin);
	printf("Total runtime: %f\n", time_spent/CLOCKS_PER_SEC);
	printf("Sequential runtime: %f\n", (time_spent - time_spentp)/CLOCKS_PER_SEC);

	return 0;
}
Example #15
0
void
Scene_c3t3_item::build_histogram()
{
#ifdef CGAL_MESH_3_DEMO_BIGGER_HISTOGRAM_WITH_WHITE_BACKGROUNG
  // Create an histogram_ and display it
  const int height = 280;
  const int top_margin = 5;
  const int left_margin = 20;
  const int drawing_height = height - top_margin * 2;
  const int width = 804;
  const int cell_width = 4;
  const int text_margin = 3;
  const int text_height = 34;

  histogram_ = QPixmap(width, height + text_height);
  histogram_.fill(QColor(255, 255, 255));
#else
  // Create an histogram_ and display it
  const int height = 140;
  const int top_margin = 5;
  const int left_margin = 20;
  const int drawing_height = height - top_margin * 2;
  const int width = 402;
  const int cell_width = 2;
  const int text_margin = 3;
  const int text_height = 20;

  histogram_ = QPixmap(width, height + text_height);
  histogram_.fill(QColor(192, 192, 192));
#endif  

  QPainter painter(&histogram_);
  painter.setPen(Qt::black);
  painter.setBrush(QColor(128, 128, 128));
  //painter.setFont(QFont("Arial", 30));

  // Build histogram_ data
  double min_value, max_value;
  std::vector<int> histo_data = create_histogram(c3t3(), min_value, max_value);

  // Get maximum value (to normalize)
  int max_size = 0;
  for (std::vector<int>::iterator it = histo_data.begin(), end = histo_data.end();
    it != end; ++it)
  {
    max_size = (std::max)(max_size, *it);
  }

  // colored histogram
  int j = 0;

  // draw
  int i = left_margin;
  for (std::vector<int>::iterator it = histo_data.begin(), end = histo_data.end();
    it != end; ++it, i += cell_width)
  {
    int line_height = static_cast<int>(std::ceil(static_cast<double>(drawing_height)*
      static_cast<double>(*it) / static_cast<double>(max_size)) + .5);

    painter.fillRect(i,
      drawing_height + top_margin - line_height,
      cell_width,
      line_height,
      get_histogram_color(j++));
  }

  // draw bottom horizontal line
  painter.setPen(Qt::blue);

  painter.drawLine(QPoint(left_margin, drawing_height + top_margin),
    QPoint(left_margin + static_cast<int>(histo_data.size())*cell_width,
    drawing_height + top_margin));


  // draw min value and max value
  const int min_tr_width = static_cast<int>(2 * (std::floor(min_value)*cell_width + left_margin));
  const int max_tr_width = static_cast<int>(
    2 * ((histo_data.size() - std::floor(max_value))*cell_width + left_margin));
  const int tr_y = drawing_height + top_margin + text_margin;

  painter.setPen(get_histogram_color(min_value));
  QRect min_text_rect(0, tr_y, min_tr_width, text_height);
  painter.drawText(min_text_rect, Qt::AlignCenter, tr("%1").arg(min_value, 0, 'f', 1));

  painter.setPen(get_histogram_color(max_value));
  QRect max_text_rect(width - max_tr_width, tr_y, max_tr_width, text_height);
  painter.drawText(max_text_rect, Qt::AlignCenter, tr("%1").arg(max_value, 0, 'f', 1));
}
Example #16
0
std::vector<double> create_normalized_histogram( iterator begin, iterator end, size_t num_buckets, typename std::iterator_traits<iterator>::value_type min, typename std::iterator_traits<iterator>::value_type max )
{
    return normalize_histogram( create_histogram( begin, end, num_buckets, min, max ) );
}
Example #17
0
std::vector<unsigned long> CVMatProvider::createHistogram(unsigned char number) const
{
	assert(number < m_original.channels());

	return create_histogram(m_mat, number);
}
Example #18
0
std::vector<double> create_normalized_histogram( iterator begin, iterator end, size_t num_buckets )
{
    return normalize_histogram( create_histogram( begin, end, num_buckets ) );
}