質問

いというイメージMATLAB:

y = rgb2gray(imread('some_image_file.jpg'));

いい加工かれています。

pic = some_processing(y);

の地域のマキシマ-の出力に出力します。それは、すべてのポイント y よりも大きて、皆、表札も掲げず隣近所に

ないのですが見MATLAB関数になります。エクスペディアのキャンセができるのは:

[dim_y,dim_x]=size(pic);
enlarged_pic=[zeros(1,dim_x+2);
              zeros(dim_y,1),pic,zeros(dim_y,1);
              zeros(1,dim_x+2)];

% now build a 3D array
% each plane will be the enlarged picture
% moved up,down,left or right,
% to all the diagonals, or not at all

[en_dim_y,en_dim_x]=size(enlarged_pic);

three_d(:,:,1)=enlarged_pic;
three_d(:,:,2)=[enlarged_pic(2:end,:);zeros(1,en_dim_x)];
three_d(:,:,3)=[zeros(1,en_dim_x);enlarged_pic(1:end-1,:)];
three_d(:,:,4)=[zeros(en_dim_y,1),enlarged_pic(:,1:end-1)];
three_d(:,:,5)=[enlarged_pic(:,2:end),zeros(en_dim_y,1)];
three_d(:,:,6)=[pic,zeros(dim_y,2);zeros(2,en_dim_x)];
three_d(:,:,7)=[zeros(2,en_dim_x);pic,zeros(dim_y,2)];
three_d(:,:,8)=[zeros(dim_y,2),pic;zeros(2,en_dim_x)];
three_d(:,:,9)=[zeros(2,en_dim_x);zeros(dim_y,2),pic];

そのような場合は最大での3次元表示され、1層目(これは: three_d(:,:,1)):

(max_val, max_i) = max(three_d, 3);
result = find(max_i == 1);

ああこれまでにないるのか?このような少kludge.

役に立ちましたか?

解決

bw = pic > imdilate(pic, [1 1 1; 1 0 1; 1 1 1]);

他のヒント

ただし、次の 画像処理ツールボックス, ここでは、この構造をどう使用する IMREGIONALMAX 機能:

BW = imregionalmax(y);

変数 BW する論理的なマトリクスと同じサイズ y ものを示す地域は、マキシマをゼロにします。

注意: ご指摘のとおり、IMREGIONALMAXエマキシマよりも大き または等しい 、皆、表札も掲げず隣近所に場合は除外したい隣国マキシマと同じ値(すなわちマキシマを見る単一ピクセル)をご利用 BWCONNCOMP 機能です。以下はできるだけ除去することが望のポイント BW その他近隣には、多くのシングルピクセル:

CC = bwconncomp(BW);
for i = 1:CC.NumObjects,
  index = CC.PixelIdxList{i};
  if (numel(index) > 1),
    BW(index) = false;
  end
end

また、あなたは nlfilter を使用し、独自の機能を供給することができます各近傍に適用される。

このの「検索する厳格な最大」の機能近所の中心は常にこの目的のために3×3である周辺に他のすべての要素よりも厳密に大きい場合、単純にチェックします。したがってます:

I = imread('tire.tif');
BW = nlfilter(I, [3 3], @(x) all(x(5) > x([1:4 6:9])) );
imshow(BW)

あるいは、単に優れたを使用します。 extrema2.mする

のほか、 imdilate, の画像処理ツールボックスなどでもお使いいただけます ordfilt2.

ordfilt2 な価値を地元地域をピックのn番目の値です。(の取り組みを支援例 る方法を示して実施し、最大フィルター) でも実施する3×3ピークファインダ ordfilt2 以下の論理:

  1. を定義する3×3のものをつくる を含まないピクセルセンター (8ピクセル)

    >> mask = ones(3); mask(5) = 0 % 3x3 max
    mask =
         1     1     1
         1     0     1
         1     1     1
    
  2. を選択し、最大の(8)値 ordfilt2.

    >> B = ordfilt2(A,8,mask)
    B =
         3     3     3     3     3     4     4     4
         3     5     5     5     4     4     4     4
         3     5     3     5     4     4     4     4
         3     5     5     5     4     6     6     6
         3     3     3     3     4     6     4     6
         1     1     1     1     4     6     6     6
    
  3. 比較出力のセンターの価値の近く A):

    >> peaks = A > B
    peaks =
         0     0     0     0     0     0     0     0
         0     0     0     0     0     0     0     0
         0     0     1     0     0     0     0     0
         0     0     0     0     0     0     0     0
         0     0     0     0     0     0     1     0
         0     0     0     0     0     0     0     0
    
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top