简体   繁体   English

如何在C ++中调整图像大小?

[英]How to resize an image in C++?

I have an image which is representative of an Array2D: 我有一个代表Array2D的图像:

template<class T = uint8_t>
Array2D<T> mPixData[4];  ///< 3 component channels + alpha channel.

The comment is in the library. 该评论在库中。 I have no clues about the explanation. 我没有任何解释的线索。

Would someone: 有人:

  1. explain what are the 3 component channels + alpha channel are about 解释3个分量通道+ alpha通道是关于什么的

  2. show how I could resize this image based on the mPixData 展示如何根据mPixData调整此图像的大小

Without know what library this is, here is a stab in the dark: 在不知道这是什么库的情况下,这是一片黑暗:

  1. The type definition implies that it is creating a 2D array of unsigned chars (allowing you to store values up to 255. 类型定义意味着它正在创建一个二维的无符号字符数组(允许您存储最多255个值)。

    template<class T = uint8_t> Array2D<T>

  2. Then, mPixData itself is an array, which implies that at each co-ordinate, you have four values (bytes to contend with), 3 for the colours (let's say RGB, but could be something else) and 1 for Alpha. 然后,mPixData本身是一个数组,这意味着在每个坐标处,您有四个值(要竞争的字节),3个颜色(假设是RGB,但可以是其他值)和1个Alpha。

  3. The "image" is basically this three dimensional array. “图像”基本上就是这个三维数组。 Presumably when loading stuff into it, it resizes to the input - what you need to do is to find some form of resizing algorithm (not an image processing expert myself, but am sure google will reveal something), which will then allow you to take this data and do what you need... 大概是在将内容加载到其中时,它会调整为输入大小-您需要做的是找到某种形式的调整大小算法(我自己不是图像处理专家,但可以肯定Google会透露一些内容),然后您便可以这些数据并做您需要的...

1) 3 component channels - Red Green Blue channels. 1)3个分量通道-红色绿色蓝色通道。 alpha channel tells about image transparency Alpha通道可显示图像透明度

2) There are many algorithms you can use to resize the image. 2)您可以使用多种算法来调整图像大小。 The simplest would be to discard extra pixels. 最简单的是丢弃多余的像素。 Another simple is to do interpolation 另一个简单的方法是进行插值

The 3 component channels represent the Red Green Blue (aka RGB) channels. 3个分量通道代表红色绿色蓝色(又名RGB)通道。 The 4th channel, ALPHA, is the transparency channel. 第四通道ALPHA是透明通道。

A pixel is defined by mPixData[4] 一个像素由mPixData[4]定义

mPixData[0] -> R
mPixData[1] -> G
mPixData[2] -> B
mPixData[3] -> A

Therefore, an image can be represented as a vector or array of mPixData[4]. 因此,图像可以表示为mPixData [4]的向量或数组。 As you already stated, in this case is Array2D<T> mPixData[4]; 正如您已经说过的,在这种情况下是Array2D<T> mPixData[4];

Resize/rescale/resample an image is not a trivial process. 调整图像的大小/重新缩放/重新采样并非易事 There are lots of materials available on the web about it and I think you should consider using a library to do this. 网上有很多关于它的资料,我认为您应该考虑使用图书馆来做到这一点。 Check CxImage (Windows/Linux). 检查CxImage (Windows / Linux)。

There are some code here but I haven't tested it. 这里有一些代码但我尚未对其进行测试。 Check the resample() function. 检查resample()函数。

Hi the 3 channels are the rgb + alpha channel. 嗨,这3个频道是rgb + alpha频道。 So red green and blue channels and the alpha channel. 因此,红色,绿色和蓝色通道以及alpha通道。 There are several methods to downscaling. 有几种缩小规模的方法。 You could take for example every 4 pixel, but the result would look quite bad, take a look at different interpolation methods eg: http://en.wikipedia.org/wiki/Bilinear_interpolation . 例如,您可以每4个像素拍摄一次,但是结果看起来很糟糕,请看一下不同的插值方法,例如: http : //en.wikipedia.org/wiki/Bilinear_interpolation

Or if you want to use a library use: http://www.imagemagick.org/Magick++/ 或者,如果您想使用图书馆,请使用: http : //www.imagemagick.org/Magick++/

or as mentioned by karlphillip: http://www.xdp.it/cximage.htm 或karlphillip提到: http ://www.xdp.it/cximage.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM