2016-04-17 9 views
-2

私は白黒画像を持っています。イメージビューアでこのイメージの特定のcoordinate (x,y)を見ると、値が0であることがわかりました。しかし、私のスクリプトで(x,y)から値を取得したい場合は、255が得られます。コードは以下のようになります。matlabで黒のピクセルを白にする

bw = imread('my_map.png'); 
    imshow(bw); 
    hold on 
    % find corners of obstacles 
    corners = detectHarrisFeatures(bw); 
    plot(corners.selectStrongest(50)); 
    cornerPoints = corners.selectStrongest(50); 
    hold on 
    % determine line's equation for two particular corners 
    m = cornerPoints.Location(4,2)-cornerPoints.Location(3,2); 
    n = cornerPoints.Location(4,1)-cornerPoints.Location(3,1); 
    k = (m)/(n); 
    b = cornerPoints.Location(3,2) - k*cornerPoints.Location(3,1); 

    %determine if this line intersects any obstacle 
    black = 0; 
    white = 0; 
    for y=cornerPoints.Location(3,2):1:cornerPoints.Location(4,2) 

     x = (y-b)/k; 
     if (int16(x) == 0) 
      x = cornerPoints.Location(3,1); 
     end 
     plot(int16(x),int16(y),'r*') 
     hold on 
     c = bw(int16(x), int16(y)); 
     if (c==255) 
      white=white+1; 

     else 
      black=black+1; 
     end 
    end 
    if (white == 0) 
     display('valid') 

    else if (black <= 2) 
     display('valid') 
    else 
     display('invalid') 
    end 

画像がこの

this oneです。

何が問題なのですか?

+0

私はあなたには、いくつかのコードを追加しますお勧めします。それ以外の場合、私はあなたが答えを得るとは思わない。 – Lukasz

+1

おそらく座標系の原点に注意する必要があります。また、MATLABは1ベースのインデックス – Amro

答えて

0

Matlabでは、行列の最初の座標は行インデックスを表し、2番目の座標は列インデックスを表します。

従って、行インデックスyと列インデックスXと行列M、すなわち、点(x、y)にアクセスするために、次のように記述する必要があります。あなたのケースで

M(y,x) 

を、あなたがすべき書き込み:

c = bw(int16(y), int16(x)); 

の代わり:

c = bw(int16(x), int16(y)); 
+0

を使用することを覚えておいてください。[xとyの交換後の見方](https://www.dropbox.com/s/ud1wo0o1o8iwg07/%D0%A1%DBA%D1%80%D0 %B8%D0%BD%D1%88%D0%BE%D1%82%202016-04-18%2000.48.52.png?dl = 0)。何かがおかしい。赤い線は、青い星から赤の星に移動する必要があります。 –

+0

もう一度、xとyの値が混在しています。線の(x、y)座標と赤と青の星の(x、y)座標を見ると、まったく逆です。 – drorco

関連する問題