Example #1
0
cv::Mat contrastR2(cv::Mat img1,cv::Mat img2,double coeff1,double coeff2)
{
	cv::Mat img3(img1.rows,img1.cols,CV_32FC1);
	float a,b,min=10000;
	
	cv::MatIterator_<uchar> it1 = img1.begin<uchar>(),it_end1 = img1.end<uchar>();
	cv::MatIterator_<uchar> it2 = img2.begin<uchar>(),it_end2 = img2.end<uchar>();
	cv::MatIterator_<float> it3 = img3.begin<float>(),it_end3 = img3.end<float>();
	
	for(; it1 != it_end1; ++it1)
	{
		a=2*coeff1*(*it1)-coeff2*(*it2);
		b=coeff1*(*it2)+5;
		if (b<1)
		{
			*it3=510;
		}
		else
		{
			*it3=510*a/b;
		}
		if (*it3<min) min=*it3;
		it2++;it3++;
	}
	std::cout<<min<<std::endl;
	it3 = img3.begin<float>();
	it_end3 = img3.end<float>();
	
	for(; it3 != it_end3; ++it3)
	{
		*it3=*it3-min;
	}
	
	return img3;
}
TEST_F(for_each_channel_accumulate_test, should_throw_when_image_dimensions_dont_match)
{
    rgb16_image_t img1(1, 2), img2(1, 3), img3(2, 2);

    auto zero = [](channel16_t, channel16_t) { return 0; };
    ASSERT_THROW(for_each_channel_accumulate(const_view(img1), const_view(img2), 0, zero), std::invalid_argument);
    ASSERT_THROW(for_each_channel_accumulate(const_view(img1), const_view(img3), 0, zero), std::invalid_argument);
}
Example #3
0
void
PNGTests::testWriter() {
  static const int width  = 256;
  static const int height = 256;

  // create an image and fill it with random data
  auto_ptr<Image> image(CreateImage(width, height, PF_R8G8B8A8));
  setRandomBytes((byte*)image->getPixels(), width * height * 4);

  // generate filename
  char* filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file", filename != 0);

  // save image
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, image.get()) == true);

  // load it back
  auto_ptr<Image> img2(OpenImage(filename, PF_R8G8B8A8));
  CPPUNIT_ASSERT_MESSAGE("reloading image file", img2.get() != 0);

  AssertImagesEqual(
    "comparing saved with loaded",
    image.get(),
    img2.get());

  // force pixel format conversion (don't destroy the old image)
  auto_ptr<Image> img3(OpenImage(filename, PF_R8G8B8));
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, img3.get()) == true);

  remove(filename);


  //== PALETTIZED SAVING TEST ==
  // disabled until loading palettized PNGs with a correct palette format
  // is implemented.
#if 0
  char* plt_filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file (palette)", plt_filename != 0);
  auto_ptr<Image> plt(CreateImage(256, 256, PF_I8, 256, PF_R8G8B8));
  setRandomBytes((byte*)plt->getPixels(), 256 * 256);
  setRandomBytes((byte*)plt->getPalette(), 256);

  CPPUNIT_ASSERT(SaveImage(plt_filename, FF_PNG, plt.get()) == true);

  auto_ptr<Image> plt2(OpenImage(plt_filename, FF_PNG));
  CPPUNIT_ASSERT_MESSAGE("reloading palettized image", plt2.get() != 0);
  CPPUNIT_ASSERT(plt2->getPaletteSize() == 256);
  CPPUNIT_ASSERT(plt2->getPaletteFormat() == PF_R8G8B8);
  CPPUNIT_ASSERT(plt2->getFormat() == PF_I8);
  AssertImagesEqual("Comparing palettized image", plt.get(), plt2.get());

  remove(plt_filename);
#endif
}
Example #4
0
void TextureSplatting::onPluginLoad(){
	// VS + FS
  vs=new QGLShader(QGLShader::Vertex, this);
  vs->compileSourceFile("/home/llop/Llop/FIB/2015-2016QT/G/Lab/NewViewer/plugins/texture-splatting/texture-splatting.vert");
  fs=new QGLShader(QGLShader::Fragment, this);
  fs->compileSourceFile("/home/llop/Llop/FIB/2015-2016QT/G/Lab/NewViewer/plugins/texture-splatting/texture-splatting.frag");
  
	// Program  
	program=new QGLShaderProgram(this);
  program->addShader(vs);
	program->addShader(fs);
	program->link();

	// Load noise
	glActiveTexture(GL_TEXTURE0);
	QString noiseFilename = QFileDialog::getOpenFileName(0, "Open Noise Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)");	
	QImage img3(noiseFilename);	
	QImage im3=QGLWidget::convertToGLFormat(img3);
	glGenTextures( 1, &noiseId);
	glBindTexture(GL_TEXTURE_2D, noiseId);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im3.width(), im3.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im3.bits());
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glBindTexture(GL_TEXTURE_2D, 0);

	// Load Texture 1
	glActiveTexture(GL_TEXTURE0);
	QString filename = QFileDialog::getOpenFileName(0, "Open Rock Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)");	
	QImage img0(filename);	
	QImage im0 = QGLWidget::convertToGLFormat(img0);
	glGenTextures( 1, &textureId0);
	glBindTexture(GL_TEXTURE_2D, textureId0);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im0.width(), im0.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im0.bits());
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glBindTexture(GL_TEXTURE_2D, 0);

	// Load Texture 2
	glActiveTexture(GL_TEXTURE1);
	QString filename2 = QFileDialog::getOpenFileName(0, "Open Grass Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)");	
	QImage img1(filename2);	
	QImage im1 = QGLWidget::convertToGLFormat(img1);
	glGenTextures( 1, &textureId1);
	glBindTexture(GL_TEXTURE_2D, textureId1);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im1.width(), im1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im1.bits());
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glBindTexture(GL_TEXTURE_2D, 0);
}
Example #5
0
ObjectSettings
Background::get_settings() {
  ObjectSettings result = GameObject::get_settings();
  result.options.push_back( ObjectOption(MN_INTFIELD, _("Z-pos"), &layer, "z-pos"));
  ObjectOption align(MN_STRINGSELECT, _("Alignment"), &alignment);
  align.select.push_back(_("none"));
  align.select.push_back(_("left"));
  align.select.push_back(_("right"));
  align.select.push_back(_("top"));
  align.select.push_back(_("bottom"));
  result.options.push_back(align);
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Scroll offset x"),
                                         &scroll_offset.x, "scroll-offset-x"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Scroll offset y"),
                                         &scroll_offset.y, "scroll-offset-y"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Scroll speed x"),
                                         &scroll_speed.x, "scroll-speed-x"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Scroll speed y"),
                                         &scroll_speed.y, "scroll-speed-y"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Speed x"), &speed, "speed"));
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Speed y"), &speed_y));

  ObjectOption img(MN_FILE, _("Top image"), &imagefile_top, "image-top", (OPTION_VISIBLE));
  img.select.push_back(".png");
  img.select.push_back(".jpg");
  img.select.push_back(".gif");
  img.select.push_back(".bmp");
  result.options.push_back(img);
  ObjectOption img2(MN_FILE, _("Image"), &imagefile, "image");
  img2.select = img.select;
  ObjectOption img3(MN_FILE, _("Bottom image"), &imagefile_bottom, "image-bottom", (OPTION_VISIBLE));
  img3.select = img.select;
  result.options.push_back(img2);
  result.options.push_back(img3);

  result.options.push_back( ObjectOption(MN_REMOVE, "", NULL));
  return result;
}