簡單高效的圖片降噪方法

圖片降噪在很多場合下都要使用到,譬如我遇到的醫療產品。

計算機通過USB口從醫療產品中獲取圖像,但由於硬件的原因,清晰度一直不夠,有很多噪點。

降噪不可避免。降噪算法就是主要問題了。

下面介紹一種簡單高效的降噪方法。

由於硬件拍照造成的噪點是隨機的,要去除這些隨機噪點的方法,其實很簡單,多拍幾張,5張、10張。

對現在的拍照設備來說,拍個10張圖片,也花費不了多長時間,都在毫秒級別。

然後對這幾張圖片進行疊加,這樣的話,那些隨機噪點就會被去除掉。原理我就不說了。可以參考隨機信號理論。

而且效率也很高,都是在內存中操作。


下面給出Delphi疊加圖片函數:


procedure OverlyBmp(const bmp: TArray<TBitmap>; bmpResult: TBitmap);
var
  III, JJJ, KKK   : Integer;
  P               : TArray<PRGBTriple>;
  Q               : PRGBTriple;
  intR, intG, intB: Integer;
  intLen          : Integer;
begin
  intLen := Length(bmp);
  SetLength(P, intLen);
  for III := 0 to bmp[0].Height - 1 do
  begin
    for KKK := 0 to intLen - 1 do
    begin
      P[KKK] := bmp[KKK].ScanLine[III];
    end;
    Q       := bmpResult.ScanLine[III];
    for JJJ := 0 to bmp[0].Width - 1 do
    begin
      intR    := 0;
      intG    := 0;
      intB    := 0;
      for KKK := 0 to intLen - 1 do
      begin
        intR := intR + P[KKK]^.rgbtRed;
        intG := intG + P[KKK]^.rgbtGreen;
        intB := intB + P[KKK]^.rgbtBlue;
      end;
      intR         := Byte(intR div intLen);
      intG         := Byte(intG div intLen);
      intB         := Byte(intB div intLen);
      Q^.rgbtRed   := intR;
      Q^.rgbtGreen := intG;
      Q^.rgbtBlue  := intB;
      for KKK      := 0 to intLen - 1 do
      begin
        Inc(P[KKK]);
      end;
      Inc(Q);
    end;
  end;
  bmpResult.HandleType := bmDDB;
end;

上面的函數,要求圖片是BMP位圖,24位。圖片大小一致。


其它顏色位數的可自行改寫該函數。


我稱這種降噪方法爲疊加降噪。


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