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


C++ CFloatImage类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例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;
				for (int kx = 0; kx < kShape.width; kx++)
					for (int ky = 0; ky < kShape.height; ky++)
						if ((x-kernel.origin[0]+kx >= 0) && (x-kernel.origin[0]+kx < sShape.width) && (y-kernel.origin[1]+ky >= 0) && (y-kernel.origin[1]+ky < sShape.height))
							sum += kernel.Pixel(kx,ky,0) * src.Pixel(x-kernel.origin[0]+kx,y-kernel.origin[1]+ky,c);
				dst.Pixel(x,y,c) = (T) __max(dst.MinVal(), __min(dst.MaxVal(), sum));
			}
}
开发者ID:WangDequan,项目名称:cs4670,代码行数:25,代码来源:Convolve.cpp

示例5: 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

示例6: convertToByteImage

// Convert CFloatImage to CByteImage.
void convertToByteImage(CFloatImage &floatImage, CByteImage &byteImage) {
	CShape sh = floatImage.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<sh.nBands; c++) {
				float value = floor(255*floatImage.Pixel(x,y,c) + 0.5f);

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

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

示例7: 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

示例8: 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

示例9: 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

示例10: ComputeHarrisFeatures

void ComputeHarrisFeatures(CFloatImage &image, FeatureSet &features)
{
    //Create grayscale image used for Harris detection
    CFloatImage grayImage=ConvertToGray(image);

    //Create image to store Harris values
    CFloatImage harrisImage(image.Shape().width,image.Shape().height,1);

    //Create image to store local maximum harris values as 1, other pixels 0
    CByteImage harrisMaxImage(image.Shape().width,image.Shape().height,1);

    //compute Harris values puts harris values at each pixel position in harrisImage. 
    //You'll need to implement this function.
    computeHarrisValues(grayImage, harrisImage);
        
    // Threshold the harris image and compute local maxima.  You'll need to implement this function.
    computeLocalMaxima(harrisImage,harrisMaxImage);

    // Prints out the harris image for debugging purposes
    CByteImage tmp(harrisImage.Shape());
    convertToByteImage(harrisImage, tmp);
    WriteFile(tmp, "harris.tga");

    // TO DO--------------------------------------------------------------------
    //Loop through feature points in harrisMaxImage and fill in information needed for 
    //descriptor computation for each point above a threshold. We fill in id, type, 
    //x, y, and angle.
	CFloatImage A(grayImage.Shape());
	CFloatImage B(grayImage.Shape());
	CFloatImage C(grayImage.Shape());

	CFloatImage partialX(grayImage.Shape());
	CFloatImage partialY(grayImage.Shape());

	GetHarrisComponents(grayImage, A, B, C, &partialX, &partialY);
	int featureCount = 0;
    for (int y=0;y<harrisMaxImage.Shape().height;y++) {
        for (int x=0;x<harrisMaxImage.Shape().width;x++) {
                
            // Skip over non-maxima
            if (harrisMaxImage.Pixel(x, y, 0) == 0)
				continue;

            //TO DO---------------------------------------------------------------------
            // Fill in feature with descriptor data here. 
            Feature f;
			f.type = 2;
			f.id = featureCount++;
			f.x = x;
			f.y = y;
			f.angleRadians = GetCanonicalOrientation(x, y, A, B, C, partialX, partialY);
				//atan(partialY.Pixel(x, y, 0)/partialX.Pixel(x, y, 0));
			// Add the feature to the list of features
            features.push_back(f);
        }
    }
}
开发者ID:zbs,项目名称:Feature-detection-and-matching,代码行数:57,代码来源:features.cpp

示例11: 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

示例12: ConvolveSeparable

void ConvolveSeparable(CImageOf<T> src, CImageOf<T>& dst,
                       CFloatImage x_kernel, CFloatImage y_kernel,
                       float scale, float offset,
                       int decimate, int interpolate)
{
    // Allocate the result, if necessary
    CShape dShape = src.Shape();
    if (decimate > 1)
    {
        dShape.width  = (dShape.width  + decimate-1) / decimate;
        dShape.height = (dShape.height + decimate-1) / decimate;
    }
    dst.ReAllocate(dShape, false);

    // Allocate the intermediate images
    CImageOf<T> tmpImg1(src.Shape());
    CImageOf<T> tmpImg2(src.Shape());

    // Create a proper vertical convolution kernel
    CFloatImage v_kernel(1, y_kernel.Shape().width, 1);
    for (int k = 0; k < y_kernel.Shape().width; k++)
        v_kernel.Pixel(0, k, 0) = y_kernel.Pixel(k, 0, 0);
    v_kernel.origin[1] = y_kernel.origin[0];

    // Perform the two convolutions
    Convolve(src, tmpImg1, x_kernel, 1.0f, 0.0f);
    Convolve(tmpImg1, tmpImg2, v_kernel, scale, offset);

    // Downsample or copy
    for (int y = 0; y < dShape.height; y++)
    {
        T* sPtr = &tmpImg2.Pixel(0, y * decimate, 0);
        T* dPtr = &dst.Pixel(0, y, 0);
        int nB  = dShape.nBands;
        for (int x = 0; x < dShape.width; x++)
        {
            for (int b = 0; b < nB; b++)
                dPtr[b] = sPtr[b];
            sPtr += decimate * nB;
            dPtr += nB;
        }
    }

    interpolate++; // to get rid of "unused parameter" warning
}
开发者ID:DCayee,项目名称:iDSL,代码行数:45,代码来源:Convolve.cpp

示例13: getMinMax

// get min and max (non-INF) values
void getMinMax(CFloatImage fimg, float& vmin, float& vmax)
{
    CShape sh = fimg.Shape();
    int width = sh.width, height = sh.height;

    vmin = INFINITY;
    vmax = -INFINITY;

    for (int y = 0; y < height; y++) {
	for (int x = 0; x < width; x++) {
	    float f = fimg.Pixel(x, y, 0);
	    if (f == INFINITY)
		continue;
	    vmin = min(f, vmin);
	    vmax = max(f, vmax);
	}
    }
}
开发者ID:mzhang94,项目名称:stereo,代码行数:19,代码来源:pfm2png.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: ConvolveSeparable

void ConvolveSeparable(CImageOf<T> src, CImageOf<T>& dst,
                       CFloatImage x_kernel, CFloatImage y_kernel,
                       int subsample)
{
    // Allocate the result, if necessary
    CShape dShape = src.Shape();
    if (subsample > 1)
    {
        dShape.width  = (dShape.width  + subsample-1) / subsample;
        dShape.height = (dShape.height + subsample-1) / subsample;
    }
    dst.ReAllocate(dShape, false);

    // Allocate the intermediate images
    CImageOf<T> tmpImg1(src.Shape());
    CImageOf<T> tmpImg2(src.Shape());

    // Create a proper vertical convolution kernel
    CFloatImage v_kernel(1, y_kernel.Shape().width, 1);
    for (int k = 0; k < y_kernel.Shape().width; k++)
        v_kernel.Pixel(0, k, 0) = y_kernel.Pixel(k, 0, 0);
    v_kernel.origin[1] = y_kernel.origin[0];

    // Perform the two convolutions
    Convolve(src, tmpImg1, x_kernel);
    Convolve(tmpImg1, tmpImg2, v_kernel);
				
    // Downsample or copy
    for (int y = 0; y < dShape.height; y++)
    {
        T* sPtr = &tmpImg2.Pixel(0, y * subsample, 0);
        T* dPtr = &dst.Pixel(0, y, 0);
        int nB  = dShape.nBands;
        for (int x = 0; x < dShape.width; x++)
        {
            for (int b = 0; b < nB; b++)
                dPtr[b] = sPtr[b];
            sPtr += subsample * nB;
            dPtr += nB;
        }
    }
}
开发者ID:WangDequan,项目名称:cs4670,代码行数:42,代码来源:Convolve.cpp


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