2017-04-20 2 views
0

Ich habe eine gepaarte Matrix mit Pixeln gleich 0 oder 255, und wenn es 255 ist, macht es Disk Form. Ich möchte die verschiedenen Datenträger beschriften und für jedes Etikett einen Tab bekommen: ihren Radius und ihren Mittelpunkt. Wie kann ich für diese letzten zwei Punkte tun?erhalten Eigenschaften von Matrix

Unterhalb einen exemple mit einer kleinen Matrix

Mat=zeros(12,12); 
Mat(2,6:7)=255; Mat(3,5)=255; Mat(3,8)=255; Mat(4,5)=255 
Mat(4,8)=255; Mat(5,6:7)=255; 

Mat(10,10)=255; Mat(11,9)=255; Mat(12,10)=255; Mat(11,11)=255; 

CC=bwconncomp(Mat,8); 
MatL=labelmatrix(CC); 

figure, imagesc(Mat) 
+0

Was tun Sie meinen mit "Get in a tab"? Was ist die erwartete Ausgabe? – rayryeng

+1

['regionprops'] (https://nl.mathworks.com/help/images/ref/regionprops.html) ist möglicherweise das, wonach Sie suchen. – m7913d

Antwort

0

Sie regionprops Schwerpunkt und Fläche zu berechnen, verwenden können, und dann Bereich ungefähren Radius berechnen verwenden:

% generate matrix 
Mat=zeros(12,12); 
Mat(2,6:7)=255; Mat(3,5)=255; Mat(3,8)=255; Mat(4,5)=255; 
Mat(4,8)=255; Mat(5,6:7)=255; 
Mat(10,10)=255; Mat(11,9)=255; Mat(12,10)=255; Mat(11,11)=255; 
% convert to binary 
MatBin = Mat > 0; 
% fill circles 
MatFull = imfill(MatBin,4,'holes'); 
% get centroids and areas 
props = regionprops(MatFull,{'Area','Centroid'}); 
Area = [props(:).Area]; 
Centroid = reshape([props(:).Centroid],[],2)'; 
% compute radius 
Radius = sqrt(Area ./ pi); 
% plotting 
imshow(MatFull,[],'InitialMagnification','fit') 
hold on 
for ii = 1:numel(Radius) 
    text(Centroid(ii,1),Centroid(ii,2),['r = ' num2str(Radius(ii))],... 
     'VerticalAlignment','middle','HorizontalAlignment',... 
     'center','FontSize',12,'Color','b'); 
end 
hold off 

enter image description here

Verwandte Themen