Last active
December 8, 2015 04:02
-
-
Save qxcv/4cd21e144c6c9bdc4d0d to your computer and use it in GitHub Desktop.
Applying a small kernel to an image to reduce blurriness.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Demo of a basic filter for deblurring an image | |
% Grab image | |
img_url = 'http://www.artwallpaperhi.com/thumbnails/detail/20121017/sand%20macro%20blurred%201920x1200%20wallpaper_www.artwallpaperhi.com_77.jpg'; | |
img = imread(img_url); | |
img = single(img) / 255; | |
% Apply convolution. Play around with the filter matrix if you're curious. | |
filter = [-1 -1 -1; -1 9 -1; -1 -1 -1]; | |
result = zeros(size(img)); | |
padded = padarray(img, [1 1 0], 'replicate'); | |
for c=1:size(img, 3) | |
convolved = conv2(padded(:, :, c), filter); | |
result(:, :, c) = convolved(3:end-2, 3:end-2); | |
end | |
% Show everything | |
subplot(1, 2, 1); | |
imshow(img); | |
text(0, -12, 'Before'); | |
axis equal; | |
subplot(1, 2, 2); | |
imshow(result); | |
text(0, -12, 'After'); | |
axis equal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment