コード例 #1
0
ファイル: imgpro.cpp プロジェクト: azrosen92/comp_vision
int 
main(int argc, char **argv)
{
  // Look for help
  for (int i = 0; i < argc; i++) {
    if (!strcmp(argv[i], "-help")) {
      ShowUsage();
    }
	if (!strcmp(argv[i], "-svdTest")) {
      R2Image *image = new R2Image();
	  image->svdTest();
	  return 0;
    }
  }

  // Read input and output image filenames
  if (argc < 3)  ShowUsage();
  argv++, argc--; // First argument is program name
  char *input_image_name = *argv; argv++, argc--; 
  char *output_image_name = *argv; argv++, argc--; 

  // Allocate image
  R2Image *image = new R2Image();
  if (!image) {
    fprintf(stderr, "Unable to allocate image\n");
    exit(-1);
  }

  // Read input image
  if (!image->Read(input_image_name)) {
    fprintf(stderr, "Unable to read image from %s\n", input_image_name);
    exit(-1);
  }

  // Initialize sampling method
  int sampling_method = R2_IMAGE_POINT_SAMPLING;

  // Parse arguments and perform operations 
  while (argc > 0) {
    if (!strcmp(*argv, "-brightness")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -=2;
      image->Brighten(factor);
    }
	else if (!strcmp(*argv, "-sobelX")) {
      argv++, argc--;
      image->SobelX();
    }
	else if (!strcmp(*argv, "-sobelY")) {
      argv++, argc--;
      image->SobelY();
    }
	else if (!strcmp(*argv, "-log")) {
      argv++, argc--;
      image->LoG();
    }
    else if (!strcmp(*argv, "-saturation")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -= 2;
      image->ChangeSaturation(factor);
    }
	else if (!strcmp(*argv, "-harris")) {
      CheckOption(*argv, argc, 2);
      double sigma = atof(argv[1]);
      argv += 2, argc -= 2;
      image->Harris(sigma);
    }
    else if (!strcmp(*argv, "-blur")) {
      CheckOption(*argv, argc, 2);
      double sigma = atof(argv[1]);
      argv += 2, argc -= 2;
      image->Blur(sigma);
    }
    else if (!strcmp(*argv, "-sharpen")) {
      argv++, argc--;
      image->Sharpen();
    }
    else if (!strcmp(*argv, "-matchTranslation")) {
      CheckOption(*argv, argc, 2);
      R2Image *other_image = new R2Image(argv[1]);
      argv += 2, argc -= 2;
      image->blendOtherImageTranslated(other_image);
      delete other_image;
    }
    else if (!strcmp(*argv, "-matchHomography")) {
      CheckOption(*argv, argc, 2);
      R2Image *other_image = new R2Image(argv[1]);
      argv += 2, argc -= 2;
      image->blendOtherImageHomography(other_image);
      delete other_image;
    }
    else {
      // Unrecognized program argument
      fprintf(stderr, "image: invalid option: %s\n", *argv);
      ShowUsage();
    }
  }

  // Write output image
  if (!image->Write(output_image_name)) {
    fprintf(stderr, "Unable to read image from %s\n", output_image_name);
    exit(-1);
  }

  // Delete image
  delete image;

  // Return success
  return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: raypro.cpp プロジェクト: freezeflare/cos426-assign3
int 
main(int argc, char **argv)
{
  // Look for help
  for (int i = 0; i < argc; i++) {
    if (!strcmp(argv[i], "-help")) {
      ShowUsage();
    }
  }

  // Read input and output filenames
  if (argc < 3)  ShowUsage();
  argv++, argc--; // First argument is program name
  char *input_scene_name = *argv; argv++, argc--; 
  char *output_image_name = *argv; argv++, argc--; 

  // Initialize arguments to default values
  int width = 256;
  int height = 256;
  int max_depth = 0;
  int num_distributed_rays_per_intersection = 0;
  int num_primary_rays_per_pixel = 1;
	bool hard_shadow = false;

  // Parse arguments 
  while (argc > 0) {
    if (!strcmp(*argv, "-width")) {
      CheckOption(*argv, argc, 2);
      width = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
    else if (!strcmp(*argv, "-height")) {
      CheckOption(*argv, argc, 2);
      height = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
    else if (!strcmp(*argv, "-max_depth")) {
      CheckOption(*argv, argc, 2);
      max_depth = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
    else if (!strcmp(*argv, "-antialias")) {
      CheckOption(*argv, argc, 2);
      num_primary_rays_per_pixel = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
    else if (!strcmp(*argv, "-distribute")) {
      CheckOption(*argv, argc, 2);
      num_distributed_rays_per_intersection = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
		else if (!strcmp(*argv, "-hard_shadow")) {
			hard_shadow = true;
			argv += 1, argc -= 1;
		}
    else {
      // Unrecognized program argument
      fprintf(stderr,  "meshpro: invalid option: %s\n", *argv);
      ShowUsage();
    }
  }

  // Read scene
  R3Scene *scene = ReadScene(input_scene_name, width, height);
  if (!scene) {
    fprintf(stderr, "Unable to read scene from %s\n", input_scene_name);
    exit(-1);
  }

  // Render image
  R2Image *image = RenderImage(scene, width, height, max_depth, 
    num_primary_rays_per_pixel, num_distributed_rays_per_intersection, hard_shadow);
  if (!image) {
    fprintf(stderr, "Did not render image from scene\n");
    exit(-1);
  }

  // Transfer the image to sRGB color space: for Windows + Linux and Mac OS X
  // 10.6+ (for earlier MAC OS X it will look slightly too bright, but not as
  // much as it would be too dark otherwise. This function also clamps the 
  // image values; however, it does not scale the brightness and also does not
  // perform any more complicated tone mapping
  image->TosRGB();

  // Write output image
  if (!image->Write(output_image_name)) {
    fprintf(stderr, "Did not write image to %s\n", output_image_name);
    exit(-1);
  }

  // Delete everything
  delete scene;
  delete image;

  // Return success
  return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: imgpro.cpp プロジェクト: freezeflare/COS-426
int 
main(int argc, char **argv)
{
  // Look for help
  for (int i = 0; i < argc; i++) {
    if (!strcmp(argv[i], "-help")) {
      ShowUsage();
    }
  }

  // Read input and output image filenames
  if (argc < 3)  ShowUsage();
  argv++, argc--; // First argument is program name
  char *input_image_name = *argv; argv++, argc--; 
  char *output_image_name = *argv; argv++, argc--; 

  // Allocate image
  R2Image *image = new R2Image();
  if (!image) {
    fprintf(stderr, "Unable to allocate image\n");
    exit(-1);
  }

  // Read input image
  if (!image->Read(input_image_name)) {
    fprintf(stderr, "Unable to read image from %s\n", input_image_name);
    exit(-1);
  }

  // Initialize sampling method
  int sampling_method = R2_IMAGE_POINT_SAMPLING;

  // Parse arguments and perform operations 
  while (argc > 0) {
    if (!strcmp(*argv, "-bilateral")) {
      CheckOption(*argv, argc, 3);
      double sx = atof(argv[1]);
      double sy = atof(argv[2]);
      argv += 3, argc -= 3;
      image->BilateralFilter(sy, sx);
    } 
    else if (!strcmp(*argv, "-blackandwhite")) {
      argv++, argc--;
      image->BlackAndWhite();
    }
    else if (!strcmp(*argv, "-blur")) {
      CheckOption(*argv, argc, 2);
      double sigma = atof(argv[1]);
      argv += 2, argc -= 2;
      image->Blur(sigma);
    }
    else if (!strcmp(*argv, "-brightness")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -=2;
      image->Brighten(factor);
    }
    else if (!strcmp(*argv, "-composite")) {
      CheckOption(*argv, argc, 5);
      R2Image *top_image = new R2Image(argv[2]);
      R2Image *bottom_mask = new R2Image(argv[1]);
      R2Image *top_mask = new R2Image(argv[3]);
      int operation = atoi(argv[4]);
      argv += 5, argc -= 5;
      image->CopyChannel(*bottom_mask, R2_IMAGE_BLUE_CHANNEL, R2_IMAGE_ALPHA_CHANNEL);
      top_image->CopyChannel(*top_mask, R2_IMAGE_BLUE_CHANNEL, R2_IMAGE_ALPHA_CHANNEL);
      image->Composite(*top_image, operation);
      delete top_image;
      delete bottom_mask;
      delete top_mask;
    }
    else if (!strcmp(*argv, "-contrast")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -= 2;
      image->ChangeContrast(factor);
    }
    else if (!strcmp(*argv, "-crop")) {
      CheckOption(*argv, argc, 5);
      int x = atoi(argv[1]);
      int y = atoi(argv[2]);
      int w = atoi(argv[3]);
      int h = atoi(argv[4]);
      argv += 5, argc -= 5;
      image->Crop(x, y, w, h);
    }
    else if (!strcmp(*argv, "-dither")) {
      CheckOption(*argv, argc, 3);
      int dither_method = atoi(argv[1]);
      int nbits = atoi(argv[2]);
      argv += 3, argc -= 3;
      if (dither_method == 0) image->RandomDither(nbits);
      else if (dither_method == 1) image->OrderedDither(nbits);
      else if (dither_method == 2) image->FloydSteinbergDither(nbits);
      else { fprintf(stderr, "Invalid dither method: %d\n", dither_method); exit(-1); }
    }
    else if (!strcmp(*argv, "-edge")) {
      argv++, argc--;
      image->EdgeDetect();
    } 
    else if (!strcmp(*argv, "-extract")) {
      CheckOption(*argv, argc, 2);
      int channel = atoi(argv[1]);
      argv += 2, argc -= 2;
      image->ExtractChannel(channel);
    }
    else if (!strcmp(*argv, "-fun")) {
      image->Fun(sampling_method);
      argv++, argc--;
    }
    else if (!strcmp(*argv, "-gamma")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -= 2;
      image->ApplyGamma(factor);
    }
    else if (!strcmp(*argv, "-median")) {
      CheckOption(*argv, argc, 2);
      double sigma = atof(argv[1]);
      argv += 2, argc -= 2;
      image->MedianFilter(sigma);
    }
    else if (!strcmp(*argv, "-motionblur")) {
      CheckOption(*argv, argc, 1);
      int amount = atoi(argv[1]);
      argv += 2, argc -= 2;
      image->MotionBlur(amount);
    }
    else if (!strcmp(*argv, "-morph")) {
      int nsegments = 0;
      R2Segment *source_segments = NULL;
      R2Segment *target_segments = NULL;
      CheckOption(*argv, argc, 4);
      R2Image *target_image = new R2Image(argv[1]);
      ReadCorrespondences(argv[2], source_segments, target_segments, nsegments);
      double t = atof(argv[3]);
      argv += 4, argc -= 4;
      image->Morph(*target_image, source_segments, target_segments, nsegments, t, sampling_method);
      delete target_image;
    }
    else if (!strcmp(*argv, "-noise")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -= 2;
      image->AddNoise(factor);
    }
    else if (!strcmp(*argv, "-quantize")) {
      CheckOption(*argv, argc, 2);
      int nbits = atoi(argv[1]);
      argv += 2, argc -= 2;
      image->Quantize(nbits);
    }
    else if (!strcmp(*argv, "-rotate")) {
      CheckOption(*argv, argc, 2);
      double angle = atof(argv[1]);
      argv += 2, argc -= 2;
      image->Rotate(angle, sampling_method);
    }
    else if (!strcmp(*argv, "-sampling")) {
      CheckOption(*argv, argc, 2);
      sampling_method = atoi(argv[1]);
      argv += 2, argc -= 2;
    }
    else if (!strcmp(*argv, "-saturation")) {
      CheckOption(*argv, argc, 2);
      double factor = atof(argv[1]);
      argv += 2, argc -= 2;
      image->ChangeSaturation(factor);
    }
    else if (!strcmp(*argv, "-scale")) {
      CheckOption(*argv, argc, 3);
      double sx = atof(argv[1]);
      double sy = atof(argv[2]);
      argv += 3, argc -= 3;
      image->Scale(sx, sy, sampling_method);
    }
    else if (!strcmp(*argv, "-sharpen")) {
      argv++, argc--;
      image->Sharpen();
    }
    else {
      // Unrecognized program argument
      fprintf(stderr, "image: invalid option: %s\n", *argv);
      ShowUsage();
    }
  }

  // Write output image
  if (!image->Write(output_image_name)) {
    fprintf(stderr, "Unable to write image to %s\n", output_image_name);
    exit(-1);
  }

  // Delete image
  delete image;

  // Return success
  return EXIT_SUCCESS;
}