简体   繁体   English

java中彩色图像到灰度图像(512级灰度)的转换

[英]Conversion of coloured image to grey scale image (512 shades of grey) in java

I am trying to convert a colored image to grayscale.我正在尝试将彩色图像转换为灰度。 The result should be 512 shades of grey.结果应该是 512 级灰色。

How can I convert the pixel value to 9 bit so that I get 512 shades?如何将像素值转换为 9 位,以便获得 512 个阴影?

I dont know how to do it in 9 bits but if you want value of your image in range of 0 to 511, this can be done in following manner.我不知道如何在 9 位中做到这一点,但如果您希望图像的值在 0 到 511 的范围内,可以通过以下方式完成。

im = imread('lena.png'); 
im = double(im);
gray = 0.2989*im(:,:,1)+0.5870*im(:,:,2)+0.1140*im(:,:,3);
gray  = 511*mat2gray(gray); % scale image b/w 0 and 1;

This is my thought, please give us some more explanation with your code, so that anyone here can suggest solution of your problem.这是我的想法,请给我们更多的代码解释,以便这里的任何人都可以建议您解决问题。

Thank You谢谢你

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

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