简体   繁体   中英

GrayScale (8bit per pixel) Image Pixel Manipulation in Java

I've heard that the data in gray-scale images with 8-bits color depth is stored in the first 7 bits of a byte of each pixel and the last bit keep intact! So we can store some information using the last bit of all pixels, is it true?

If so, how the data could be interpreted in individual pixels? I mean there is no Red, Blue and Green! so what do those bits mean?

And How can I calculate the average value of all pixels of an image? I prefer to use pure java classes not JAI or other third parties.

Update 1

BufferedImage image = ...; // loading image
image.getRGB(i, j);

getRGB method always return an int which is bigger than one byte!!! What should I do?

My understanding is that 8-bits colour depth means there is 8-bits per pixel (ie one byte) and that Red, Gren and Blue are all this value. eg greyscale=192 means Red=192, Green=192, Blue=192. There is no 7 bits plus another 1 bit.

AFAIK, you can just use a normal average. However I would use long for the sum and make sure each byte is unsigned ie `b & 0xff

EDIT: If the grey scale is say 128 (or 0x80), I would expect the RGB to be 128,128,128 or 0x808080.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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