void verifyImagePixels(const ImageType& image,
            ImageFunction expectedPixels) {
        auto width = image.getWidth();
        auto height = image.getHeight();

        verifyImagePixels(image, width, height, expectedPixels);
    }
    cl::NDRange getLocalWorkSize(const ImageType&,
            const ImageType& destinationImage) const override {
        auto width = destinationImage.getWidth();
        auto height = destinationImage.getHeight();

        return cl::NDRange(width / 2, height / 2);
    }
Example #3
0
static jobject newIntImage(JNIEnv* env, ImageType& image) {
	jclass cls = safeFindClassMacro(cls, "Lcom/intel/vpg/IntImage;")
	jmethodID clsCons = safeFindMethodMacro(clsCons, cls, "<init>", "(II)V")
	jobject jintImage = env->NewObject(cls, clsCons, image.getWidth(),
			image.getHeight());
	jfieldID dataField = env->GetFieldID(cls, "data", "[I");
	jintArray jdata = (jintArray) env->GetObjectField(jintImage, dataField);
	arrayCopyToJNIMacro(data, Int, jint, image.getData())
	return jintImage;
}
// The evolve method filters the "current" image passed in by the INVT
// simulation framework and computes this image's gist vector. To compute
// this vector, it first applies Gabor filters to the input image at
// different orientations and scales. Then, it subdivides each of the
// filteration results into smaller "chunks" and populates the gist
// vector with the average pixel values in these coarse chunks.
void GistEstimatorContextBased::
onSimEventVisualCortexOutput(SimEventQueue& q, rutz::shared_ptr<SimEventVisualCortexOutput>& e)
{
  ///////////// VisualCortex* vc = dynamic_cast<VisualCortex*>(e->source()) ;

  const double G = GRID_SIZE ;
  const int N = GRID_SIZE * GRID_SIZE ;
  Image<double>::iterator gist_vector = itsGistVector.beginw() ;

  clock_t start_time = clock() ;
  for (uint orientation = 0; orientation < NUM_ORIENTATIONS; ++orientation)
    for (uint scale = 0; scale < NUM_SCALES; ++scale, gist_vector += N)
      {

        LFATAL("Please talk to Laurent to fix this");

        ImageType I; /////// = apply_gabor_filter(vc, orientation, scale) ;
        //LINFO("Gabor filter [O:%u, S:%u] returned %dx%d image",
        //orientation, scale, I.getWidth(), I.getHeight()) ;

        Dims grid_size(static_cast<int>(std::ceil(I.getWidth()/G)),
                       static_cast<int>(std::ceil(I.getHeight()/G))) ;
        //LINFO("computing averages for %dx%d subimages of filtered image",
        //grid_size.w(), grid_size.h()) ;
        std::vector<double> averages = grid_averages(I, grid_size) ;

        //LINFO("copying %d averages to gist vector at offset %d",
        //int(averages.size()),
        //int(gist_vector - itsGistVector.beginw())) ;
        std::copy(averages.begin(), averages.end(), gist_vector) ;
      }
  LINFO("%g seconds to compute %dx%d gist vector",
        static_cast<double>(clock() - start_time)/CLOCKS_PER_SEC,
        itsGistVector.getHeight(), itsGistVector.getWidth()) ;

  rutz::shared_ptr<SimEventGistOutput>
    gist_event(new SimEventGistOutput(this, itsGistVector)) ;
  q.post(gist_event) ;
}
Example #5
0
void GlutImage::draw()
{
	if (m_firstRun)
	{
	   glGenTextures(1, &m_texture);
	   m_firstRun = false;
	}

	glDisable(GL_LIGHTING);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, m_texture);

	ImageType imageData;
	if(image.tryTakeChanged(&imageData))
	{
		float maxPixel = imageData.getAsVector().maxCoeff();
		if (maxPixel > 1.0)
		{
		   float scaleFactor = 1.0 / maxPixel;
		   glPixelTransferf(GL_RED_SCALE, scaleFactor);
		   glPixelTransferf(GL_BLUE_SCALE, scaleFactor);
		   glPixelTransferf(GL_GREEN_SCALE, scaleFactor);
		}
		else
		{
		   glPixelTransferf(GL_RED_SCALE, 1.0);
		   glPixelTransferf(GL_BLUE_SCALE, 1.0);
		   glPixelTransferf(GL_GREEN_SCALE, 1.0);
		}

		switch (imageData.getNumChannels())
		{
		case 1:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast<GLsizei>(imageData.getWidth()),
					static_cast<GLsizei>(imageData.getHeight()), 0, GL_LUMINANCE, GL_FLOAT, imageData.getData());
			break;
		case 3:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast<GLsizei>(imageData.getWidth()),
					static_cast<GLsizei>(imageData.getHeight()), 0, GL_RGB, GL_FLOAT, imageData.getData());
			break;
		}
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	}

	glColor3d(1, 1, 1);
	glBegin(GL_QUADS);

	glTexCoord2f(1, 1);
	glVertex2f(m_bounds.min()(0), m_bounds.min()(1));

	glTexCoord2f(0, 1);
	glVertex2f(m_bounds.max()(0), m_bounds.min()(1));

	glTexCoord2f(0, 0);
	glVertex2f(m_bounds.max()(0), m_bounds.max()(1));

	glTexCoord2f(1, 0);
	glVertex2f(m_bounds.min()(0), m_bounds.max()(1));

	glEnd();

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);

	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}
Example #6
0
	virtual void draw()
	{
		if (m_firstRun)
		{
		   glGenTextures(1, &m_texture);
		   m_firstRun = false;
		}

		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(-m_numImages, m_numImages, -1, 1, -1.0, 1.0);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();

		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBindTexture(GL_TEXTURE_2D, m_texture);

		ImageType imageData;
		if(image.tryTakeChanged(&imageData))
		{
			float maxPixel = imageData.getAsVector().maxCoeff();
			if (maxPixel > 1.0)
			{
			   float scaleFactor = 1.0 / maxPixel;
			   glPixelTransferf(GL_RED_SCALE, scaleFactor);
			   glPixelTransferf(GL_BLUE_SCALE, scaleFactor);
			   glPixelTransferf(GL_GREEN_SCALE, scaleFactor);
			}
			else
			{
			   glPixelTransferf(GL_RED_SCALE, 1.0);
			   glPixelTransferf(GL_BLUE_SCALE, 1.0);
			   glPixelTransferf(GL_GREEN_SCALE, 1.0);
			}

			switch (imageData.getNumChannels())
			{
			case 1:
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageData.getWidth(), imageData.getHeight(), 0, GL_LUMINANCE,
						GL_FLOAT, imageData.getData());
				break;
			case 3:
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageData.getWidth(), imageData.getHeight(), 0, GL_RGB, GL_FLOAT,
						imageData.getData());
				break;
			}
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		}

		int xMin = -m_numImages + m_imageNum * 2;
		glColor4f(1,1,1,1);
		glBegin(GL_QUADS);

		glTexCoord2f(1, 1);
		glVertex2f(xMin, -1.0);

		glTexCoord2f(0, 1);
		glVertex2f(xMin+2, -1.0);

		glTexCoord2f(0, 0);
		glVertex2f(xMin+2, 1.0);

		glTexCoord2f(1, 0);
		glVertex2f(xMin, 1.0);

		glEnd();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	}