使用10位深度数字图像 [英] Working with 10 bits depth digital image

查看:750
本文介绍了使用10位深度数字图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#(读取每个像素的值)处理和提取图像数据,其中像素是10位深度?

How to process and extract image data using c# (reading the value of each pixel ) where the pixel is 10 bits depth?

此外图像有4个波段( R,G,B& NIR)。

Also the image has 4 bands (R,G,B & NIR).

提前致谢。

推荐答案

我在C ++中编码而不是在C#中编码所以你需要移植我的代码...

I code in C++ not in C# so you need to port my code ...

你应该添加像素组合(每个频段有多少比特及其顺序)。

You should add the pixel composition (how many bits per band and their order).


  • 你写了每像素10位,R,G,B,NIR(我假设近红外)频段。

  • 未指定像素格式

  • 因此我只需创建一个,您必须将其更改为您的案例!!!

 bit: |9 8 7 6 5 4 3 2 1 0|
band: | R |  G  | B | NIR |


  • R - 2位

  • R - 2 bits

    现在如何使用它...

    Now how to work with it ...


    • 我会将其转换为更易于管理的位大小(对于示例每个带4位)

    • 所以我可以使用标准数据类型...

    • 并在完成您的流程后再将其转换回来到10位像素格式

    现在4 * 10 = 40和40/8 = 5这意味着每4个像素对齐5个BYTES (LCM(10,8))

    Now 4*10 = 40 and 40/8=5 which means every 4 pixels are aligned to 5 BYTES (LCM(10,8))


    • 假设这样可以保存你的图像

    • Let assume this holds your image

    int xs,ys; // resolution
    int siz;   // BYTE size of whole image data ... siz = ceil(xs*ys*10/8)
    BYTE *dat=new BYTE[siz+5]; // 10bit image data
    


  • 现在如何从5个BYTES中读取4个像素并转换为更多BYTE对齐...

  • so now how to read 4 pixels from 5 BYTES and convert to something more BYTE aligned...

    数据布局如下:

    |    0    |    1    |    2     |    3     |    4   | // BYTE
    |rrgggbbn|nn rrgggb|bnnn rrgg|gbbnnn rr|gggbbnnn|
    |      0     |       1    |      2     |     3     | // Pixel
    


  • 首先选择与BYTES对齐的新像素格式

  • first chose new pixel format aligned to BYTES

     bit: |15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0|
    band: |      R     |    G    |    B  |  NIR  | // all bands are 4 bits
    


  • 我会像这样转换像素格式:

  • I would convert pixel format like this:

    void convert10to16 (BYTE *dst,BYTE *src)
     {
     int i=0,o=0;
     BYTE in,out;
    
     in=scr[i]; i++;    // rrgggbbn
     out =(in>>2)&0x30; // 00rr0000
     out|=(in>>3)&0x07; // 00rr0ggg
     dst[o]=out; o++;
     out =(in<<3)&0x30; // 00bb0000
     out|=(in<<2)&0x04; // 00bb0n00
    
     in=scr[i]; i++;    // nnrrgggb
     out|=(in>>6)&0x03; // 00bb0nnn
     dst[o]=out; o++;
     out =(in   )&0x30; // 00rr0000
     out|=(in>>1)&0x07; // 00rr0ggg
     dst[o]=out; o++;
     out =(in<<5)&0x20; // 00b00000
    
     in=scr[i]; i++;    // bnnnrrgg
     out|=(in>>3)&0x10; // 00bb0000
     out|=(in>>4)&0x07; // 00bb0nnn
     dst[o]=out; o++;
     out =(in<<2)&0x30; // 00rr0000
     out|=(in<<1)&0x06; // 00rr0gg0
    
     in=scr[i]; i++;    // gbbnnnrr
     out|=(in>>7)&0x01; // 00rr0ggg
     dst[o]=out; o++;
     out =(in>>1)&0x30; // 00bb0000
     out|=(in>>2)&0x07; // 00bb0nnn
     dst[o]=out; o++;
     out =(in<<4)&0x30; // 00rr0000
    
     in=scr[i]; i++;    // gggbbnnn
     out|=(in>>5)&0x07; // 00rr0ggg
     dst[o]=out; o++;
     out =(in<<1)&0x30; // 00bb0000
     out|=(in   )&0x07; // 00bb0nnn
     dst[o]=out; o++;
     }
    


  • 希望我没有在某个地方弄错或错字,但你应该得到想法

  • hope I did not mistake or typo somewhere but you should get the idea

    所以现在只需

    BYTE *xxx=new BYTE[xs*ys*2+8] // 16 bit per pixel data (2 BYTE per pixel)
    BYTE *src,*dst;
    int i;
    for (src=dat,dst=xxx,i=0;i<siz;i+=5,src+=5,dst+=8)
     convert10to16(dst,src);
    


  • 您也可以重写此内容以访问单个像素而无需转换,但访问速度要慢得多

  • also you can rewrite this to access individual pixels without conversion but that is much slower access

    这篇关于使用10位深度数字图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆