简体   繁体   English

如何在16位显示器上缩小原始rgb数据的数组

[英]How can I scale down an array of raw rgb data on a 16 bit display

I have an array of raw rgb data on a 16 bit display with dimension of 320 * 480. The size of the array is 320*480*4 = 6144000. 我在16位显示器上有一系列原始rgb数据,尺寸为320 * 480.阵列大小为320 * 480 * 4 = 6144000。

I would like to know how can I scale this down (80 * 120) without losing image quality? 我想知道如何在不降低图像质量的情况下缩小(80 * 120)?

I found this link about scaling image in 2D array, but how can I apply that to my array of 16 bit display? 我找到了关于在2D数组中缩放图像的链接,但是如何将其应用于我的16位显示数组呢? It is not a 2D array (because of it has 16 bit color). 它不是2D数组(因为它有16位颜色)。

Image scaling and rotating in C/C++ 图像缩放和C / C ++旋转

Thank you. 谢谢。

If you are scaling down a big image to a smaller one, you WILL lose image quality. 如果要将较大的图像缩小到较小的图像,则会丢失图像质量。

The question, then, is how to minimize that loss. 那么,问题是如何最大限度地减少损失。

There are many algorithms that do this, each with strengths and weaknesses. 有许多算法可以做到这一点,每个算法都有优点和缺点。

Typically you will apply some sort of filter to your image, such as Bilinear or Nearest Neighbor. 通常,您会对图像应用某种滤镜,例如双线性或最近邻。 Here is a discussion of such filters in the context of ImageMagick. 以下是 ImageMagick上下文中对此类过滤器的讨论

Also, if the output is going to be less than 16 bits per pixel, you need to do some form of Color Quantization . 此外,如果输出将小于每像素16位,则需要进行某种形式的颜色量化

I assume that you mean a 16 bit rgb display, not a display that has each color (red, green, and blue) as 16 bits. 我假设您的意思是16位rgb显示器,而不是每种颜色(红色,绿色和蓝色)为16位的显示器。 I also assume you know how your r, g, and b values are encoded in that 16 bit space, because there are two possibilities . 我还假设你知道你的r,g和b值是如何在16位空间中编码的,因为有两种可能性

So, assuming you know how to split your color space up, you can now use a series of byte arrays to represent your data. 因此,假设您知道如何分割颜色空间,现在可以使用一系列字节数组来表示数据。 What becomes a tricky decision is whether to go with byte arrays, because you have a body of algorithms that can already do the work on those arrays but will cost you a few extra bits per byte that you may not be able to spend, or to keep everything crammed into that 16 bit format and then do the work on the appropriate bits of each 16 bit pixel. 什么变成一个棘手的决定是,是否使用字节数组,因为你有一组算法已经可以在这些数组上工作,但每个字节会花费你一些额外的比特,你可能无法花费,或者将所有内容都塞进16位格式,然后对每个16位像素的相应位进行处理。 Only you can really answer that question; 只有你能真正回答这个问题; if you have the memory, I'd opt for the byte array approach, because it's probably faster and you'll get a little extra precision to make the images look smooth(er) in the end. 如果你有内存,我会选择字节数组方法,因为它可能更快,你会得到一点额外的精度,使图像最终看起来平滑(呃)。

Given those assumptions, the question is really answerable by how much time you have on your device. 鉴于这些假设,问题实际上是您在设备上花了多少时间。 If you have a very fast device, you can implement a Lanczos resampling . 如果您的设备速度非常快,则可以实施Lanczos重采样 If you have a less fast device, bicubic interpolation works very well as well. 如果您的设备速度较慢 ,则双三次插值也可以很好地工作。 If you have an even slower device, bilinear interpolation is your friend. 如果你有一个更慢的设备, 双线性插值是你的朋友。

If you really have no speed, I'd do the rescaling down in some external application, like photoshop, and save a series of bitmaps that you load as you need them. 如果你真的没有速度,我会在一些外部应用程序(如photoshop)中进行重新缩放,并保存一系列根据需要加载的位图。

There are plenty of methods of scaling down images, but none can guarantee not losing "quality". 有很多缩小图像的方法,但没有一种方法可以保证不会失去“质量”。 Ultimately information is lost during the rescaling process. 最终在重新缩放过程中丢失信息。

You have 16bit colors = 2bytes, but in your calculations you use 4 multiplier. 你有16位颜色= 2字节,但在你的计算中你使用4乘法器。
Maybe you don't needed reducing image size? 也许你不需要减小图像尺寸?

in general it is impossible to scale raster image without loosing quality. 通常,不能在不失去质量的情况下缩放光栅图像。 Some algorithms make scaling almost without visible quality loosing. 一些算法使得缩放几乎没有可见的质量松动。

Since you are scaling down by a factor of 4, each 4x4 block of pixels in your original image will correspond to a single pixel in your output image. 由于缩小了4倍,原始图像中的每个4x4像素块将对应输出图像中的单个像素。 You can then loop through each 4x4 block in the original image and then reduce this to a single pixel. 然后,您可以遍历原始图像中的每个4x4块,然后将其缩小为单个像素。 A simple way (perhaps not the best way) to do this reduction could be to take the average or median of the RGB components. 进行此减少的一种简单方法(可能不是最好的方法)可以是取RGB组件的平均值或中值。

You should note that you cannot do image scaling without losing image quality unless for all the blocks in the original image, each pixel is the exact same colour (which is unlikely). 您应该注意,在不丢失图像质量的情况下无法进行图像缩放,除非对于原始图像中的所有块,每个像素都是完全相同的颜色(这是不太可能的)。

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

相关问题 将浮点数的高度图数组导出为 16 位原始数据 - Exporting heightmap array of floats to 16bit raw 如何直接从RGB原始数组中显示像素,比SetPixel()更快? - How to display pixels on screen directly from a raw array of RGB values faster than SetPixel()? 如何将 MJPEG 解码为原始 RGB(或 YUV)数据 - How to decode an MJPEG to raw RGB (or YUV) data opengl c ++:如何将32位png文件转换为16位565RGB文件 - opengl c++: How to convert a 32bit png file to a 16 bit 565RGB file 将RGB存储在无符号16位整数中 - Storing RGB in an unsigned 16bit integer 在开放式简历中,如何将灰度图像转换回RGB图像(彩色) - In open cv, how can i convert gray scale image back in to RGB image(color) 如何在C ++中将16位十六进制颜色转换为RGB888值 - How to convert 16 bit hex color to RGB888 values in C++ C++ 从原始 img 读取 16 位二进制数据并将它们存储在向量中 - C++ reading 16bit binary data from raw img and store them in vector 当一个为负数时,如何将两个16位值组合为一个32位值? - How can I combine two 16-bit values into a single 32-bit value when either one is negative? 如何减少或消除通过更改16bit PCM的样本“音量”而产生的噪声 - How can I reduce or remove the noise created by changing the 'volume' of a sample from 16bit PCM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM