At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Neural Networks » Applications/Code

Hopfield Image Recognizor (HIR)

Download here (56K).

This collection of two programs are sample programs showing how to use Hopfield neural networks for monochrome image recognition. This page has completely changed with the advent of v2.1, which got rid of the Windows-version limitation on not being able to watch the network stabilize.


Using HIR2

When the program starts up, and loads the program data, it will display (what is supposed to be) the English flag. Use the left and right arrows to the right to look through the 3 images. The second is Japanese for 5, the third is HIR! Now, click on 'Train' and the program will train the network (Hopfield training is REAL quick!) and in the place of the whole images, corrupt images are shown. To get the network to recognize the image, press Run. Red squares will popup where the network changes it.

Callback

The CHopfield uses a cool way of allowing your program to display the network changing if you want by using a pointer to a function. The CHopfield class will call this function every time a pixel is changed. The function obviously has to be static or global, and have the following signature:
int Function(int, int, void *);
Obviously, the function name doesn't make a difference. The first two integers are the xy-coordinates of the point change. The void pointer is whatever you want! I use it in the Windows version to provide a pointer to the main dialog class. The callback function is set by calling SetCallback(). You set the pointer data by calling the SetCallbackData() function. Here is the code from the Windows version:
m_cHopfield.SetCallback(PaintImage);
m_cHopfield.SetCallbackData(reinterpret_cast(this));

// Code removed

int CHIR2Dlg::PaintImage(int x, int y, void *pointer) {
	CHIR2Dlg *dlg = reinterpret_cast(pointer);
	// Paint code removed
	return 0;
}

Version 2.11

Tiny cosmetic change. Added a dialog box after training is complete that explains what has happened, and what the user is then presented with. People got understandably confused.

Version 2.1

Added void pointer to the callback function, allowing the Windows version to show the network stabilizing. Also, improved coding slightly - program would resize the rectangle used to calculate the grid every redraw! It does it once now. I also changed the icon too, if anyone cares!

Last Updated: 21/04/2001

Article content copyright © James Matthews, 2001.
 Article Toolbar
Print
BibTeX entry

Search

Latest News
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)
- NeuroEvolving Robotic Operatives (NERO) (25/06/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)


All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -