2016-04-22 41 views

答えて

1

私は画像に既に注釈がついていると仮定しています。この場合、マークされた点を見つけて座標を抽出するだけです(コードを使って赤い点を動的に見つける必要がある場合、これはまったく機能しません)

最初に行うべきことは、セグメンテーションに使用します。コードと詳細については、私のSO答えはこちらwhat-should-i-use-hsv-hsb-or-rgb-and-whyを参照してください。良い候補色空間である我々はその彩度(およびいくつかの他を)見ることができます

color spaces

:それは次のような画像が生成されます。それでは、新しい色空間にイメージを転送し、ポイントを見つけるために閾値処理を行う必要があります。

ポイントは、重心を具体的に探してmatlab's region propertiesを使用して取得されます。その時点であなたは完了です。ここ

は完全なコードであり、

im = imread('http://i.stack.imgur.com/eajRb.jpg'); 
HUE = 1; 
SATURATION = 2; 
BRIGHTNESS = 3; 

%see https://stackoverflow.com/questions/30022377/what-should-i-use-hsv-hsb-or-rgb-and-why/30036455#30036455 
ViewColoredSpaces(im) 

%convert image to hsv 
him = rgb2hsv(im); 

%threshold, all rows, all columns, 
my_threshold = 0.8;  %determined empirically 
thresh_sat = him(:,:,SATURATION) > my_threshold; 

%remove small blobs using a 3 pixel disk 
se = strel('disk',3'); 
cleaned_sat = imopen(thresh_sat, se);% imopen = imdilate(imerode(im,se),se) 

%find the centroids of the remaining blobs 
s = regionprops(cleaned_sat, 'centroid'); 
centroids = cat(1, s.Centroid); 

%plot the results 
figure(); 
subplot(2,2,1) ;imshow(thresh_sat) ;title('Thresholded saturation channel') 
subplot(2,2,2) ;imshow(cleaned_sat);title('After morpphological opening') 
subplot(2,2,3:4);imshow(im)   ;title('Annotated img') 

hold on 
for (curr_centroid = 1:1:size(centroids,1)) 
    %prints coordinate 
    x = round(centroids(curr_centroid,1)); 
    y = round(centroids(curr_centroid,2)); 
    text(x,y,sprintf('[%d,%d]',x,y),'Color','y'); 
end 
%plots centroids 
scatter(centroids(:,1),centroids(:,2),[],'y') 
hold off 

%prints out centroids 
centroids 

重心結果=

7.4593
435.3106 355.9255 494.6491 91.1491


.0000
383.0000 87.9911 0

color spaces color spaces color spaces

+0

グレートコーディング(y) – 16per9

+0

赤い点はイメージにはありません。 –

-2

いくつかのサンプルコードでは、特定のソリューションを問題に合わせる方がずっと簡単です。

この一般的な問題の1つの解決策は、impointです。

h = figure(); 
ax = gca; 

% ... drawing your image 

points = {}; 
points = [points; impoint(ax,initialX,initialY)]; 

% ... generate more points 

indx = 1 % or whatever point you care about 
[currentX,currentY] = getPosition(points{indx}); 

よう

何かがトリックを行う必要があります。

編集:impointの最初の引数は、図形オブジェクトではなく軸オブジェクトです。

+0

私には役に立たない –

関連する問題