0

画像からエッジを抽出しようとしています。次のアルゴリズムを使用しました。512 * 512 グレースケール画像である入力画像 (e11) も与えられます。

  1. 入力画像の形態勾配を求める(gradientim)
  2. グラデーション画像のネガ画像を求める(negativeim)
  3. ボトムハット変換 (bottomhatim) を使用して、閉じたイメージから元のイメージを減算します。
  4. 入力画像の平均ピクセルを計算する(AVG)
  5. AVG に基づいてバイナリ イメージを見つけて、イメージを滑らかにします。
  6. より大きなオブジェクト (CC) を見つけるために、最大の連結領域を見つけます。
  7. 平滑化された画像 (エッジ) から最大領域を減算します。

私が書いたmatlabコードを以下に示します

e11 = imread("lena.jpg");
e11= double(e11);
gradientim = imdilate(e11,se) - imerode(e11,se);
negativeim = imcomplement(gradientim);
bottomhatim = imclose(negativeim,se) -  e11 ;
AVG = mean2(e11);
%-------Computing binary image--------
for i=1:(height)
     for j=1:(width)
         if(AVG > bottomhatim(i,j,:))
              bottomhatim(i,j,:) = 1;
         else
              bottomhatim(i,j,:) = 0;
         end
     end
end
CC = bwconncomp(bottomhatim);
edge = bottomhatim - CC;

ここに画像の説明を入力

手順 7 を実行中に、接続されたコンポーネント (CC) の型が 'struct' であるため、次のようなエラーが発生します。

「タイプ 'struct' の入力引数に対して未定義の関数 'minus'」.

「bwconncomp」関数を使用して、最大の接続領域を見つけることができますか?これに代わる関数はありますか?このコードを修正するのを手伝ってください。よろしくお願いします。

4

1 に答える 1

2

は配列であると想定していますがCC、実際には構造体です。具体的には、これはドキュメントが言っていることbwconncompです:

 bwconncomp Find connected components in binary image.
    CC = bwconncomp(BW) returns the connected components CC found in BW. 
    BW is a binary image that can have any dimension. CC is a structure 
    with four fields:

       Connectivity   Connectivity of the connected components (objects).

       ImageSize      Size of BW.

       NumObjects     Number of connected components (objects) in BW.

       PixelIdxList   1-by-NumObjects cell array where the kth element
                      in the cell array is a vector containing the linear
                      indices of the pixels in the kth object.

アルゴリズムの説明により、最大の連結成分を見つけて、これを画像から差し引いて、最終的な画像を に保存する必要がありedgeます。代わりに使用することをお勧めしますbwlabel。これは、一意の ID で個別の各オブジェクトにラベルを付けるラベル マップを返します。の 2 番目の出力は、bwlabel検出されたオブジェクトの数を返します。

bwlabelと を組み合わせて使用histc​​して、各領域に属するピクセル数を数えます。これを使用して、最大の面積を持つ領域を決定します。次に、このオブジェクトで構成されるマスクを作成し、これを使用してイメージを差し引いて、最終的な出力を取得しますedge

具体的には、コードの最後でこれを行います。

%// Do bwlabel on image
[L, num] = bwlabel(bottomhatim);

%// Count how many values belong to each object, ignoring background
counts = histc(L(:), 1:num);

%// Find which object gives us the largest area
[~,max_id] = max(counts);

%// Make a mask and then subtract
CC = L == max_id;
edge = imsubtract(bottomhatim, CC);
于 2015-03-14T06:06:56.060 に答える