⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 label.m

📁 rang doppler imaging and motion compensation中的源代码
💻 M
字号:
function X = label(imagen);

% Labelling of several components in a binary image.
%	function X = label(imagen)
% 	in:  imagen = binary image to be label
% 	out: X = labelled image with 1,2, .... numbers for
%           each component; same size as imagen.

% Written by:  Gabriel Thomas. Jan/21/98.
% Version 1.0

% Add two columns and a row of zeros of original image

[x y] = size(imagen);
im2 = zeros(x+1,y+2);
im2(2:x+1,2:y+1) = imagen;
X = zeros(size(im2));

% Initialize labels

N = 0;

% Scan the image and label  (See ref.)

for i = 2:(x+1)
 for j = 2:(y+1)

  if ( im2(i,j)==1 )
	if ( (X(i-1,j-1)==0)&(X(i-1,j)==0)&(X(i-1,j+1)==0)&(X(i,j-1)==0) )
	  
	  N = N+1;    % Select new label for new object
	  X(i,j) = N; % Assign label to pixel
 	
	else

	  vec = [X(i-1,j-1) X(i-1,j) X(i-1,j+1) X(i,j-1)];
	  ma = max(vec);
	  X(i,j) = ma;
	  valc = find( (vec~=max(vec))&(vec~=min(vec)) );
	  if ~isempty(valc)
	     for tt = 1:length(valc);
	        val = vec(valc(tt));
		[I,J] = find(X == ma); 
	       for t = 1:size(I)
		 X( I(t),J(t) ) = val;
	       end
	     end
	  end

	end
  end

 end
end

% Restore original size (delete extra cols. and rows).

X(1,:) = [];
X(:,1) = [];
X(:,y+1) = [];

% Make labels to be 1,2,3, ......

XX = reshape(X,1,x*y);
XX = sort(XX);, XXd = diff(XX);
pos = find( XXd~=0 ); % Positions where dif. values are.
final = zeros(size(X));
for i = 1:length(pos)   % Start with two in order to skip the zero
  fin = X==XX(pos(i)+1);
  fin = fin.*i;
  final = fin + final;
end
  
X = final;

imagesc(-X)
colormap(gray)

% Reference:

% E. R. Davies, Machine Vision, Thoery, Algorithms, Practicalities,
% 2nd edition, Academic Press, 1997. pp. 133 - 137.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -