Example #1
0
   void load_pgm(const char* name, uchar* &im, int &height, int& width)
   {
      char buf[PNM_BUFFER_SIZE];

      /* read header */
      std::ifstream file(name, std::ios::in | std::ios::binary);
      pnm_read(file, buf);
      if (strncmp(buf, "P5", 2))
      {
         printf("type mismatch\n");
         exit(1);
      }

      pnm_read(file, buf);
      width = atoi(buf);

      pnm_read(file, buf);
      height = atoi(buf);

      pnm_read(file, buf);
      if (atoi(buf) > UCHAR_MAX)
      {
         printf("type mismatch\n");
         exit(1);
      }

      /* read data */
      if( im != NULL ) delete[] im;
      im = new uchar[width*height];
      file.read( (char *)im, width * height * sizeof(uchar));
   }
Example #2
0
   void load_pbm(const char* name, uchar* &im, int &height, int &width)
   {
      char buf[PNM_BUFFER_SIZE];

      /* read header */
      std::ifstream file(name, std::ios::in | std::ios::binary);
      pnm_read(file, buf);
      if (strncmp(buf, "P4", 2))
      {
         printf("type mismatch\n");
         exit(1);
      }

      pnm_read(file, buf);
      width = atoi(buf);

      pnm_read(file, buf);
      height = atoi(buf);

      /* read data */
      if( im != NULL) delete[]im;
      im = new uchar[width*height];
      for (int i = 0; i < height; i++)
         read_packed(im+(width*i), width, file);
   }
Example #3
0
Image<unsigned char>* loadPGM(const char* name)
{
	char buf[BUF_SIZE];

	// Read header
	std::ifstream file(name, std::ios::in | std::ios::binary);
	pnm_read(file, buf);
	if (strncmp(buf, "P5", 2))
		throw pnm_error();

	pnm_read(file, buf);
	int width = atoi(buf);
	pnm_read(file, buf);
	int height = atoi(buf);

	pnm_read(file, buf);
	if(atoi(buf) > UCHAR_MAX)
		throw pnm_error();

	// Read data
	Image<unsigned char> *im = new Image<unsigned char>(width, height);
	file.read((char *)imPtr(im, 0, 0), width*height*sizeof(unsigned char));

	return im;
}
Example #4
0
int main(int argv, char** argc) {
    printf("\n\nRunning code for question 1.11:\n\n");

    int		train_area1[4] = {150-1,330-1,264-1,328-1};

    /*read images from file*/
    pnm_img	* kande1 = pnm_read(IMG_IN_DIR "kande1.pnm"),
              * kande2 = pnm_read(IMG_IN_DIR "kande2.pnm");

    pnm_img	* train_img =pnm_subimage(kande1, train_area1);
    mtrx	* train_set = img2train_set(train_img);
    vect	* s_mean = sample_mean(train_set);
    mtrx	* s_cov = sample_cov(train_set, s_mean);


    double* map = (double*)malloc(kande2->width*kande2->height*sizeof(double));
    pdf_map(kande2, s_mean,s_cov,&map);

    vect* w_mean = weighted_avg_pos(kande2, map);

    pnm_pixmap p = {0,255,0};
    for (int x = -2; x<4; x++)
        for (int y=-2; y<4; y++) {
            pnm_set_pixel(kande2, (*w_mean->data)+x, *(w_mean->data+1)+y, &p);
        }
    //	pnm_write(kande1, IMG_OUT_DIR"cas10center.pnm");

    mtrx* w_cov = weighted_2dcov(map, w_mean, kande2);

    FILE* fp = fopen(TEX_OUT_DIR"c11.tex", "w");
    vect2tex(w_mean, "celevenwmean", fp);
    mtrx2tex(w_cov, "celevenwcov", fp);
    fclose(fp);

    gplot_img2splot(kande2, 0 ,TEX_OUT_DIR"case11.kande2.gnuplot.dat");
    gplot_pdf2splot(w_mean, w_cov, kande2, 5, TEX_OUT_DIR"case11.pdf.gnuplot.dat");

    gsl_matrix_free(train_set);
    gsl_matrix_free(s_cov);

    gsl_vector_free(s_mean);
    pnm_destroy(kande1);
    pnm_destroy(train_img);
}
Example #5
0
   void get_size_ppm(const char *name, int &height, int &width)
   {
      char buf[PNM_BUFFER_SIZE];
      //char doc[PNM_BUFFER_SIZE]
      // read header
      std::ifstream file(name, std::ios::in | std::ios::binary);
      pnm_read(file, buf);
      if (strncmp(buf, "P6", 2))
      {
         printf("type mismatch\n");
         exit(1);
      }

      pnm_read(file, buf);
      width = atoi(buf);

      pnm_read(file, buf);
      height = atoi(buf);

      file.close();
      return;
   }
Example #6
0
static off_t pnm_plugin_read (input_plugin_t *this_gen,
                              void *buf_gen, off_t len) {
  pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
  char *buf = (char *)buf_gen;
  off_t               n;

  lprintf ("pnm_plugin_read: %"PRId64" bytes ...\n", len);

  n = pnm_read (this->pnm, buf, len);
  if (n >= 0)
    this->curpos += n;

  return n;
}
Example #7
0
static off_t pnm_plugin_read (input_plugin_t *this_gen, 
                              char *buf, off_t len) {
  pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
  off_t               n;

#ifdef LOG
  printf ("pnm_plugin_read: %lld bytes ...\n",
          len);
#endif

  nbc_check_buffers (this->nbc);

  n = pnm_read (this->pnm, buf, len);
  this->curpos += n;

  return n;
}