C++ C++;裁剪连续的二维数组
假设我有一个名为image的数组,它是一个由“size”元素组成的长连续数组,定义如下。 我想裁剪这个数组(然后得到一个子矩阵),然后,通过修改子数组,我将自动修改源图像(参考) 请注意,裁剪操作将返回非连续数组。这其实就是问题所在 有没有一种方法在C++中优雅地完成?< /P> 顺便说一下,我对使用OpenCV、boost等不感兴趣 谢谢你的帮助C++ C++;裁剪连续的二维数组,c++,image-processing,C++,Image Processing,假设我有一个名为image的数组,它是一个由“size”元素组成的长连续数组,定义如下。 我想裁剪这个数组(然后得到一个子矩阵),然后,通过修改子数组,我将自动修改源图像(参考) 请注意,裁剪操作将返回非连续数组。这其实就是问题所在 有没有一种方法在C++中优雅地完成?< /P> 顺便说一下,我对使用OpenCV、boost等不感兴趣 谢谢你的帮助 template <class Type> class Image { private: Type *image; publi
template <class Type> class Image
{
private:
Type *image;
public:
int rows;
int cols;
int size;
Image(int rows, int cols): rows(rows), cols(cols)
{
image = new Type[size = rows*cols];
}
~Image()
{
delete [] image;
}
Type & at(int i, int j)
{
return image[cols*i + j];
}
void print()
{
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < cols; ++j)
cout << at(i,j) << " ";
cout << endl;
}
cout << endl;
}
};
模板类图像
{
私人:
类型*图像;
公众:
int行;
int cols;
整数大小;
图像(int行,int列):行(行),列(列)
{
图像=新类型[大小=行*列];
}
~Image()
{
删除[]图像;
}
类型和at(int i,int j)
{
返回图像[cols*i+j];
}
作废打印()
{
对于(int i=0;i cout您可以创建一个CroppedImage类,该类包含指向原始图像和偏移量的引用或指针,并提供自己的方法,这些方法添加偏移量,然后调用原始图像方法:
template <class Type> class CroppedImage
{
private:
Image<Type> *original;
int offsetX;
int offsetY;
public:
int rows;
int cols;
int size;
CroppedImage(Image<Type> *orig, int offX, int offY, int width, int height)
{
original = orig;
offsetX = offX;
offsetY = offY;
rows = height;
cols = width;
size = rows*cols;
}
~CroppedImage(){}
Type & at(int i, int j)
{
return original->at(i+offsetX, j+offsetY);
}
void print()
{
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < cols; ++j)
cout << at(i,j) << " ";
cout << endl;
}
cout << endl;
}
}
模板类裁剪图像
{
私人:
图像*原件;
国际抵销;
int-offsetY;
公众:
int行;
int cols;
整数大小;
裁剪图像(图像*原始、整数偏移x、整数偏移y、整数宽度、整数高度)
{
原件=原件;
offsetX=offX;
offsetY=offY;
行=高度;
cols=宽度;
大小=行*列;
}
~crappedimage(){}
类型和at(int i,int j)
{
返回原稿->在(i+offsetX,j+offsetY);
}
作废打印()
{
对于(int i=0;i cout您可以创建一个CroppedImage类,该类包含指向原始图像和偏移量的引用或指针,并提供自己的方法,这些方法添加偏移量,然后调用原始图像方法:
template <class Type> class CroppedImage
{
private:
Image<Type> *original;
int offsetX;
int offsetY;
public:
int rows;
int cols;
int size;
CroppedImage(Image<Type> *orig, int offX, int offY, int width, int height)
{
original = orig;
offsetX = offX;
offsetY = offY;
rows = height;
cols = width;
size = rows*cols;
}
~CroppedImage(){}
Type & at(int i, int j)
{
return original->at(i+offsetX, j+offsetY);
}
void print()
{
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < cols; ++j)
cout << at(i,j) << " ";
cout << endl;
}
cout << endl;
}
}
模板类裁剪图像
{
私人:
图像*原件;
国际抵销;
int-offsetY;
公众:
int行;
int cols;
整数大小;
裁剪图像(图像*原始、整数偏移x、整数偏移y、整数宽度、整数高度)
{
原件=原件;
offsetX=offX;
offsetY=offY;
行=高度;
cols=宽度;
大小=行*列;
}
~crappedimage(){}
类型和at(int i,int j)
{
返回原稿->在(i+offsetX,j+offsetY);
}
作废打印()
{
对于(int i=0;i cout您可以创建一个CroppedImage类,该类包含指向原始图像和偏移量的引用或指针,并提供自己的方法,这些方法添加偏移量,然后调用原始图像方法:
template <class Type> class CroppedImage
{
private:
Image<Type> *original;
int offsetX;
int offsetY;
public:
int rows;
int cols;
int size;
CroppedImage(Image<Type> *orig, int offX, int offY, int width, int height)
{
original = orig;
offsetX = offX;
offsetY = offY;
rows = height;
cols = width;
size = rows*cols;
}
~CroppedImage(){}
Type & at(int i, int j)
{
return original->at(i+offsetX, j+offsetY);
}
void print()
{
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < cols; ++j)
cout << at(i,j) << " ";
cout << endl;
}
cout << endl;
}
}
模板类裁剪图像
{
私人:
图像*原件;
国际抵销;
int-offsetY;
公众:
int行;
int cols;
整数大小;
裁剪图像(图像*原始、整数偏移x、整数偏移y、整数宽度、整数高度)
{
原件=原件;
offsetX=offX;
offsetY=offY;
行=高度;
cols=宽度;
大小=行*列;
}
~crappedimage(){}
类型和at(int i,int j)
{
返回原稿->在(i+offsetX,j+offsetY);
}
作废打印()
{
对于(int i=0;i cout您可以创建一个CroppedImage类,该类包含指向原始图像和偏移量的引用或指针,并提供自己的方法,这些方法添加偏移量,然后调用原始图像方法:
template <class Type> class CroppedImage
{
private:
Image<Type> *original;
int offsetX;
int offsetY;
public:
int rows;
int cols;
int size;
CroppedImage(Image<Type> *orig, int offX, int offY, int width, int height)
{
original = orig;
offsetX = offX;
offsetY = offY;
rows = height;
cols = width;
size = rows*cols;
}
~CroppedImage(){}
Type & at(int i, int j)
{
return original->at(i+offsetX, j+offsetY);
}
void print()
{
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < cols; ++j)
cout << at(i,j) << " ";
cout << endl;
}
cout << endl;
}
}
模板类裁剪图像
{
私人:
图像*原件;
国际抵销;
int-offsetY;
公众:
int行;
int cols;
整数大小;
裁剪图像(图像*原始、整数偏移x、整数偏移y、整数宽度、整数高度)
{
原件=原件;
offsetX=offX;
offsetY=offY;
行=高度;
cols=宽度;
大小=行*列;
}
~crappedimage(){}
类型和at(int i,int j)
{
返回原稿->在(i+offsetX,j+offsetY);
}
作废打印()
{
对于(int i=0;i 如果不获取原始连续数据的子集,您能否详细说明裁剪
是什么?如果不获取原始连续数据的子集,您能否详细说明裁剪
是什么?如果不获取原始连续数据的子集,您能否详细说明裁剪
是什么?您能否详细说明如果不获取原始连续数据的子集,什么是裁剪
?