メディアンフィルターの一般化

注釈



この記事では、1990年に登場したユニークなフィルターについて説明しています。MaslovA.M.、Sergeev V.V. ランク信号処理を使用した線形歪みシステムの識別//コンピューター光学。 -M.、1990。-第6号。 -S.97-102。 このアルゴリズムは「ランク処理アルゴリズム」と呼ばれ、実際にはメディアンフィルターの一般化です。

このフィルターの使用は、ノイズの抑制とグリースの削減の2つの場合に正当化されます。

画像

図1-元の画像、 2-ぼやけてノイズの多い塩。





信号処理アルゴリズム-極端なフィルター



このアルゴリズムは、ローカルウィンドウで画像を処理し、処理結果を新しい画像で記録することで構成されます。

  1. 我々は画像座標(I、J)の地点にあると仮定- 現在のカウント
  2. 現在のフレームの周りのサイズN×N個の局所近傍と考えられています
  3. 近隣内蔵loalnoyの内の画素の値から変化番号 Pで示されます、。 この行のサイズはN * Nです。
  4. 現在のカウント出力画像は、以下の規則に従って値を取ります。


画像

ここで、 kはアルゴリズムのパラメーター、 Nは奇数、 Im1は元の画像、 Im2は結果の画像です。

k =(N ^ 2 + 1)/ 2-つまり、変分級数の中心-このフィルターは既知の中央値フィルターになります。 将来、このパラメーターはindentationと呼ばれます。



極端なフィルターのプロパティ



このフィルタのプロパティは、実際には非常に便利です。フィルタを使用すると、ノイズだけでなく、画像のぼけの影響を(部分的に)除去できるためです。 k =(N ^ 2 + 1)/ 2でのこのフィルターの制限的なケースは、ノイズを除去するだけで境界に触れないメディアンフィルターであり、画像がぼやけている場合、ぼやけは残ります。



k <(N ^ 2 + 1)/ 2では、ノイズはわずかにフィルタリングされますが、画像の鮮明度は向上し、 k = 0では、ノイズはまったくフィルタリングされませんが、グリースは最も強力に除去されます。



このアルゴリズムの基本的な実装で読者を煩わさないために、ここでMatlabでコードを提供します。

テストスクリプトは画像を読み取り、ぼかし、ノイズを追加します。 次に、これらの極端なフィルターによって画像が復元されます。

I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  1. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  2. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  3. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  4. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  5. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  6. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  7. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  8. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  9. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  10. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







  11. I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .







I1 = imread( 'coins.png' ); h = ones(3,3) / 9; I2 = imfilter(I1,h) ; I3 = imnoise(I2, 'salt & pepper' ,0.02); I4 = im2_rang_filter (I3, 1, 2); figure; imagesc(I1); colormap gray; figure; imagesc(I3); colormap gray; figure; imagesc(I4) colormap gray; * This source code was highlighted with Source Code Highlighter .











フィルター機能コードim2_rang_filter

function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  1. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  2. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  3. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  4. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  5. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  6. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  7. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  8. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  9. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  10. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  11. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  12. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  13. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  14. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  15. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







  16. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .







function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup) [ver,hor] = size(aImage); wsize = (aHalfWindowSize*2+1)^2; result = zeros(ver,hor); for i = aHalfWindowSize+1 : (ver - aHalfWindowSize) for j = aHalfWindowSize+1 : (hor - aHalfWindowSize) wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize)); vec = reshape(wind,1,wsize); vec = sort(vec); if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) ) result(i,j) = vec(aOtsup+1); else result(i,j) = vec(wsize - aOtsup); end ; end ; end ; outImage = result; * This source code was highlighted with Source Code Highlighter .









実験



以下に示すのは、パラメータk = 1.2.5を変化させたときの3 x 3ウィンドウでのフィルタリングの結果です。 最初の画像は元の画像で、2番目の画像は歪んでおり、k = 1、2、5のフィルターされたフィルターは互いに続きます。

ソース:

画像

歪んだ:

画像

k = 1で再構築

画像

k = 2で回復

画像

k = 5で再構築:

画像



私はこのフィルターが大好きで、実際に積極的に使用しています。 読者はこのフィルターに興味があります。



All Articles