Legendre moments are an image component used to limit the representation complexity by invoking Lengendre polynomials. Here we use this components to calculate images' similarities, and recognize the closest pattern for a test image from our database.
- The program is very memory efficient and fast, using C programming language, memory allocation and pointers destruction.
- Legendre moments are stored in triangular allocated 2D arrays.
- the program is dynamic for different degrees of Legendre Coefficients and it is adaptable to larger data-bases.
The only prerequesite needed is a C compiler, go ahead and use your favorite (gcc, clang...). I will use gcc
and make
.
$ sudo apt install build-essential
- Install the MinGW instalation manager
- On All packages window, check
mingw32-gcc-*
andming32-make-*
- Put
C:/MinGW/bin
on your System path.
Run this command to make sure you have the compiler working correctly: gcc --version
git clone https://github.com/ily-R/Legendre-Moments-for-Pattern-Recognition-and-Reconstruction.git
After Installing run the following commands:
cd Legendre-Moments-for-Pattern-Recognition-and-Reconstruction/src
$ make
then a.out
mingw32-make
then a
If you get some problems using make, just run the following command from the src directory:
gcc main.c Reconnaissance_Formes.c myBmpGris.c
and then a
After building the the source files and running the executable file, you should see this:
This will write result/.txt file containing the image reconstructed from the closet image in the database.
Now run the python file to display the results:
python display.py --path result/lady2.txt
- If you want to get more precision, you can change the ordre varible to higher values and uncomment the following:
int main()
{
// if you want to recreate a database uncomment the block bellow
/**
ecrireMlegendre("..\\database\\lady.bmp","..\\LegendreMoments\\lady.txt",ordre,2);
ecrireMlegendre("..\\database\\barre.bmp","..\\LegendreMoments\\barre.txt",ordre,2);
ecrireMlegendre("..\\database\\carre.bmp","..\\LegendreMoments\\carre.txt",ordre,1);
ecrireMlegendre("..\\database\\dessin2.bmp","..\\LegendreMoments\\dessin2.txt",ordre,1);
ecrireMlegendre("..\\database\\dessin3.bmp","..\\LegendreMoments\\dessin3.txt",ordre,1);
ecrireMlegendre("..\\database\\snow2.bmp","..\\LegendreMoments\\snow2.txt",ordre,2);
ecrireMlegendre("..\\database\\stop.bmp","..\\LegendreMoments\\stop.txt",ordre,1);
ecrireMlegendre("..\\database\\cercle.bmp","..\\LegendreMoments\\cercle.txt",ordre,1);
**/
-
if you want to test with another image change the following:
comparaisonImages("testImages\\lady2.bmp","results\\lady2.txt",ordre,a,2,size,true);
-
Don't change beta, the normalization coeff. For better result, test with 1 or 2.
To update the database, but the your images of size (265, 265) into the file database/ and add the following:
ecrireMlegendre("..\\database\\custom.bmp","..\\LegendreMoments\\custom.txt",ordre,1);
a[0]=lireMlegendre("..\\LegendreMoments\\custom.txt",ordre);