tags:

views:

402

answers:

5

Hi,

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.

I would like to know how can I scale this down (80 * 120) without losing image quality?

I found this link about scaling image in 2D array, but how can I apply that to my array of 16 bit display? It is not a 2D array (because of it has 16 bit color).

http://stackoverflow.com/questions/299267/image-scaling-and-rotating-in-cc

Thank you.

+2  A: 

There are plenty of methods of scaling down images, but none can guarantee not losing "quality". Ultimately information is lost during the rescaling process.

Assaf Lavie
A: 

You have 16bit colors = 2bytes, but in your calculations you use 4 multiplier.
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.

bb
Good point. Here is the information I get:* the size of the raw RGB buffer is 614400* the size of the display is 320 * 480* it is a 16 bit displayI know the above are right because I follow thishttp://docs.blackfin.uclinux.org/doku.php?id=framebufferand my result shows correctly
lucius
And now I don't know why the size of the buffer is 614400. I try to reverse engineering why it was that big from the fact that my display is 320 * 480.
lucius
Hm. In docs mentioned by you they shows perl script which convert raw data to rgb.
bb
+4  A: 

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.

Also, if the output is going to be less than 16 bits per pixel, you need to do some form of Color Quantization.

jw
A: 

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. You can then loop through each 4x4 block in the original image and then reduce this to a single pixel. A simple way (perhaps not the best way) to do this reduction could be to take the average or median of the RGB components.

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).

MahlerFive
It looks like the OP meant a factor of 4 in each dimension, so you want to average 4x4 blocks of source pixels, not 2x2, for an overall size change of a factor of 16.
RBerteig
True, edited answer to reflect that
MahlerFive
+2  A: 

I assume that you mean a 16 bit rgb display, not a display that has each color (red, green, and blue) as 16 bits. I also assume you know how your r, g, and b values are encoded in that 16 bit space, because there are two possibilities.

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. 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. 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.

mmr