gdal获取像元的灰度值java,使用BufferedImage从Java中获取RGB colourspace的灰度像素值...

Anyone know of a simple way of converting the RGBint value returned from getRGB(i,j) into a greyscale value?

I was going to simply average the RGB values by breaking them up using this;

int alpha = (pixel >> 24) & 0xff;

int red = (pixel >> 16) & 0xff;

int green = (pixel >> 8) & 0xff;

int blue = (pixel) & 0xff;

and then average red,green,blue.

But i feel like for such a simple operation I must be missing something...

After a great answer to a different question, I should clear up what i want.

I want to take the RGB value returned from getRGB(i,j), and turn that into a white-value in the range 0-255 representing the "Darkness" of that pixel.

This can be accomplished by averaging and such but I am looking for an OTS implementation to save me a few lines.

解决方案

the method i'd use is to convert RGB to HSL then 0 the S portion (and optionally convert back to RGB) but this might not be exactly what you want. (it is equivalent to the average of the highest and lowest rgb value so a little different to the average of all 3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值