Skip to content

Instantly share code, notes, and snippets.

@JakubMifek
Created January 10, 2018 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakubMifek/abe41779e566be5cee5d04396caa53d3 to your computer and use it in GitHub Desktop.
Save JakubMifek/abe41779e566be5cee5d04396caa53d3 to your computer and use it in GitHub Desktop.
Matlab function for creating Hopfield network from an image containing the alphabet
function [input network] = CreateNetwork( path, width, height )
%CREATENETWORK Summary of this function goes here
% Detailed explanation goes here
img = imread(path);
img = 1-im2double(img(:,:,1));
img = img == 1;
colormap(gray);
img = 1-img;
imagesc(img);
tileW = size(img, 2) / width;
tileH = size(img, 1) / height;
cols = (im2col(img, [round(tileH) round(tileW)],'distinct'));
input = unique(cols', 'rows', 'stable')';
T = input * 2 - 1;
network = newhop(T);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment