8 Bit plane slicing 主要是進行影像分割,經影像切割出來以觀察其高頻與低頻訊息。

 

如上圖所示,

若我要將影像進行位元平面分割,轉換成一張 8-bit 的位元平面

需先將是將像素值(0~255) 轉換成 2進位制來表達。

因此,可以獲得8個bit plane 的影像,其中每個位元的位置上僅可能出現1 / 0 兩個可能。


以下為一張影像進行 8 Bit plane slicing 後的影像,以7bit與5bit的影像為例 : 

Bit plane slicing :: 7

Bit plane slicing :: 5

在影像訊號中而第8個位元平面與第1個位元平面所代表的訊號分別是「高頻訊號」 以及 「低頻訊號」。

由此處可以觀察出「高頻訊號」 比「低頻訊號」更加清晰,其要成因係於灰階值差異越大在人眼辨識上即越清晰。

因此可知 最高位元與最低位元影像平面為甚麼一張是看的清原始影像的輪廓,一張則像是充滿雜訊

 


 

C#

private static Bitmap bitOf8_PlaneSlicing(Bitmap bitmap, int bitNumber)
{
    int width = bitmap.Width;
    int height = bitmap.Height;

    System.IntPtr srcScan, dstScan;
    BitmapData srcBmData, dstBmData;
    Bitmap dstBitmap =ImageExtract.InitPonitMethod(bitmap, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);

    unsafe //啟動不安全代碼
    {
        byte* srcP = (byte*)srcScan;
        byte* dstP = (byte*)dstScan;
        int srcOffset = srcBmData.Stride - width * 3;
        int dstOffset = dstBmData.Stride - width * 3;

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
            {
                // R,G,B Color
                for (int c = 0; c < 3; c++)
                {
                    double n = planes[bitNumber - 1];
                    *(dstP + c) = (byte)(((((int)n & ((int)srcP[c])) == (int)n)) ? 255 : 0);
                }

            }
            srcP += srcOffset;
            dstP += dstOffset;
        }
    }

    bitmap.UnlockBits(srcBmData);
    dstBitmap.UnlockBits(dstBmData);

    return dstBitmap;
}

 

以下程式碼主要是先將數值轉換為二進制後,進行"AND"運算後,判斷其數值是否正確,若正確時將像素設為255,否則設為0。

(((((int)n & ((int)srcP[c])) == (int)n)) ? 255 : 0);

 

 

完整程式碼 : https://github.com/Lung-Yu/ImageToolBox/blob/master/ImageProcessToolBox/BitOf8PlaneSlicing.cs

 

 

 

arrow
arrow
    文章標籤
    Image Process Point processing
    全站熱搜

    Lung-Yu,Tsai 發表在 痞客邦 留言(0) 人氣()