本文整理汇总了C++中CFloatImage::Shape方法的典型用法代码示例。如果您正苦于以下问题:C++ CFloatImage::Shape方法的具体用法?C++ CFloatImage::Shape怎么用?C++ CFloatImage::Shape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFloatImage
的用法示例。
在下文中一共展示了CFloatImage::Shape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
}
示例2: 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;
}
}
}
}
示例3: 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");
}
}
示例4: 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;
}
}
}
示例5: 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 ***
}
示例6: 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);
}
}
}
示例7: 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
}
示例8: 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;
}
}
}
示例9: 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));
}
}
示例10: 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);
}
}
}
}
示例11: 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));
}
}
}
示例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
}
示例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;
}
}
}
}
示例14: 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);
}
示例15: 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;
}
}
}
}