Active Shape Models are statistical models of the shapes of objects which iteratively deform to fit to an example of the object in a new image. The shapes are constrained by a Statistical Shape Model to vary only in ways seen in a training set of labelled examples.An tutorial MATLAB program from here is used to learn the programming part of ASM.
Firstly, landmarks of target in each training sample are labelled. It will result in a smooth contour by uniform interpolating the landmarks and connecting all points between the landmarks. For each shape (1 shape per sample), we need to translate it to origin and correct its rotation so that shapes in different samples have same mean position (the origin) and orientation. It can be done by subtracting mean position and rotation from original shape, like the following MATLAB code:
% Center data to remove translation offsetv = -mean(Vertices,1); Vertices(:,1) = Vertices(:,1) + offsetv(1); Vertices(:,2) = Vertices(:,2) + offsetv(2); % Correct for rotation % Calculate angle to center of all points rot = atan2(Vertices(:,2),Vertices(:,1)); % Subtract the mean angle offsetr=-mean(rot(1:round(end/2))); rot = rot+offsetr; % Make the new points, which all have the same rotation dist = sqrt(Vertices(:,1).^2+Vertices(:,2).^2); Vertices(:,1) = dist.*cos(rot); Vertices(:,2) = dist.*sin(rot);Vertices is a n-by-2 matrix (in 2D) and n is number of point (include landmarks and interpolated points) in each sample.
Secondly, all normalized points in every sample will be analysed by PCA (principle component analysis) and eigen vectors and values are found over all samples.
[Evalues, Evectors, x_mean]=PCA(x); % Keep only 98% of all eigen vectors, (remove contour noise) i=find(cumsum(Evalues)>sum(Evalues)*0.98,1,'first'); Evectors=Evectors(:,1:i); Evalues=Evalues(1:i);In above code, x is a 2n-by-N matrix where n is number point in each sample and N is number of samples for training. We only remain the larger eigenvalues which indicate the most significant modes of variation in the shape. In this case, 98% of variation can be achieved by accepting 6 (out of 10) largest eigenvalues.
Thirdly, an appearance model which samples a intensity pixel profile/line perpendicular to each contour point in each training set is been made. In this step, normal direction of each contour point is approximated by neighbouring points. More specifically, normal of point 2 is perpendicular to the line connecting point 1 and 3. Since the last point in training set is connected to the first point, therefore, the normal of the 1st point is calculated from the last point and the 2nd point.
Based on the normal, we can get the pixel profiles of every landmark (contour point) perpendicular to the contour. For both positive and negative normal direction, we can set how many pixel we want to have (length of profile).
If we want to search method using PCA on intensities at later application stage, we should apply PCA on the intensity profile first. Again, we remain the eigenvector whose eigenvalue is large so that 98% of total eigenvalue has achieved. With this, noises around contour are removed.
-----------------------------------------------------------------------------------------------------------
The training process of ASM is finished and now we can apply the model on a test sample with target object. We need to give an initial contour approximation of the target manually (automatic solution is achievable using Genetic Algorithm). In each iteration, suggested movement for each model point is calculated in order to minimise the distance to mean of eigenvector.
-----------------------------------------------------------------------------------------------------------
Effect of parameters:
length of landmark intensity profile: determine how many pixels are recorded in perpendicular direction of landmarks.
Could you please explain why we divided by 2 in
ReplyDelete"offsetr=-mean(rot(1:round(end/2)));"
OK, the post was 3 years ago and I can barely remember the detail I done. I can be wrong.
DeleteAfter you centre all points (i.e centre is at origin), if you calculate all points (which are all around the origin), then you may get a 0 degree mean if the points are uniformly distributed.