View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Active Shape Model (ASM) and Active Appearance Model (AAM)

4.6 | 49 ratings Rate this file 449 Downloads (last 30 days) File Size: 15.1 MB File ID: #26706 Version: 1.5
image thumbnail

Active Shape Model (ASM) and Active Appearance Model (AAM)


Dirk-Jan Kroon (view profile)


16 Feb 2010 (Updated )

Cootes 2D/3D Active Shape & Appearance Model for automatic image object segmentation and recognition

| Watch this File

File Information

This is an example of the basic Active Shape Model (ASM) and also the Active Appearance Model (AAM) as introduced by Cootes and Taylor, 2D and 3D with multi-resolution approach, color image support and improved edge finding method. Very useful for automatic segmentation and recognition of biomedical objects.

Basic idea ASM:
The ASM model is trained from manually drawn contours (surfaces in 3D) in training images. The ASM model finds the main variations in the training data using Principal Component Analysis (PCA), which enables the model to automatically recognize if a contour is a possible/good object contour. Also the ASM modes contains matrices describing the texture of the lines perpendicular to the control point, these are used to correct the positions in the search step.

After creating the ASM model, an initial contour is deformed by finding the best texture match for the control points. This is an iterative process, in which the movement of the control points is limited by what the ASM model recognizes from the training data as a "normal" object contour.

Basic idea AAM:
PCA is used to find the mean shape and main variations of the training data to the mean shape. After finding the Shape Model, all training data objects are deformed to the main shape, and the pixels converted to vectors. Then PCA is used to find the mean appearance (intensities), and variances of the appearance in the training set.
Both the Shape and Appearance Model are combined with PCA to one AAM-model.
By displacing the parameters in the training set with a know amount, an model can be created which gives the optimal parameter update for a certain difference in model-intensities and normal image intensities. This model is used in the search stage.

- Ginneken B. et al. "Active Shape Model Segmentation with Optimal Features", IEEE Transactions on Medical Imaging 2002.
 - T.F. Cootes, G.J Edwards, and C,J. Taylor "Active Appearance Models", Proc. European Conference on Computer Vision 1998
 - T.F. Cootes, G.J Edwards, and C,J. Taylor "Active Appearance Models", IEEE Transactions on Pattern Analysis and Machine Intelligence 2001

Run the example "ASM_2D_example" and "AAM_AAM_2D_example", the examples are made from manually drawn contours in 10 hand photos (with DrawContourGui). After training the ASM / AAM model will automatically find the contour in the test hand image.

First train the classifier to recognize the Mandible "ASM_3D_train_example" or "AAM_3D_train_example", and then segment with "ASM_3D_apply_example", or "AAM_3D_apply_example".

Please leave a comment, if you like it, find a bug, or know (made) good improvements to the code.


This file inspired Shape Model Builder.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Other requirements For the 3D examples, 64bit Matlab and c-compiler
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (132)
09 Jan 2017 everton skeika

Please,can any one help me with how to make the .mat file for the new training image?

Comment only
08 Jan 2017 Yihao Xia

I have same question about how to make the landmark and refsurface for the training of 3D ASM model. Is there anyone know how to get it?

29 Dec 2016 shanshan zhu

Hi,i have used the statismo software building a shape model,now i want to use this model to segment the target surface(my shape model is 3D),how can i use your code to implement the searching scheme???And which part of your code implement the searching schemeand model fitting???
Thanks very much!

Comment only
23 Dec 2016 shanshan zhu

01 Dec 2016 Nina

Nina (view profile)

Hi, I am trying to run the example of AAM_3D_train_example.m with my dataset.But I don't know how to get the Landmark and RefSurface. Anyone knows ?

Comment only
20 Oct 2016 Alice Wang

05 Oct 2016 Mahmoud Khattab

Thank you very much.
I have the same question about how can i make my datasets (.dcm) like the used dataset. and how can i generate the same number of faces with each of the dataset

01 Sep 2016 Fadzil Hassan

i have the same question as below: How can i use this code to train my own dataset?
Thanks a lot!

04 Aug 2016 Beulah A

How can i use this code to train my own dataset? how to start from the scratch. My email :
Thanks a lot!

Comment only
06 Apr 2016 Xuefeng Peng

Hey, is there anyone who used this code know what does the E_init in AAM_ApplyModel2D.m means? Besides, how could I check the whether the final result is converged or not. i.e what variable should I check to decide convergence.

By the way, "mean point position error" is mentioned in the paper of "Active Appearance Models" fromT.F. Cootes, G.J Edwards, and C,J. Taylor, anyone knows how to compute it?

Thanks very much!

19 Mar 2016 kamel

kamel (view profile)

How can I obtain the same number of vertices and faces from 2 binary volumetric images?
Dear Mr, Kroon,
Thanks for his project codes:
I have a question about how to create the simulation data in the 3D ASM and AAM algorithm. I have some segmented 3D volume (brain mask from volumetric MR images) but as I see for 3D examples that all the Jaw volumes have same number of triangles (vertices and faces).
I used Matlab commands :
[F1 V1] = isosurface (mask 1,0)
[F2 V2] = isosurface (mask2,0)
but in these cases the number of vertices (V1 and V2) are different even for faces. I am just wondering how may I generate the same number of triangles for each images volumetric binary image.

Comment only
14 Mar 2016 Silvia Wognum

Update on my earlier question below.
It appears that all the following toolboxes are required to make the 2D example work (in newer versions of Matlab?):

•Image Processing Toolbox
•Statistics and Machine Learning Toolbox
•System Identification Toolbox
•Control System Toolbox
•Signal Processing Toolbox

Comment only
05 Mar 2016 imad ouloul

houh I can get the shape parametre?

Comment only
18 Jan 2016 Julian Wesley

Hi there, I've seen some materials (e.g. train001.mat, train002.mat, etc) in these tool and yet I still have no idea how to get it, could anyone tell me how to do it?

Thanks before :)

Comment only
14 Jan 2016 Cheng ZHANG

Thanks so much for this program! It runs almost perfectly with my data except for a small problem when choosing the initial position to apply the method. A correct roration of the statistical model on the image is essential which influence the result a lot. But when chosing the initial position manually, the function ASM_align_data2D won't allow chaning the rotation, cause it has been defined based on the barycenter of the model:

% Center data to remove translation
offsetv = -mean(Vertices,1);
% offsetv=barycentre(Vertices);
Vertices(:,1) = Vertices(:,1) + offsetv(1);
Vertices(:,2) = Vertices(:,2) + offsetv(2);

This function works perfectly in the training phase because our data have similar shapes, therefore similar barycenter and rotation along it, although the result displayed are up side down. So I added/modified this function ASL_align_data only in the 'application' part. More precisely, I changed the line 105 in ASM_2D_example.m:
to pos=ASM_align_data_inverse2D_selectpos(pos,tform,roAngle):
defined as follow:

function pos=ASM_align_data_inverse2D_selectpos(pos,tform,roAngle)
% Correct for rotation
rot = atan2(pos(:,2),pos(:,1))+roAngle %pi/2 for example depending on your subject;
rot = rot-tform.offsetr;
dist = sqrt(pos(:,1).^2+pos(:,2).^2);
% *tform.offsets;
pos(:,1) =dist.*cos(rot);
pos(:,2) =dist.*sin(rot);
pos(:,1) = pos(:,1) - tform.offsetv(1);
pos(:,2) = pos(:,2) - tform.offsetv(2);

Hope this helps those who have this rotation issue. And again thanks very much for this program!!!

26 Dec 2015 Jay change

21 Sep 2015 Silvia Wognum

When running the 2D example of ActiveModels_version7, I get an error message:

Undefined function or variable 'interp'.

Error in LoadDataSetNiceContour (line 21)
pointsx=interp(p.x,r); pointsx=pointsx(1:end-r+1);

Error in ASM_2D_example (line 60)

Could it be that the function "interp" doesn't exist in Matlab 2015?

Instead, I tried to use the results of the asm example of creating the training set, but failed.

I hope you can help me solve this problem. I would like to use this example in my lecture on active shape models.


Comment only
16 Aug 2015 Andres Cristancho

¿Para utilizarlo en imagenes MRI del tracto vocal necesito solo MATLAB o tambien necesito un compilador de archivos .C?

Comment only
15 Aug 2015 Lungile Mtetwa

Hi, I am trying to run the example of AAM_3D_train_example.m please advise which code i need run first, as i get can not find path error.

Comment only
06 Aug 2015 Shantanu Banik


Thank you so much for this nice tool. I am trying to use it in 3D and test it on my dataset. I have some segmented 3D volume but as I see for 3D examples that all the Jaw volumes have same number of triangles (vertices and faces). I am just wondering how may I generate the same number of triangles for each images for training?

Comment only
05 Aug 2015 Shantanu Banik

31 Jul 2015 tareq Altalmas

Error using load
Unable to read file 'lips/train001.mat'. No such file or directory.

Error in LoadDataSetNiceContour (line 17)
always i got that error
help me please

Comment only
24 Jun 2015 juned khan

whenever i m running ASM_3D_Train_example is giving linking error.'unable to connect '
max32 error
Plz help me out

17 Jun 2015 Richa Sharma

can any one help me with how to make the .mat file for the new training image?

Comment only
05 May 2015 simin as

.I need some help urgently. I have been trying to implement the AAM_2D_example model for prostat MRI images.The following error was encountered.
Please help me.
Error using -
Matrix dimensions must agree.

Error in AAM_align_data2D (line 25)

Error in AAM_MakeShapeModel2D (line 19)
[TrainingData(i).CVertices, TrainingData(i).tform]=AAM_align_data2D(TrainingData(i).Vertices,MeanVertices);

Error in AAM_2D_example (line 82)
[ShapeData,TrainingData] = AAM_MakeShapeModel2D(TrainingData,options);

Comment only
05 Feb 2015 dpappu

dpappu (view profile)

15 Jan 2015 Ines

Ines (view profile)

I have seen that the effect of varying parameters for appearance normalization is not included in AAM_MakeSearchModel.m. Why? Thanks in advance!

Comment only
21 Nov 2014 zhixiang

There are somethings wrong about the results.Can you tell me how to promote the code?Thank you!

Comment only
12 Aug 2014 subha

subha (view profile)

I am doing my project in lung nodule segmentation. I have to the segment lung alone, for that i am using ASM model. What is the value that i have to use for vertices? Thanks in advance.

Comment only
12 Aug 2014 HEMALATHA P

I am trying to use this ASM model for creating a model of knee image.please i cant understand this coding.kindly explain it.

Comment only
10 Aug 2014 Anum

Anum (view profile)

Hello all !
I am using this code for the lung segmentation of xrays by defining my own landmark points but getting following error :

Subscripted assignment dimension mismatch.

Error in ASM_MakeShapeModel2D (line 20)
x(:,i)=[TrainingData(i).CVertices(:,1)' TrainingData(i).CVertices(:,2)']';

Error in ASM_2D_example (line 82)
[ShapeData TrainingData]= ASM_MakeShapeModel2D(TrainingData);

Can anyone help me out where I am doing wrong ?

Comment only
04 Aug 2014 Anum

Anum (view profile)

Hello all !
I am working on a project for which I have to segment lung regions using ASM from chest xrays. Can anyone help me out that what changes I should made for making this code usable for my project.
Thanks in advance.

Comment only
24 Jul 2014 Wang Hongyu

Thank you very much for the sharing.I hanve a question about how to create the simulation data in the 3D ASM algorithm(eg:V 400*400*352 logical).

Thanks again.

05 Jul 2014 si wei

si wei (view profile)

Hello all,I learned a lot for this model.But when I use this model for face property,It didn't works well.I didn't change the model.Are there any changes in the model?Thanks a lot.

03 Jul 2014 Faniya Mokhayeri

16 Jun 2014 Lianli

Lianli (view profile)

Hi all, I am a bit confused about the use of "face" property. Why specify contour points (vertices) will not suffice? Many thanks!

Comment only
03 Jun 2014 Harley

Harley (view profile)

03 Jun 2014 Harley

Harley (view profile)

27 May 2014 Luca

Luca (view profile)

is it possible to train the software for multiple contours eg. face countour + nose countour?

09 Apr 2014 Taoufik

I need ASM for detection points on the frontal face recognition. I will use for facial expression recognition. My email is:
Thanks a lot!

04 Apr 2014 Sorath Asnani

Hello all. I tried ASM_2D_example.m
It is working perfectly. When I tried it for my own training data set (Images of Guns), after showing the gun images with landmark points upto figure 4, i got the following error.

Subscripted assignment dimension mismatch.

Error in ASM_MakeShapeModel2D (line 19)
x(:,i)=[TrainingData(i).CVertices(:,1)' TrainingData(i).CVertices(:,2)']';

Can anyone help me to resolve this issue?

Comment only
21 Feb 2014 nguyen

nguyen (view profile)

19 Feb 2014 Tang

Tang (view profile)

thanks for your sharing, but there are 2 bugs as I run:
1 function SelectPosition doesn't correspond sometimes, keeping running: while(~data.done), pause(0.1); data=getMyData(); end
2 DrawContourGui get contours perpendicular with real images.

Comment only
22 Jan 2014 Chaw Thim Vai

Hi everyone here, I am new to this image processing topic. I executed this program "AAM_2D_example.m" and there are some errors. I don't know how to solve it. Is anyone here can help me? Thanks
Error using zeros
Out of memory. Type HELP MEMORY for your options.

Error in AAM_MakeSearchModel2D (line 6)

Error in AAM_2D_example (line 154)

Comment only
15 Dec 2013 Andre Agustin

Hi, I'm very new to this and image processing in general but I'm interested in using aam for object recognition/segmentation. It's quite amazing for me and so far AAM_ApplyModel2D works but when it goes to piecewise linear transformation (cp2tform) something goes wrong

it gives this error
'At least 4 non-collinear points needed to infer piecewise linear transform.'

The objects that I was trying to detect were eyeglasses with 7 training images.

Comment only
06 Dec 2013 Ehsan golk

I encounter this error after applying for my own 3D training data please help me:
Error in ASM_align_data3D (line 17)

Error in ASM_MakeShapeModel3D (line 16)

The vectors of my have different dimensions because using marching-cube create different vertices sizes. please hep me if possible.thanks

Comment only
21 Nov 2013 fatemeh

Hi everyone,I applied this code on my images but in part of"% Show some eigenvector variations" my shape shown in incorrect direction and then in part "% Apply the ASM model onm the test image" shape moved in incorrect direction.Does anyone know about this?

Comment only
20 Nov 2013 moha

moha (view profile)

31 Oct 2013 Laura

Laura (view profile)

I would like to use this code with faces (face tracking). Do you know any set of training set images or demo that I can use?



Comment only
17 Sep 2013 WONG

WONG (view profile)

hello,evertyone.I want to apply this code on 3d segmentation.It works well.The only thing I want to know is how to put the trained shape on a initial position for segmenting like the example for 2d hand.I think it's necessary as updated points positions are limited by PCA.If we don't put the trained shape on a initial position like the example for 2d hand,the result should be uncorrect.Thanks.

Comment only
15 Aug 2013 TU Darmstadt

@All with out of memory issues:
This happens because in AAM_MakeSearchModel the variable drdp is 4D, you can just split it into smaller matrices, such as i did it in 2 3D matrices,and did averaging by adding and dividing instead of using mean and squeeze function. Because in the end you are using this drdp for the calculation of matrix R which is 2D

Comment only
19 Jul 2013 Yiping

Yiping (view profile)


Hi, I had the same error as yours, when it tried to allocate a matrix of 13*6*10*468249 = 365234220 double precision values.
I've added a "single" parameter to the "zero" statement that make it use single precision values instead, and it uses approx. 1.3GB of memory now. Before the change it might take 2.6GB, which will cause a "Out of memory" on my PC.
I don't know whether this change will have an impact on accuracy.


04 Jun 2013 Ardeal

Ardeal (view profile)

Hi, All,

when I run the code without any changes after I download it, I get the following error messages:
??? Error using ==> zeros
Out of memory. Type HELP MEMORY for your options.

Error in ==> AAM_MakeSearchModel2D at 6

Error in ==> AAM_2D_example at 154

The RAM of my PC is 4GB, and I have already enlarged the virtual RAM to 3G. I think I have enough memory.
why did that error happen still?

04 Jun 2013 Le Hien

11 May 2013 Ming Jin

goodwork, thanks

07 Apr 2013 liao lulu

how can i use the ASM_2D_example.m to train my own shapes? my email :
thanks a lot!

11 Mar 2013 Zuying Wo

is this sample permitted in commercial use or any development for some commercial purpose?

19 Feb 2013 Isabel

Isabel (view profile)

27 Nov 2012 Jack Sparrow

12 Nov 2012 snoorwal Noorwali

I ran the "AAM_2D_example" in my MAC computer
it is work but it is stuck in some point ! ... I just see the 7 Figures that apeares then it is stuck I am not sure why !!

I have question , how can I implement this code to work in something else (segmenting the vertebra for example)

Comment only
12 Nov 2012 snoorwal Noorwali

I ran the "AAM_2D_example" in my MAC computer
it is work but it is stuck in some point ! ... I just see the 7 Figures that apeares then it is stuck I am not sure why !!

I have question , how can I implement this code to work in something else (segmenting the vertebra for example)

Comment only
06 Nov 2012 LIU WEIHUA

18 Aug 2012 huang

huang (view profile)

28 Jul 2012 ainleuh-89

j ia pas compris le principe de asm si quilqun m'idee pour comprendre le principe d asm

Comment only
18 Jul 2012 Ana

Ana (view profile)

Dear all,

can any one help me with how to make the .mat file for the new training image for 3D?

Comment only
22 Jun 2012 Lacey

Lacey (view profile)

Does anybody have code to apply this to face images? I'm looking to use it to extract the full contour of a face. I can't seem to get the model trained properly. It is always too far rotated one direction or the other, but my training images are all well aligned.

Comment only
20 Jun 2012 Ming

Ming (view profile)

Very Good

07 Jun 2012 saman abdanan

could you please explain to me why you plus and minus 0.5 to the following line of ASM_MAkeAppearanceModel2D
% Get the pixel profiles of every landmark perpendicular to the contour
for i=1:s
P = (TrainingData(i).Vertices-0.5)*scale+0.5;

30 Apr 2012 shweta

shweta (view profile)

Hi all,
I need some help urgently. I have been trying to implement the AAM_2D_example model for fetal ultrasound images. It works perfectly for some training data but generates the below mentioned error in other data sets. I am of the opinion if it is so because of change in image scales for the training sets. So i ran the code for certain similar scale images too still i get stuck sometimes with this error. Although I have made the contours keeping the number of major Landmarks same across all the training images. Please will be grateful if any one of u could give some suggestion to get rid of this error.

??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> AAM_align_data2D at 25

Error in ==> AAM_MakeShapeModel2D at 19

Error in ==> AAM_2D_US at 95
[ShapeData,TrainingData] = AAM_MakeShapeModel2D(TrainingData,options);

Also does the training contours drawn using DrawContourGui need to have same number of major land marks and have to have closed loops?
Will be looking forward to some early replies.

Comment only
30 Apr 2012 shweta

shweta (view profile)

02 Apr 2012 Manoj Murali

See the image with feature points or landmark points marked on an image as shown in the link below:

Now my problem is that I need to write a program which could identify and plot the landmark points on any face image given as the test/input image to the program.I think we need to first train the program with a set of database images with the land mark points.Then I need to use some logic to exactly fit those points on the specific positions in the input image to identify the feature points on the face.So frns how to do this program.What methodology cud be used to do this coding.I need some suggessions..

Comment only
02 Apr 2012 Manoj Murali

Friends my project is to perfom what is shown in the below youtube link using Matlab.Plz help me how to start form the begiining from creation of databases step by step..plz help me..

Comment only
27 Mar 2012 Long

Long (view profile)

The error proclaimed itself: your computer does not have enough memory. Try a better computer.

Comment only
22 Mar 2012 amany

amany (view profile)

hi everybody >>> i need help plz,,,,

i get this error when i applied ASM_3D_train_example.m:

Error using ==> rand
Out of memory. Type HELP MEMORY for your options.

Error in ==> ASM_3D_train_example at 62
I=single(V)-0.5*single(imerode(V,ones(5,5,5))); I=I+rand(size(I))*0.1;

and get the same on applying AAM_3D_train_example.m

i used matlab 2009a and visual studio 2008

Comment only
21 Mar 2012 R

R (view profile)

In 2D DrawContourGui works, does anyone has a solution how a trainingset can be created for a 3D dataset?

Comment only
21 Mar 2012 R

R (view profile)

example=training dataset

Comment only
21 Mar 2012 researcher

to robert,and any one needs to apply this program on his own images, you should use DRawContureGui.m to get the mat file. you will find the program in functions folder.

save the mat files and use them in the example program.

Comment only
15 Mar 2012 robert

robert (view profile)

Dear all,
can any one help me with how to make the .mat file for the new training image?

Comment only
14 Mar 2012 Chen

Chen (view profile)

In the file ASM_align_data2D.m, the position and rotation are considered during aligning the training set, but the scale is not considered. It seems that the align process is simplified very much.

Comment only

If anyone has applied it for face recognition please share the code. It will be much appreciated.

Comment only
17 Jan 2012 Filka Yaneva

Dear Fati,
I have the same quenstion. Did you get some answer?

Thank you very much,

Comment only
17 Jan 2012 Fatima laghrafi

Dear all,
Ineed facial expression recognition AAM or ASM ? how can I use this code to train my own databse?.
my email :
Thanks in advance.

Comment only
16 Jan 2012 Fatima laghrafi

Dear all,
Can I use this demo for Facial expression recognition? If so, could you please specify what parts need to be modified ?.

Thanks in advance.


Comment only
06 Jan 2012 Ray

Ray (view profile)

02 Jan 2012 alps jia

Dear all
when I was running "ASM_2D_example.m",
I have some questions about "ASM Functions\ASM_ApplyModel2D.m ":
In the file
code number:66-70
"for k=1:size(Itest,3),
I have made some changes about "coffset2" as follows:
But it does not get a correct resoult,
So I want to know how to align "gt",

Comment only
07 Dec 2011 marshmallow

I need a Face recognition model too, how could I train my own face as dataset? my email is:
Thanks a lot!

Comment only
24 Nov 2011 Sriraj

Sriraj (view profile)

Anybody tried this code for Face recognition pls share Face shape model with me at

Comment only
22 Oct 2011 divya

divya (view profile)

Thanx for d have done a great job.i am doing my thesis on sign language recognition. i have segmented the hand and done with fingertips detection and tracking.i want to do feature extraction using PCA(principal component analysis). please suggest me which features should i take to match signs and how to do this. I shall be very thankful to you

Comment only
10 Oct 2011 yayun

yayun (view profile)


When I executed the ASM_2D_example.m, I got this information

"can't find interp2fast_double.mexw32.manifest" , and I check the folder, it only produced a file called interp2fast_double.mex not interp2fast_double.mexw32.manifest, so how can I do to solve this problem? By the way, my computer system is Windows7 and Matlab version is (R2009b)7.9.0.
Thank you very much!!!

Comment only
23 Aug 2011 shruti saraswat

Hello,How can we rotate the landmarking image? is there any coding or just a key function? Please help I am learning this landmarking.

Comment only
15 Aug 2011 Jiahao Qiu

13 Aug 2011 Jiahao Qiu

??? Referance to non-existent field 'offsetv'.
Error in ==>AAM_align_data_inverse2D at 15 Vertices(:,1) = Vertices(:,1)-tform.offsetv(1).
Error in==>AAM_2D_example at 188
pos = AAM_align_data_inverse2D(pos,tform)
How can i maintain the code,which will run successully?

30 Jul 2011 Jiahao Qiu

Dear Mr, Kroon,
When i run the 'AAM_2D_example.m' on matlab 2010a,the command window shows 'compile c-files failed :example will be slow'.How can i compile c-files successful?
Thanks in advance.

Comment only
29 Jul 2011 samia dop

please i need a help i need just someone how can send me training data wich he used just 10 images tks for all

Comment only
27 Jul 2011 fpuspitasari

hi, when training the data, should the image contour be located in roughly the same location? what if I have several hand images with different orientation, e.g. horizontal and 45 degree angle. should I do some pre-processing before training the data. thanks

Comment only
10 Jul 2011 samia dop

first u choose ur image for example u do that:
im2=lirimage;u read ur training data then u save it
save('samia','im2');ur training data now is called samia.mat

Comment only
06 Jul 2011 Pasindu Abeysundera

How do we create the .Mat files in the training data. Can some one please enlighten me?

Comment only
03 Jul 2011 samia dop

When I execute either ASM_example.m or AAM_example.m
I met an error:
??? Undefined variable "p" or class "p.x".

Error in ==> efface at 21
pointsx=interp(p.x,r); pointsx=pointsx(1:end-r+1);

Comment only
07 Jun 2011 Zheng

Zheng (view profile)

I read the code again. I find that the function AAM_NormalizeAppearance.m is used to compensate for illumination, and plays the similar role to the texture transform parameter u.

Comment only
07 Jun 2011 Zheng

Zheng (view profile)

The classical aam model contains three parts of paramters: c,t,and u. u is the texture transformation. But in the function AAM_MakeSearchModel.m, u is not included. Why? and how to include it?

07 Jun 2011 Munie Ahmad

Hi SDU, now it works perfectly! Thank u so much for your solution :)

Comment only
05 Jun 2011 sdu

sdu (view profile)

Hi,Munie Ahmad,I meet the same trouble like yours.I do this like below:Add the function'save' after AppearanceData.It you want to use training data, then 'load'.
AppearanceData = ASM_MakeAppearanceModel(TrainingData,options);

Comment only
05 Jun 2011 Munie Ahmad

Hi there, I've tried with my image database (chest x-ray, for lung segmentation), it works, many thanks! But how can I run the algorithm for batch processing without repeating the 'training process'? Thank u in advance..

08 May 2011 sdu

sdu (view profile)

With my training data,It works,Thank you!

22 Apr 2011 Joy King

I'm using ASM and AAM to train and segment carotid ultrasound images. ASM_example.m works very well, But when I execute AAM_example.m, I met an error:
??? Error using ==> cgprechecks at 47
Not enough unique points specified.

Error in ==> delaunayn at 48
cgprechecks(x, nargin, cg_opt);

Error in ==> delaunay at 50
tri = delaunayn([x(:) y(:)]);

Error in ==> PreProcessCp2tform at 43
tri = delaunay(xy(:,1),xy(:,2));

Error in ==> AAM_Appearance2Vector at 20
[xy uv]=PreProcessCp2tform(xy,uv);

Error in ==> AAM_MakeAppearanceModel at 32
g(:,i)=AAM_Appearance2Vector(TrainingData(i).I,TrainingData(i).x,TrainingData(i).y, base_points,

Error in ==> AAM_example at 90

If I use your dataset, it works very well. I really don't know why, hoping you can help me or give directions. Thanks in advance.

Comment only
18 Apr 2011 Saidani

thesis a good work
can i use this work for face base
if yes how
please help me

Comment only
17 Mar 2011 mirs

mirs (view profile)

Here is maybe the solution, by I can´t tell exactly, didn´t try yet.

Comment only
17 Mar 2011 Agnieszka

I have the same problem with function DrawContourGui.m. Have anyone knows how to run this function without error. Thanks in advance

Comment only
16 Mar 2011 mirs

mirs (view profile)

Thanks a lot! I would like to use your work as a part of my school project, which deals with facial detection (nose, eyes, mouth). For face detection, I am going to use Viola-Jones detector, for it´s parts AAM and ASM. But I have a little problem, when I´m trying to run DrawCountoutGui, there is some kind of bug "Segmentation violation". Could you please tell me, how to run it properly?

Best regards

Comment only
08 Mar 2011 Manuel

Manuel (view profile)

03 Mar 2011 Green_Apple

I have researched about this.Can you share your code with me for reference, Weiyuan?

Thanks and best regards!

01 Mar 2011 Fettah Light


i want just know how i can get the train.mat from an image, so if u have code source of this function ,can u give it to me

With my best regards

Comment only
28 Feb 2011 Nslakshmi

Anybody tried this code for Face recognition pls share Face shape model with me at

27 Feb 2011 Weiyuan

Very good.

I made some modifications for faces, and it works!! Thanks a lot.

04 Feb 2011 Aakash

Aakash (view profile)


24 Jan 2011 Qiang Li

I applied it on faces with little revisions:
First, in building of the combine model, 'dpdr' may be too large for a real application. I replaced it by averaging submatrix in the big loop.
Second, 'svds' in pca may cause unexpected mistake... I use svd instead, though it may slower...

02 Jan 2011 A.Rahim

Dear all

I want to apply this script on my own images. Could guide me how I can do this (in which order I should use the function) ?

Comment only
18 Dec 2010 Muhammad

"??? Subscripted assignment dimension mismatch.

Error in ==> ASM_MakeShapeModel at 20

I am using this code for ear. I trained 10 images of ear. but I am getting this error. can any one help me plzzzz

Comment only
15 Sep 2010 xudong cao

very good!

13 Sep 2010 Mofakharul

Do we need to convert screen coordinates into image coordinates? If yes, then how it could be done?


Comment only
07 Aug 2010 Iqbal Nouyed

Dear Mr, Kroon,
Can I use this demo for Facial expression recognition? If so, could you please specify what parts need to be modified ? I am trying to train and test it with the data set given with the cootes' aam tools.

Thanks in advance.


Comment only
16 Jul 2010 Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

* Zhi
Interp is part of the "Signal Processing Toolbox" of Matlab.

Comment only
15 Jul 2010 Zhi

Zhi (view profile)

When I execute either ASM_example.m or AAM_example.m
I met an error:
??? Undefined function or method 'interp' for input arguments of type 'double'.

Error in ==> LoadDataSetNiceContour at 21
pointsx=interp(p.x,r); pointsx=pointsx(1:end-r+1);

So where is interp.m?

Comment only
19 Jun 2010 Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*ISI Purkait

The size of a dataset will not cause an error. Try to display some in between results, maybe you find the error

Comment only
18 Jun 2010 Greg B

Greg B (view profile)

Is it possible to have multiple contours in a model with this program? Imagine two separate eyes or distinct image features that are not connected. If it can't do multiples, I'll just double back when drawing contour lines or attempt to add multiple contour on my own :)
Thanks for the program, I've been looking for it for a long time and it works great!

Comment only
10 Jun 2010 ISI Purkait

Why this program is not working for large dataset??....I made some hand images on my own....there are 34 images ....but it's working but texture is not comming well...!!

01 Apr 2010 Ashwith Rego

In the function AAM_align_data.m, you have chosen the base to always be the first shape. According to Procrustes analysis, isn't the base supposed to be the mean of the current set of aligned shapes? Am I missing something in your code or are you using some sort of modified Procrustes analysis which aligns all shapes to the first shape? If it is the latter how much difference would it make in the result?

Comment only
25 Mar 2010 Ashwith Rego

I figured it out. Took me some time to realize what exactly you meant. Thanks a ton again! :-)

Comment only
25 Mar 2010 Ashwith Rego

Thanks for your reply.
How do you convert between screen coordinates and image coordinates?

Comment only
25 Mar 2010 Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

* Ashwith ,
The x and y are indeed the row and column indexes, but if you click the mouse the coordinates are converted from screen coordinates to image coordinates, which gives the .1234 numbers, and also of course the linear interpolation between the landmarks.

The Matrix I, is the training image.

The vector t, specifies if a point is a major well defined landmark (like the top of a finger), or a minor point along an edge.

Comment only
25 Mar 2010 Ashwith Rego

Could you tell me how one selects the landmark points. And how do you set the coordinates of these points? Till now I was under the impression that the coordinates are the row and column indexes of the pixel in the image matrix. I saw x and y having values like 216.8761?
Secondly, for the database of training images, what are vector t and matrix I for? I understand x and y give the coordinates of each point. What are t and I?
This is my first project in image processing so I really have no clue.
Thanks in advance!

24 Mar 2010 M Ladderman


02 Mar 2010 1.1

PCA bug fix.

17 Mar 2010 1.2

Added the Active Appearance Model

22 Mar 2010 1.3

Added Color support, new edge finding method in ASM, and contour starting point GUI.

20 Jul 2011 1.4

Added 3D examples.
Added LinearWarp function

26 Jan 2012 1.5

Many bugfixes and ASM and AAM optimizations

Contact us