圖像清晰度評價

圖像清晰度是衡量圖像質量的一個重要指標,對於相機來說,其一般工作在無參考圖像的模式下,所以在拍照時需要進行對焦的控制。對焦不準確,圖像就會變得比較模糊不清晰。相機對焦時通過一些清晰度評判指標,控制鏡頭與CCD的距離,使圖像成像清晰。一般對焦時有一個調整的過程,圖像從模糊到清晰,再到模糊,確定清晰度峯值,再最終到達最清晰的位置。
常見的圖像清晰度評價一般都是基於梯度的方法,本文將介紹五種簡單的評價指標,分別是Brenner梯度法、Tenegrad梯度法、laplace梯度法、方差法、能量梯度法。


Brenner梯度法

計算相差兩個單元的兩個像素點的灰度差:

FBrenner=MN(f(x+2,y)f(x,y))2

式中(f(x+2,y)f(x,y))2>Threshold
算法準確性取決於閾值的選取。

Tenegrad梯度法

採用sobel算子分別提取水平和豎直方向的梯度:

FTenegrad=MN|G(x,y)|

G(x,y)>Threshold
G(x,y)=Gx(x,y)2+Gy(x,y)2
sobel算子模板如下:
Gx=14121000121I

Gy=14101202101I

Laplace梯度法

laplace梯度函數與Tenegrad基本一致,只需要用Laplace算子替代sobel算子即可:

L=161414204141I

方差法

聚焦清晰的圖像比模糊圖像有更大的灰度差異,可用方差函數作爲評價:

Fvariance=MN(f(x,y)E2)

式中E爲整幅圖像的平均灰度值,該函數對噪聲敏感。

能量梯度法

能量梯度函數適合實時評價圖像清晰度:

FBrenner=MN((f(x+1,y)f(x,y))2+(f(x,y+1)f(x,y))2)

實例代碼

採用halcon實現:

//方差法
        region_to_mean(Image, Image, &ImageMean);
        convert_image_type(ImageMean, &ImageMean, "real");
        convert_image_type(Image, &Image, "real");
        sub_image(Image, ImageMean, &ImageSub, 1, 0);
        mult_image(ImageSub, ImageSub, &ImageResult, 1, 0);
        intensity(ImageResult, ImageResult, &Value, &Deviation);
//拉普拉斯梯度函數
        laplace(Image, &ImageLaplace4, "signed", 3, "n_4");
        laplace(Image, &ImageLaplace8, "signed", 3, "n_8");
        add_image(ImageLaplace4, ImageLaplace4, &ImageResult1, 1, 0);
        add_image(ImageLaplace4, ImageResult1, &ImageResult1, 1, 0);
        add_image(ImageLaplace8, ImageResult1, &ImageResult1, 1, 0);
        mult_image(ImageResult1, ImageResult1, &ImageResult, 1, 0);
        intensity(ImageResult, ImageResult, &Value, &Deviation);
//能量梯度函數
        crop_part(Image, &ImagePart00, 0, 0, Width-1, Height-1);
        crop_part(Image, &ImagePart01, 0, 1, Width-1, Height-1);
        crop_part(Image, &ImagePart10, 1, 0, Width-1, Height-1);
        convert_image_type(ImagePart00, &ImagePart00, "real");
        convert_image_type(ImagePart10, &ImagePart10, "real");
        convert_image_type(ImagePart01, &ImagePart01, "real");
        sub_image(ImagePart10, ImagePart00, &ImageSub1, 1, 0);
        mult_image(ImageSub1, ImageSub1, &ImageResult1, 1, 0);
        sub_image(ImagePart01, ImagePart00, &ImageSub2, 1, 0);
        mult_image(ImageSub2, ImageSub2, &ImageResult2, 1, 0);
        add_image(ImageResult1, ImageResult2, &ImageResult, 1, 0);
        intensity(ImageResult, ImageResult, &Value, &Deviation);
//Brenner梯度法
        crop_part(Image, &ImagePart00, 0, 0, Width, Height-2);
        convert_image_type(ImagePart00, &ImagePart00, "real");
        crop_part(Image, &ImagePart20, 2, 0, Width, Height-2);
        convert_image_type(ImagePart20, &ImagePart20, "real");
        sub_image(ImagePart20, ImagePart00, &ImageSub, 1, 0);
        mult_image(ImageSub, ImageSub, &ImageResult, 1, 0);
        intensity(ImageResult, ImageResult, &Value, &Deviation);
//Tenegrad梯度法
        sobel_amp(Image, &EdgeAmplitude, "sum_sqrt", 3);
        min_max_gray(EdgeAmplitude, EdgeAmplitude, 0, &Min, &Max, &Range);
        threshold(EdgeAmplitude, &Region1, 20, 255);
        region_to_bin(Region1, &BinImage, 1, 0, Width, Height);
        mult_image(EdgeAmplitude, BinImage, &ImageResult4, 1, 0);
        mult_image(ImageResult4, ImageResult4, &ImageResult, 1, 0);
        intensity(ImageResult, ImageResult, &Value, &Deviation);

結果分析

處理圖像爲一組對焦從模糊到清晰再到模糊的標定板圖像,如下爲其中三幅圖像:
這裏寫圖片描述
中間爲最清晰的圖像。
採用五種評價函數,對一百多幅圖像進行計算,並將結果進行歸一化,得到如圖所示結果:
這裏寫圖片描述
一個好的評價函數需要具有單峯性,無偏性,靈敏性,在本實例中,採用Laplace、能量梯度和Brenner梯度法較好,而方差法效果較差,Tenegrad梯度法反向了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章