Raw2gray 转灰度值


    /**
     * Multispectral Sensor 10bit(16bit from HAL) raw to gray image, and 1/16 downsampling.
     *
     * @param imgSrc 16bit raw(actually 10bit valid data.
     * @param isFullSize
     * @param isGray
     * @param channel 0-15
     */
    public int[] Raw2Gray(byte[] imgSrc, boolean isFullSize, boolean isGray, int channel) {
        // 2608 x 1960 = 5111680 pixel
        // 652 x 490 = 319480 pixel 1/16 binning
        int display_width;
        int display_height;
        int row_offset;
        int col_offset;
        int[] imgInt;

        if(isFullSize == true) {
            // Full size
            display_width = 2608;
            display_height = 1960;
            imgInt = new int[display_width * display_height];
            for(int i = 0; i < display_width * display_height; i++) {
                // Big-Endian
                // full size
                if(isGray == false) {

                    imgInt[i] = (imgSrc[1 + 2*i] & 0xFF) |
                            ((imgSrc[2*i] & 0xFF) << 8) |
                            (0x00 << 16) |
                            (0xFF << 24);

                    //other way
//                    imgInt[i] = (imgSrc[2*i] & 0xFF)  | (imgSrc[1+2*i] & 0xFF <<8) |
//                                (0x00 << 16) |
//                                (0xFF << 24);//this means Alpha,0xFF means opaque

                } else {
                    byte gray_pixel = (byte) (((imgSrc[1 + 2*i] << 6) & 0xC0) | ((imgSrc[2*i] & 0xFF) >>> 2));
                    imgInt[i] = gray_pixel & 0xFF |
                            (gray_pixel & 0xFF) << 8 |
                            (gray_pixel & 0xFF) << 16 |
                            0xFF << 24;

                }
            }
        }
        else {
            // 1/16 Downsampling
            display_width = 652;
            display_height = 490;

            row_offset = channel / 4 * 2608;
            col_offset = channel % 4;//columns
            Log.e(TAG, "Raw2Gray--row: " + row_offset + "col: " + col_offset+", channel = "+channel);

            imgInt = new int[display_width * display_height];

            for(int h = 0; h < display_height; h++)
            {
                int tmp = h * display_width;
                int tmp_src = 16 * tmp;

                for(int w = 0; w < display_width; w++)
                {
                    // Big-Endian
                    // 1/16 binning
                    if(isGray == false) {
                        /*
                        imgInt[tmp + w] = (imgSrc[1 + 2*(tmp_src + row_offset + 4*w + col_offset)] & 0xFF) |
                                ((imgSrc[2*(tmp_src + row_offset + + 4*w + col_offset)] & 0xFF) << 8) |
                                (0x00 << 16)|
                                (0xFF << 24);

*/
                    //xll
                        imgInt[w + h * display_width] = (imgSrc[1+ 2*(w*4+ col_offset + row_offset  + h*display_width*16)]& 0xFF) |
                                ((imgSrc[2*(w*4+ col_offset + row_offset  + h*display_width*16)] & 0xFF) <<8) |
                                (0x00 << 16)|
                                (0xFF << 24);

                    } else {
                        // 1/16 binning & gray
                        byte gray_pixel = (byte) (((imgSrc[1 + 2*(tmp_src + row_offset + 4*w + col_offset)] << 6) & 0xC0) |
                                ((imgSrc[2*(tmp_src + row_offset + + 4*w + col_offset)] & 0xFF) >>> 2));

                        imgInt[tmp + w] = gray_pixel & 0xFF |
                                (gray_pixel & 0xFF) << 8 |
                                (gray_pixel & 0xFF) << 16 |
                                0xFF << 24;



                    }
                }
            }
        }
        return imgInt;
    }

 转灰度值

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值