Pergunta

I am using the BufferedImage class to read in an image as pixels which I then use bit shifting to get their appropriate components into separate int arrays. This works OK.

I have used this reference site to manually perform DCT functions with the pixel arrays.

Methods used: forwardDCT(), quantitizeMatrix(), dequantitzeMatrax(), inverseDCT()

which then are fed back into a resultant image array to reconstruct the JPEG file, which I then use BufferedImage's write() method to write the pixel data back out as the image.

This works perfectly, and I can view the image. (Even better the value I use to compress visually works).

My question is, is there a way to write the quantitize coefficients as the compressed values as a JPEG?

Because the BufferedImage write() method is used to input pixel data, rather than coefficient data?

Hope this is clear.

Thanks

Foi útil?

Solução

Ultimately the DCT calculation is just one step in the whole JPEG encoding process. A complete implementation also has to deal with quantization, Huffman encoding, and conforming with the JPEG standard.

Java effectively just gives you an interface to a JPEG encoder that lets you do useful things like save images.

The ImageWriter that ImageIO.write() uses for JPEG images depends on your system. The default ImageWriter for JPEGs will only let you change some settings that affect the quantization and encoding using the JPEGImageWriteParam class (http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageWriteParam.html).

Getting your hand-crafted DCT coefficients into a JPEG file could potentially involve writing an entire JPEG library. If you don't want to do all that work, then you could modify the source of an existing library so that it uses your DCT coefficients.

Outras dicas

Before the DCT . . .

While JPEG has no knowledge of colors, it is normal for JPEG file formats to use the YCbCr color space. If you are thinking about writing a JPEG file, you would need to do this conversion first.

After the Quantization . . .

The coefficients are run length encoded. That's a step you'd have to add. That's the most complex part of JPEG encoding.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top