To perform the spatial convolution/filtering operation, my algorithm first pads the image with the proper number of pixels on the top, bottom, left, and right. The padding colors are simply a reflection of the pixels on the edges. For each pixel in the original image, the neighborhood is taken from the padded image, with the filter being applied using vector dot products. Each dot product is added together, giving the value for the corresponding pixel in the output image.
for row=1:rows
paddedRow = row + filterTop;
for col=1:cols
paddedCol = col + filterLeft;
originalImage =
paddedImage(paddedRow - filterTop:paddedRow + filterTop, paddedCol - filterLeft:paddedCol + filterLeft,:);
redVal = 0;
greenVal = 0;
blueVal = 0;
% Performing dot product with filter for each row of the filter
for filterRow=1:filterRows
filterRowTranspose = reshape(filter(filterRow,:), filterCols, 1);
redVal = redVal + originalImage(filterRow,:,1) * filterRowTranspose;
greenVal = greenVal + originalImage(filterRow,:,2) * filterRowTranspose;
blueVal = blueVal + originalImage(filterRow,:,3) * filterRowTranspose;
end
output(row, col,:) = [redVal, greenVal, blueVal];
end
To make the low-frequency image, the program simply applies a Gaussian blur to the image.
% From the skeleton code
cutoff_frequency = 6;
filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
low_frequencies = my_imfilter(image1, filter);
Identity Image |
Blur Image |
Large Blur Image |
Sobel Image |
LaPlacian Image |
High Pass Image |
To make the high-frequency image, the target image is first blurred using the same filter from the Low Pass Filter section. Then the low frequency image is then subtracted from the original image, leaving only the high frequencies.
high_frequencies = image2 - my_imfilter(image2, filter);
To create the hybrid image, the low-frequency image is simply added to the high-frequency image.
hybrid_image = low_frequencies + high_frequencies;