当前位置: 首页>>代码示例>>C++>>正文


C++ CFloatImage::Pixel方法代码示例

本文整理汇总了C++中CFloatImage::Pixel方法的典型用法代码示例。如果您正苦于以下问题:C++ CFloatImage::Pixel方法的具体用法?C++ CFloatImage::Pixel怎么用?C++ CFloatImage::Pixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFloatImage的用法示例。


在下文中一共展示了CFloatImage::Pixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NormalizeBlend

/******************* TO DO 5 *********************
 * NormalizeBlend:
 *	INPUT:
 *		acc: input image whose alpha channel (4th channel) contains
 *		     normalizing weight values
 *		img: where output image will be stored
 *	OUTPUT:
 *		normalize r,g,b values (first 3 channels) of acc and store it into img
 */
static void NormalizeBlend(CFloatImage& acc, CByteImage& img)
{
	// *** BEGIN TODO ***
	// fill in this routine..
	
	int width = acc.Shape().width;
    int height = acc.Shape().height;
    for (int i=0;i<width;i++){
        for (int j=0;j<height;j++){
            float w = acc.Pixel(i,j,3);
            img.Pixel(i,j,3) = 255;
            if (w > 0){
                img.Pixel(i,j,0) = acc.Pixel(i,j,0) / w;
                img.Pixel(i,j,1) = acc.Pixel(i,j,1) / w;
                img.Pixel(i,j,2) = acc.Pixel(i,j,2) / w;
            } else {
                img.Pixel(i,j,0) = 0;
                img.Pixel(i,j,1) = 0;
                img.Pixel(i,j,2) = 0;
            }
        }
    }


	// *** END TODO ***
}
开发者ID:caomw,项目名称:image-understanding-1,代码行数:35,代码来源:BlendImages.cpp

示例2: dummyComputeFeatures

// Compute silly example features.  This doesn't do anything
// meaningful, but may be useful to use as an example.
void dummyComputeFeatures(CFloatImage &image, FeatureSet &features) {
    CShape sh = image.Shape();
    Feature f;

    for (int y=0; y<sh.height; y++) {
        for (int x=0; x<sh.width; x++) {
            double r = image.Pixel(x,y,0);
            double g = image.Pixel(x,y,1);
            double b = image.Pixel(x,y,2);

            if ((int)(255*(r+g+b)+0.5) % 100 == 1) {
                // If the pixel satisfies this meaningless criterion,
                // make it a feature.

                f.type = 1;
                f.id += 1;
                f.x = x;
                f.y = y;

                f.data.resize(1);
                f.data[0] = r + g + b;

                features.push_back(f);
            }
        }
    }
}
开发者ID:WangDequan,项目名称:cs4670,代码行数:29,代码来源:features.cpp

示例3: NormalizeBlend

/******************* TO DO 5 *********************
* NormalizeBlend:
*	INPUT:
*		acc: input image whose alpha channel (4th channel) contains
*		     normalizing weight values
*		img: where output image will be stored
*	OUTPUT:
*		normalize r,g,b values (first 3 channels) of acc and store it into img
*/
static void NormalizeBlend(CFloatImage& acc, CByteImage& img)
{
    // BEGIN TODO
    // fill in this routine..
	// divide the total weight for every pixel
	CShape shacc=acc.Shape();
    int widthacc=shacc.width;
    int heightacc=shacc.height;
	for (int ii=0;ii<widthacc;ii++)
	{
        for (int jj=0;jj<heightacc;jj++)
		{
			if (acc.Pixel(ii,jj,3)>0)
			{
				img.Pixel(ii,jj,0)=(int)(acc.Pixel(ii,jj,0)/acc.Pixel(ii,jj,3));
				img.Pixel(ii,jj,1)=(int)(acc.Pixel(ii,jj,1)/acc.Pixel(ii,jj,3));
				img.Pixel(ii,jj,2)=(int)(acc.Pixel(ii,jj,2)/acc.Pixel(ii,jj,3));
			}
			else
			{
				img.Pixel(ii,jj,0)=0;
				img.Pixel(ii,jj,1)=0;
				img.Pixel(ii,jj,2)=0;
			}
		}
	}

    // END TODO
}
开发者ID:yingthu,项目名称:Autostitch,代码行数:38,代码来源:BlendImages.cpp

示例4: Convolve

void Convolve(CImageOf<T> src, CImageOf<T>& dst,
              CFloatImage kernel)
{
    // Determine the shape of the kernel and source image
    CShape kShape = kernel.Shape();
    CShape sShape = src.Shape();

    // Allocate the result, if necessary
    dst.ReAllocate(sShape, false);
    if (sShape.width * sShape.height * sShape.nBands == 0)
        return;

    // Do the convolution
    for (int y = 0; y < sShape.height; y++)
		for (int x = 0; x < sShape.width; x++)
			for (int c = 0; c < sShape.nBands; c++)
			{
				double sum = 0;
				double sumker = 0;
				for (int k = 0; k < kShape.height; k++)
					for (int l = 0; l < kShape.width; l++)
						if ((x-kernel.origin[0]+k >= 0) && (x-kernel.origin[0]+k < sShape.width) && (y-kernel.origin[1]+l >= 0) && (y-kernel.origin[1]+l < sShape.height))
						{
							sumker += kernel.Pixel(k,l,0);
							sum += kernel.Pixel(k,l,0) * src.Pixel(x-kernel.origin[0]+k,y-kernel.origin[1]+l,c);
						}
				dst.Pixel(x,y,c) = (T) __max(dst.MinVal(), __min(dst.MaxVal(), sum/sumker));
			}
}
开发者ID:andre8359,项目名称:CodigosTCC,代码行数:29,代码来源:Convolve.cpp

示例5: ConvolveRow2D

static
void ConvolveRow2D(CFloatImage& buffer, CFloatImage& kernel, float dst[],
                   int n)
{
    CShape kShape = kernel.Shape();
    int kX  = kShape.width;
    int kY  = kShape.height;
    CShape bShape = buffer.Shape();
    int nB  = bShape.nBands;

    for (int i = 0; i < n; i++)
    {
        for (int b = 0; b < nB; b++)
        {
            float sum = 0.0f;
            for (int k = 0; k < kY; k++)
            {
                float* kPtr = &kernel.Pixel(0, k, 0);
                float* bPtr = &buffer.Pixel(i, k, b);
                for (int l = 0; l < kX; l++, bPtr += nB)
                    sum += kPtr[l] * bPtr[0];
            }
            *dst++ = sum;
        }
    }
}
开发者ID:xfrings,项目名称:StereoMatch,代码行数:26,代码来源:Convolve.cpp

示例6: MotionToColor

void MotionToColor(CFloatImage motim, CByteImage &colim, float maxmotion)
{
    CShape sh = motim.Shape();
    int width = sh.width, height = sh.height;
    colim.ReAllocate(CShape(width, height, 3));
    int x, y;
    // determine motion range:
    float maxx = -999, maxy = -999;
    float minx =  999, miny =  999;
    float maxrad = -1;
    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    float fx = motim.Pixel(x, y, 0);
	    float fy = motim.Pixel(x, y, 1);
	    if (unknown_flow(fx, fy))
		continue;
	    maxx = __max(maxx, fx);
	    maxy = __max(maxy, fy);
	    minx = __min(minx, fx);
	    miny = __min(miny, fy);
	    float rad = sqrt(fx * fx + fy * fy);
	    maxrad = __max(maxrad, rad);
	}
    }
    printf("max motion: %.4f  motion range: u = %.3f .. %.3f;  v = %.3f .. %.3f\n",
	   maxrad, minx, maxx, miny, maxy);


    if (maxmotion > 0) // i.e., specified on commandline
	maxrad = maxmotion;

    if (maxrad == 0) // if flow == 0 everywhere
	maxrad = 1;

    if (verbose)
	fprintf(stderr, "normalizing by %g\n", maxrad);

    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    float fx = motim.Pixel(x, y, 0);
	    float fy = motim.Pixel(x, y, 1);
	    uchar *pix = &colim.Pixel(x, y, 0);
	    if (unknown_flow(fx, fy)) {
		pix[0] = pix[1] = pix[2] = 0;
	    } else {
		computeColor(fx/maxrad, fy/maxrad, pix);
	    }
	}
    }
}
开发者ID:angusforbes,项目名称:optiflow,代码行数:50,代码来源:color_flow.cpp

示例7: computeHarrisValues

//TO DO---------------------------------------------------------------------
//Loop through the image to compute the harris corner values as described in class
// srcImage:  grayscale of original image
// harrisImage:  populate the harris values per pixel in this image
void computeHarrisValues(CFloatImage &srcImage, CFloatImage &harrisImage)
{
	int h = srcImage.Shape().height;
	int w = srcImage.Shape().width;

	CFloatImage A(srcImage.Shape());
	CFloatImage B(srcImage.Shape());
	CFloatImage C(srcImage.Shape());

	GetHarrisComponents(srcImage, A, B, C);

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
			double determinant = A.Pixel(x, y, 0) * C.Pixel(x, y, 0) - B.Pixel(x, y, 0)* B.Pixel(x, y, 0);
			double trace = A.Pixel(x, y, 0) + C.Pixel(x, y, 0);
			
			float *pixel = &harrisImage.Pixel(x, y, 0);

			if (trace == 0)
			{
				*pixel = 0;
			}
			else
			{
				*pixel = determinant / trace;
			}
        }
    }
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:33,代码来源:features.cpp

示例8: ConvolveRow

void ConvolveRow(CImageOf<T> buffer, CFloatImage kernel, T* dst,
                 int n, T minVal, T maxVal)
{
    CShape kShape = kernel.Shape();
    int kX  = kShape.width;
    int kY  = kShape.height;
    CShape bShape = buffer.Shape();
    int nB  = bShape.nBands;

    for (int i = 0; i < n; i++)
    {
        for (int b = 0; b < nB; b++)
        {
            float sum = 0.0f;
            for (int k = 0; k < kY; k++)
            {
                float* kPtr = &kernel.Pixel(0, k, 0);
                T*     bPtr = &buffer.Pixel(i, k, b);
                for (int l = 0; l < kX; l++, bPtr += nB)
                    sum += kPtr[l] * bPtr[0];
            }
            *dst++ = (T) __max(minVal, __min(maxVal, sum));
        }
    }
}
开发者ID:WangDequan,项目名称:cs4670,代码行数:25,代码来源:Convolve.cpp

示例9: convertToFloatImage

void convertToFloatImage(CByteImage &byteImage, CFloatImage &floatImage) {
	CShape sh = byteImage.Shape();
	//printf("%d\n", floatImage.Shape().nBands);
	//printf("%d\n", byteImage.Shape().nBands);

    assert(floatImage.Shape().nBands == min(byteImage.Shape().nBands, 3));
	for (int y=0; y<sh.height; y++) {
		for (int x=0; x<sh.width; x++) {
			for (int c=0; c<min(3,sh.nBands); c++) {
				float value = byteImage.Pixel(x,y,c) / 255.0f;

				if (value < floatImage.MinVal()) {
					value = floatImage.MinVal();
				}
				else if (value > floatImage.MaxVal()) {
					value = floatImage.MaxVal();
				}

				// We have to flip the image and reverse the color
				// channels to get it to come out right.  How silly!
				floatImage.Pixel(x,sh.height-y-1,min(3,sh.nBands)-c-1) = value;
			}
		}
	}
}
开发者ID:AySz88,项目名称:panorama-proj2,代码行数:25,代码来源:Project2.cpp

示例10: rotation

void rotation()
{	
		CFloatImage matrixImage = GetImageFromMatrix((float *)featureMatrix, 10, 10);
		CTransform3x3 translationNegative;
		CTransform3x3 translationPositive;
		CTransform3x3 rotation;
		CFloatImage postHomography;

		Feature f;
		f.x = 6;
		f.y = 5;
		f.angleRadians = PI;

		translationNegative = translationNegative.Translation(f.x,f.y);
		translationPositive = translationPositive.Translation(-f.x,-f.y);

		rotation = rotation.Rotation(-f.angleRadians * 180/ PI);


		WarpGlobal(matrixImage, postHomography, translationNegative*rotation*translationPositive, eWarpInterpLinear, eWarpInterpNearest);
		for (int i = 0; i < postHomography.Shape().height; i++)
		{
			for (int j = 0; j < postHomography.Shape().width; j++)
			{
				printf("%.0f\t", postHomography.Pixel(j, i, 0));
			}
			printf("\n");
		}
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:29,代码来源:test.cpp

示例11: float2color

// convert float disparity image into a color image using jet colormap
void float2color(CFloatImage fimg, CByteImage &img, float dmin, float dmax)
{
    CShape sh = fimg.Shape();
    int width = sh.width, height = sh.height;
    sh.nBands = 3;
    img.ReAllocate(sh);

    float scale = 1.0 / (dmax - dmin);

    for (int y = 0; y < height; y++) {
	for (int x = 0; x < width; x++) {
	    float f = fimg.Pixel(x, y, 0);
	    int r = 0;
	    int g = 0;
	    int b = 0;
	    
	    if (f != INFINITY) {
		float val = scale * (f - dmin);
		jet(val, r, g, b);
	    }

	    img.Pixel(x, y, 0) = b;
	    img.Pixel(x, y, 1) = g;
	    img.Pixel(x, y, 2) = r;
	}
    }
}
开发者ID:mzhang94,项目名称:stereo,代码行数:28,代码来源:pfm2png.cpp

示例12: GetHarrisComponents

void GetHarrisComponents(CFloatImage &srcImage, CFloatImage &A, CFloatImage &B, CFloatImage &C, CFloatImage *partialX, CFloatImage *partialY)
{
	int w = srcImage.Shape().width;
    int h = srcImage.Shape().height;

	CFloatImage *partialXPtr;
	CFloatImage *partialYPtr;

	if (partialX != nullptr && partialY != nullptr)
	{
		partialXPtr = partialX;
		partialYPtr = partialY;
	}
	else
	{
		partialXPtr = new CFloatImage(srcImage.Shape());
		partialYPtr = new CFloatImage(srcImage.Shape());
	}

	CFloatImage partialXX(srcImage.Shape());
	CFloatImage partialYY(srcImage.Shape());
	CFloatImage partialXY(srcImage.Shape());

	CFloatImage gaussianImage = GetImageFromMatrix((float *)gaussian5x5Float, 5, 5);

	Convolve(srcImage, *partialXPtr, ConvolveKernel_SobelX);
	Convolve(srcImage, *partialYPtr, ConvolveKernel_SobelY);
	
	for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
			float *xxPixel = &partialXX.Pixel(x, y, 0);
			float *yyPixel = &partialYY.Pixel(x, y, 0);
			float *xyPixel = &partialXY.Pixel(x, y, 0);
			
			// The 1/8 factor is to do the scaling inherent in sobel filtering
			*xxPixel = pow((double)(1./8. *8. * partialXPtr->Pixel(x, y, 0)), 2.);
			*yyPixel = pow((double)(1./8. *8. * partialYPtr->Pixel(x, y, 0)), 2.);
			*xyPixel = pow(1./8. *8., 2.) * partialXPtr->Pixel(x, y, 0) * partialYPtr->Pixel(x, y, 0);
		}
	}

	Convolve(partialXX, A, gaussianImage);
	Convolve(partialXY, B, gaussianImage);
	Convolve(partialYY, C, gaussianImage);
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:45,代码来源:features.cpp

示例13: computeLocalMaxima

// TO DO---------------------------------------------------------------------
// Loop through the harrisImage to threshold and compute the local maxima in a neighborhood
// srcImage:  image with Harris values
// destImage: Assign 1 to a pixel if it is above a threshold and is the local maximum in 3x3 window, 0 otherwise.
//    You'll need to find a good threshold to use.
void computeLocalMaxima(CFloatImage &srcImage,CByteImage &destImage)
{
	int width = srcImage.Shape().width;
	int height = srcImage.Shape().height;

	double mean, stdDev;
	double sum = 0;
	double squareSum = 0;

	for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
			float pixel = srcImage.Pixel(x, y, 0);
			if (!(pixel >= 0 || pixel < 0))
			{
				auto error = "TRUE";
			}
			sum += srcImage.Pixel(x, y, 0);
		}
    }

	mean = sum / (float)(width * height);

	for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            squareSum += pow((srcImage.Pixel(x, y, 0) - mean), 2.);
        }
    }

	stdDev = sqrt(squareSum / (float)(width * height - 1));
	int count = 0;
	for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
			unsigned char *pixel = &destImage.Pixel(x, y, 0);
			if (srcImage.Pixel(x, y, 0) >= 3.*stdDev + mean && isLocalMax(srcImage, x, y))
			{
				count++;
				*pixel = 1;
			}
			else
			{
				*pixel = 0;
			}
        }
    }
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:50,代码来源:features.cpp

示例14: computeLocalMaxima

//Loop through the image to determine suitable feature points
// srcImage:  image with Harris values
// destImage: Assign 1 to local maximum in 3x3 window that are above a given 
//            threshold, 0 otherwise
void computeLocalMaxima(CFloatImage &srcImage,CByteImage &destImage)
{
	int w = srcImage.Shape().width;	 // image width
	int h = srcImage.Shape().height; // image height
	
	//float threshold = .024;
	float threshold = .01;	// threshold value for identifying features


	// Declare additional variables
	float max;		// harris value to check as local max
	int newX, newY;	// (x,y) coordinate for pixel in 5x5 sliding window 
	int j;			// int for iterating through 5x5 window

	// Loop through 'srcImage' and determine suitable feature points that
	// fit the following criteria:
	//   - harris value c is greater than a predefined threshold
	//   - c is a local maximum in a 5x5 neighborhood
	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {

			max = srcImage.Pixel(x,y,0);
			
			// If harris value is greater than a predefined threshold check
			// if value is a local maximum in a 5x5 neighborhood.
			if (max > threshold) {
				for (j = 0; j < 25; j++) {
					find5x5Index(x,y,j,&newX,&newY);
					if(srcImage.Shape().InBounds(newX, newY) && srcImage.Pixel(newX, newY, 0) > max) {
						destImage.Pixel(x,y,0) = 0;
						break;
					}
				}
				if (j != 25) 
					continue;
				destImage.Pixel(x,y,0) = 1;
			} else {
				destImage.Pixel(x,y,0) = 0;
			}
		}
	}
}
开发者ID:WangDequan,项目名称:cs4670,代码行数:46,代码来源:features.cpp

示例15: convertImage

// Convert Fl_Image to CFloatImage.
bool convertImage(const Fl_Image *image, CFloatImage &convertedImage) {
    if (image == NULL) {
        return false;
    }

    // Let's not handle indexed color images.
    if (image->count() != 1) {
        return false;
    }

    int w = image->w();
    int h = image->h();
    int d = image->d();

    // Get the image data.
    const char *const *data = image->data();

    int index = 0;

    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            if (d < 3) {
		// If there are fewer than 3 channels, just use the
		// first one for all colors.
		convertedImage.Pixel(x,y,0) = ((uchar) data[0][index]) / 255.0f;
		convertedImage.Pixel(x,y,1) = ((uchar) data[0][index]) / 255.0f;
		convertedImage.Pixel(x,y,2) = ((uchar) data[0][index]) / 255.0f;
            }
            else {
		// Otherwise, use the first 3.
		convertedImage.Pixel(x,y,0) = ((uchar) data[0][index]) / 255.0f;
		convertedImage.Pixel(x,y,1) = ((uchar) data[0][index+1]) / 255.0f;
		convertedImage.Pixel(x,y,2) = ((uchar) data[0][index+2]) / 255.0f;
            }

            index += d;
        }
    }
        
    return true;
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:42,代码来源:features.cpp


注:本文中的CFloatImage::Pixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。