I'm not going to implement it here, because the actual implementation of such a thing is quite involved. But I'll try to help speed you along with an explanation at least of what it seems to me that you need to do to solve this in the general case and then in the specific case. I'm going to ignore any discussion of color here, because it's not important.
Description of the problem: You have two images of the world. Image A is just the bit around you at the moment, and image B is the accumulated total world seen so far. Every time you move, image A becomes slightly changed (the whole image slides e.g. left, losing the leftmost elements and gaining new rightmost elements). The goal then is to find the location in image B that best matches image A, and then, if the match is very strong, add the missing elements to image B to fill in the gaps in overlap.
The general case says that maybe you can get teleported around or not map all at once or that there could be another reason why you wouldn't always have a known continuous trail. Let's start with that case and then simplify.
The first time you get an image A, copy it to image B.
Every time you get a new image A:
1) Create an image C where image C is like image B but has empty padding on all sides of the image equal to the size of image A.
2) Look at every possible A-sized subsection of image C. For every such subsection:
1) Compare all of the elements in image A with all of the elements in the subsection.
If they are different only around the perimeter of A and the elements in C are blank, not some other different symbols, then you have a very strong match and should fill in the missing elements in B.
If it doesn't match well enough, discard image A. It's better to be safe than to fill in the wrong elements.
Now if you think about this for a bit, you will realize that this unconstrained image correspondence problem will become very slow very quickly. You also get an unavoidable ambiguity problem, where if two sections of image B look mostly identical but not completely identical, then you could match image A to the wrong location.
Luckily, if you keep track of where you go when mapping and always resume in the same spot as you stopped it becomes much simpler.
Start with an empty image B. It can be really really big, or it can start off the same size as image A and then expand as you get more data. It doesn't matter to me.
The first time you get an image A, copy it to somewhere in image B. Let's say the middle. We'll call that location x0,y0.
Record the coordinate location in image B associated with where you've placed the copy of image A. Let's set this coordinate record as pos={x=x0, y=y0}
Every time you get a new image A:
1) Make an image C that is like image B except with at least 1 move's worth of empty padding on all sides.
2) You know that you have moved only one step from the previous image A.
3) So you can take all the elements from image A and write them to image C in the A-sized window around pos[x-1],pos[y] or around pos[x],pos[y-1] etc.
4) Update pos with the new coordinate.
5) Make image C the new image B.
|