Matlabでの画像近傍およびブロック操作(8)



Image Neighborhood Block Operations Matlab



画像近傍演算とは、出力画像のピクセル値が入力画像の特定のピクセルによって決定されることを意味します。
そして、その近傍のピクセル、通常はピクセルの近傍は、画像自体のサイズよりもはるかに小さく、2×2の正方形、2×3の長方形、または同様の丸い多角形などの正多角形のピクセルブロックです。 。近隣操作は、近隣のタイプに応じて、スライディング近隣操作と高近隣操作に分けることができます。

MAILABでは、近隣操作を実装するいくつかの番号が提供されており、ユーザーはこれらの関数を直接呼び出してさまざまな操作を実装できます。



  • 一般的なスライディング近傍操作関数nlfilter()
  • 列方向近傍操作関数colfilt()
  • 個別の近傍操作関数blockproc()

画像処理機能nlfilter

使用法:



B = nlfilter(A,[m n],fun) B = nlfilter(A,[m n],fun,P1,P2,...) B = nlfilter(A,'indexed',...) B = nlfilter(A,[m n],fun) %For each m of image A*n Slider application function fun. %fun function must accept m*n blocks as input, and return a scalar y, like: c=fun(x) c is m*The input value of the center pixel of n block x.

例:

B = nlfilter(A,[3 3],@myfun)

myfunは次のようなmファイルです。

function scalar = myfun(x) scalar = median(x(:))

次に、分離近傍演算機能を導入します
例としてコードを取り上げます。



I = imread('lena_color_512.tif') fun = @(block_struct) imrotate(block_struct.data, 30) %Get function handle for split block operation I1 = blockproc(I, [64, 64], fun) %Perform split block operations fun = @(block_struct) std2(block_struct.data) %Get function handle for split block operation I2 = blockproc(I, [32,32],fun) fun = @(block_struct) block_struct.data(:, :, [3 1 2]) %Get function handle for split block operation blockproc(I, [100 100], fun, 'Destination', 'brg_lena.tif') set(0, 'defaultFigurePosition', [100, 100, 1000, 500]) %Modify the default settings of the image position set(0, 'defaultFigureColor', [1 1 1]) %Modify the settings of the graphic background color figure subplot(131), imshow(I1) subplot(132), imshow(I2, []) subplot(133), imshow('brg_lena.tif')

下の図の最初の部分は、各ピクセルを30°回転させて64×64ピクセルに分割した結果です。
下の図の2つ目は、グラフィックを32×32ピクセルに分割し、各ブロックの値を設定することです。
下図の3番目は緑の層を操作することです

画像


画像処理の過程で、ユーザーは通常、関連する操作のために関心のある領域を選択し、MATLABは画像領域の選択と操作のためのいくつかの関数も提供します。

  • ポリゴンエリア選択関数roipoly()
  • 灰色のROI領域選択関数roicolor()
  • エリア充填関数rofifll()
  • 地域フィルター関数roifilt2()
I = imread('lena_color_512.tif') I = rgb2gray(I) BW1 = roicolor(I, 55, 100) %ROI region selection based on gray image c = [87 171 201 165 79 32 87] r = [133 133 205 259 259 209 133] %Define ROI vertex position BW = roipoly(I, c, r) %Select the ROI area according to r and c I1 = roifill(I, BW) %Fill the area according to the image generated by the BW mask h = fspecial('motion', 20, 45) %Create a motion filter and explain the parameters I2 = roifilt2(h, I, BW) %Regional filtering set(0, 'defaultFigurePosition', [100, 100, 1000, 500]) %Modify the default settings of the image position set(0, 'defaultFigureColor', [1 1 1]) %Modify the settings of the graphic background color figure(1) subplot(121), imshow(BW1) %Display processing results subplot(122), imshow(BW) %Show ROI area figure(2) subplot(121), imshow(I1) %Show fill effect subplot(122), imshow(I2) %Display area filtering effect

結果は次のとおりです。
左の画像は、描写された領域に従って設定されたグレースケール画像であり、右の画像は、頂点を決定した後のROI領域です。
画像
左の写真はROI領域を埋めた効果であり、右の写真はROI領域をフィルタリングした結果です。
画像

  • roicolor
    その中で、roicolorは色に応じて領域を選択でき、使用法は次のとおりです(2次元画像しか処理できないため、カラー画像をグレースケールに変換する必要があります)。
BW = roicolor(A,low,high) BW = roicolor(A,v)

BW = roicolor(A、low、high)カラーマップの範囲は[low high]であり、これらのピクセルの選択領域を返します。 BWは、Aと同じサイズの配列です。Aの要素の値が[low high]の範囲内にある場合、戻り値は1です。それ以外の場合、0を返します。

  • fspecial
h = fspecial(type) h = fspecial(type,parameters,sigma)
タイプ タイプロール
type = ‘average’ これは平均フィルタリングであり、パラメーターはnであり、ベクトルで表されるテンプレートのサイズを表し、デフォルト値は[3,3]です。デフォルトは3 * 3行列です
type = ‘gaussian’ これは、2つのパラメーターを持つガウスローパスフィルターです。 nはテンプレートのサイズを表し、デフォルト値は[3,3]であり、シグマはフィルターの標準偏差をピクセル単位で表し、デフォルト値は0.5です。
type = ‘ラプラシアン’ これはラプラシアン演算子であり、パラメーターはアルファであり、ラプラシアン演算子の形状を制御するために使用されます。値の範囲は[0,1]で、デフォルト値は0.2です。
type = ‘log’ これはラプラシアンガウス演算子であり、2つのパラメーターがあります。nはテンプレートのサイズを表し、デフォルト値は[3,3]、シグマはフィルターの標準偏差、単位はピクセル、デフォルト値は0.5です。
type = ‘prewitt’ これは、パラメータなしでエッジ強調に使用されるプレウィット演算子です。
type = ‘sobel’ これは有名なソーベル演算子であり、パラメーターなしでエッジ抽出に使用されます。
type = ‘unsharp’ これはコントラスト強調フィルターであり、パラメーターalphaはフィルターの形状を制御するために使用され、範囲は[0,1]で、デフォルト値は0.2です。

再び新しい画像処理方法を学び、成果に溢れています。立ち止まるな!