Exemple #1
0
void ppm_export(const image& r, const image& g, const image& b, const boost::filesystem::path& path)
{
  if(exists(path))
  {
    std::cerr << "Error exporting to PPM! File "
	      << path << " already exists." << std::endl;
    exit(1);
  }

  boost::filesystem::ofstream ppm(path);

  ppm << "P3\n"
      << r.width() << ' ' << r.height() << '\n'
      << 255 << '\n';

  for(int y = 0; y < r.height(); ++y)
  {
    for(int x = 0; x < r.width(); ++x){
      ppm << static_cast<int>(r.pixel(x, y)) << ' ';
      ppm << static_cast<int>(g.pixel(x, y)) << ' ';
      ppm << static_cast<int>(b.pixel(x, y)) << ' ';
    }
    ppm << '\n';
  }
}
            virtual BOOL on_draw(HELEMENT he, UINT draw_type, HDC hdc, const
                RECT &rc)
            {
                if ((DRAW_EVENTS)draw_type != where)
                    return FALSE;
                // do default draw
                int w = rc.right - rc.left;
                int h = rc.bottom - rc.top;
                if (!surface)
                {
                    surface = image::create(w, h);
                    redraw = true;
                }
                else if (w != surface->width() || h != surface->height())
                {
                    delete surface;
                    surface = image::create(w, h);
                    redraw = true;
                }
                else if (redraw)
                    surface->clear();

                if (redraw)
                {
                    graphics gx(surface);
                    draw(he, gx, w, h);
                    redraw = false;
                }
                surface->blit(hdc, rc.left, rc.top);

                return default_draw ? TRUE : FALSE;
            }
Exemple #3
0
/**
 * \brief Constructor.
 * \param img The image for the sprite.
 */
bear::visual::sprite::sprite( const image& img )
  : bitmap_rendering_attributes(img.size()), m_image(img),
    m_clip_rectangle(0, 0, img.width(), img.height()),
    m_opaque_rectangle( 0, 0, 0, 0 )
{

} // sprite::sprite()
buffer2d< float >
SSIMDiffStrategy::diff( const image & img1, const image & img2 )
{
    size_t w = min( img1.width(), img2.width() );
    size_t h = min( img1.height(), img2.height() );
    float * i0 = new float[ 3 * w * h ];
    float * i1 = new float[ 3 * w * h ];

    for ( size_t y = 0; y < h; ++y ) {
        for ( size_t x = 0; x < w; ++x ) {
            i0[ ( y * w + x ) * 3 + 0 ] = img1( x, y )[ 0 ];
            i0[ ( y * w + x ) * 3 + 1 ] = img1( x, y )[ 1 ];
            i0[ ( y * w + x ) * 3 + 2 ] = img1( x, y )[ 2 ];
            i1[ ( y * w + x ) * 3 + 0 ] = img2( x, y )[ 0 ];
            i1[ ( y * w + x ) * 3 + 1 ] = img2( x, y )[ 1 ];
            i1[ ( y * w + x ) * 3 + 2 ] = img2( x, y )[ 2 ];
        }
    }

    float * weight = new float[ winsize * winsize ];
    gaussian_weight( weight, 0.1, winsize );

    buffer2d< float > result(
        min( img1.width(), img2.width() ) - winsize,
        min( img1.height(), img2.height() ) - winsize
    );

    for ( size_t y = 0; y < result.height(); ++y ) {
        for ( size_t x = 0; x < result.width(); ++x ) {
            result( x, y ) = ( 1 - floatSSIM( i0, i1, result.width() + winsize, result.height() + winsize, 3, 0, x, y, winsize, 0.01*255*0.01*255, 0.03*255*0.03*255, weight ) ) * 0.5;
        }
    }

    delete[] weight;
    delete[] i1;
    delete[] i0;

    /*
    std::vector< float > w = weight_matrix( 0.1, winsize );
    for ( size_t y = 0; y < result.height() - winsize; ++y )
        for ( size_t x = 0; x < result.width() - winsize; ++x )
            result( x, y ) = ( 1 - local_MSSIM(img1, img2, x, y, winsize, w, k1, k2) ) * 0.5;
            */

    return result;
}
Exemple #5
0
image image::operator/(const image& img) const
{
  // sanity check
  assert(width() == img.width() && height() == img.height());

  // create result
  image result(width(), height());
  std::transform(begin(), end(), img.begin(), result.begin(), std::divides<color>());

  // Done.
  return result;
}
typename image<T, D>::create_new pyramid_down(const image<T, D>& a)
{
	IplImage* src = a.ipl();
	IplImage* dst = cvCreateImage(
		image_details::cv_size(a.width() / 2, a.height() / 2),
		image_details::ipl_depth<T>(), int(a.channels()));
	cvPyrDown(src, dst);
	typename image<T, D>::create_new r(dst);
	cvReleaseImage(&src);
	cvReleaseImage(&dst);
	return r;
}
typename image<T, D>::create_new corner_eigenvals(
	const image<T, D>& a, int block_size, int aperture_size)
{
	IplImage* src = a.ipl();
	IplImage* dst = cvCreateImage(
		image_details::cv_size(a.width() * 6, a.height()),
		image_details::ipl_depth<T>(), 1);
	cvCornerEigenValsAndVecs(src, dst, block_size, aperture_size);
	typename image<T, D>::create_new r(dst);
	cvReleaseImage(&src);
	cvReleaseImage(&dst);
	return r;
}
void texture4::loadImage( image &in )
    {
    jAssert( in.isValid() );

    if( img != 0 )
        {
        glDeleteTextures( 1, &img );
        }

    width = in.width();
    height = in.height();

    float *tempBuf = new float[ 4 * width * height ];

    glGenTextures( 1, &img );
    glBindTexture( GL_TEXTURE_2D, img );

    // select modulate to mix texture with color for shading
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

    for( unsigned int y=0; y<height; y++ )
        {
        for( unsigned int x=0; x<width; x++ )
            {
            struct image::colourPacket *here = in.at( x, y );
            int base = 4 * ( x + y * width );
            tempBuf[ base ] = here->r;
            tempBuf[ base + 1 ] = here->g;
            tempBuf[ base + 2 ] = here->b;
            tempBuf[ base + 3 ] = here->a;
            }
        }


    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, (const GLvoid *)tempBuf );

    delete [] tempBuf;
    }
typename image<T, D>::create_similar grayscale(const image<T, D>& a)
{
	size_t ch = a.channels();
	CHECK(ch > 1, erange());
	size_t w = a.width();
	size_t h = a.height();
	typename types::promote<T>::type acc;
	typename image<T, D>::create_similar r(h, w, 1, 0);
	for(size_t i = 0; i < h; i++) {
		for(size_t j = 0; j < w; j++) {
			acc = a(i, j, 0);
			for(size_t col = 1; col < ch; col++)
				acc += a(i, j, col);
			acc /= typename types::promote<T>::type(ch);
			r(i, j) = T(acc);
		}
	}
	return r;
}
Exemple #10
0
void nlfilter(image& img, std::size_t w, std::size_t h,
              std::function<image::pixel_t(const ublas::matrix<image::pixel_t>&)> f)
{
    auto iw = img.width();
    auto ih = img.height();
    // The number of rows above/aside the center element
    auto top = static_cast<std::size_t>(std::floor(h / 2.0));
    auto left = static_cast<std::size_t>(std::floor(w / 2.0));
    // We must store the result and set the image to it after we have processed
    // the image as subsequent regions may need to use the unchanged pixel at
    // a location we have already modified.
    ublas::matrix<image::pixel_t> result(iw, ih);

    for(decltype(iw) x = 0; x < iw; ++x) {
        for(decltype(ih) y = 0; y < ih; ++y) {
            // img.region works from the top left of the region so we must
            // offset it so that (x, y) is at the center.
            result(x, y) = f(img.region(x - left, y - top, w, h));
        }
    }

    img.set(0, 0, result);
}
Exemple #11
0
// convert tiny_dnn::image to cv::Mat and resize
cv::Mat image2mat(image<>& img) {
    cv::Mat ori(static_cast<int>(img.height()), static_cast<int>(img.width()), CV_8U, &img.at(0, 0));
    cv::Mat resized;
    cv::resize(ori, resized, cv::Size(), 3, 3, cv::INTER_AREA);
    return resized;
}
Exemple #12
0
image::image(const image& src)
{
  _alloc(src.width(), src.height());
  std::copy(src.begin(), src.end(), begin());
}