简体   繁体   English

Java中的GrayScale(每像素8位)图像像素处理

[英]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! 我听说,色深为8位的 灰度图像中的数据存储在每个像素字节的前7位中,最后一位保持不变! 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. 我更喜欢使用纯Java类,而不是JAI或其他第三方。

Update 1 更新1

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

getRGB method always return an int which is bigger than one byte!!! getRGB方法始终返回一个大于一个字节的整数 !!! 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. 我的理解是8位色深意味着每个像素有8位(即1个字节),而Red,Gren和Blue都是这个值。 eg greyscale=192 means Red=192, Green=192, Blue=192. 例如,灰度= 192表示红色= 192,绿色= 192,蓝色= 192。 There is no 7 bits plus another 1 bit. 没有7位加另外1位。

AFAIK, you can just use a normal average. AFAIK,您只能使用正常平均值。 However I would use long for the sum and make sure each byte is unsigned ie `b & 0xff 但是,我将使用long作为总和,并确保每个字节都是无符号的,即`b&0xff

EDIT: If the grey scale is say 128 (or 0x80), I would expect the RGB to be 128,128,128 or 0x808080. 编辑:如果灰度是说128(或0x80),我希望RGB是128,128,128或0x808080。

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

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