My implementation of Matlab's imfilter takes 2 images, filters the high frequencies out of one, leaving a blurred low frequency image, and keeps only the high frequencies from the other. It then merges the two images to produce a 'hybrid image' which appears to be one of the two original images at a time, depending on the viewing distance.
Algorithm
The filtering algorithm takes in an image (an [x,y,3] matrix for colour images), and a filter (an [x,y] matrix where both x and y are odd). It then pads the image with zeros as wide as half the filter width and as high as half the fliter height. This allows the corner pixels to be calculated without index out of bounds matrix errors. It then loops through the image, once for each layer of colour, through every pixel at that layer. For every pixel, it centers the filter over the pixel, extracts a subsection of the padded matrix equal in size to the filter and then takes the scalar multiplication of the subsection with the filter. This gives a matrix, that when summed, gives an average of the pixel with multiples of its nieghbours that fall under the filter. This value is then assigned to the corresponding pixel in the resulting array.
Creating the Hybrid image
By inputting a gaussian blur as a filter to the above algorith, the reuslt is a low frequency pass of the original image. If you then subtract that pass from the original image you get a high frequency pass on the orginal. I applied each of these techinques to two separate images, and then added the results together, in other words creating an image with the low frequencies of one of the originals and the high frequencies of the other.
Below are examples of images at each stage of the process.
Original1 | Original2 | High Pass | Low Pass
Resultant Hybrid Image
Original1 | Original2 | High Pass | Low Pass
Resultant Hybrid Image
Original1 | Original2 | High Pass | Low Pass
Resultant Hybrid Image
Original1 | Original2 | High Pass | Low Pass
Resultant Hybrid Image
Original1 | Original2 | High Pass | Low Pass
Resultant Hybrid Image