- This chapter's assignment caused me
more consternation than any other.
I stewed on it for far too long.
I did what any sane programmer would do.
I did anything other than programming.
I played a computer game.
I went outside.
I even talked with a girl.
These distractions proved beneficial.
By removing my mind from the details of the ordeal,
I was able to see the big picture.
Searching for a subimage is like
searching for anything.
It's a needle in a haystack problem.
You can use C to search for a string of texts
inside a large document,
and that's effectively what the solution
to this puzzle involves.
The assignment is to compare two images.
I could do just that.
Having the code required two file names
as command line arguments.
Simple.
Another approach would be
to have a source file name specified as an argument,
and then specify a directory as the second argument.
The code would then scrub through the directory,
and compare each file in that directory to the source.
A final approach would be
to simply scan the entire directory
and compare each file with every other file.
And this is the most exhaustive method,
and it was also the approach I chose
with my program, subimage.
I'll change to the images folder,
where all the images are held.
This is the sample folder included
with this chapter's exercises,
which you can download on your computer,
just as described in an earlier movie.
I'll type the program name, subimage,
and it finds all JPEG images in the current directory,
comparing each with each other.
Matches are shown in the command line.
This code takes a while to run
because each iteration compares all files with each other.
That's a lot of memory manipulation,
but I coded a few shortcuts to ensure
that things ran as quickly as possible.
Here you can see the 10 JPEG images
supplied with this course.
Two of them are subimage matches,
Here
and right here.
In the next few movies, I'll cover details
on how the code for my subimage program works.