Skip to content

Instantly share code, notes, and snippets.

@rexlow
Created March 5, 2018 09:26
Show Gist options
  • Save rexlow/8ceee968d9f96f494e48e05ccdedbf3f to your computer and use it in GitHub Desktop.
Save rexlow/8ceee968d9f96f494e48e05ccdedbf3f to your computer and use it in GitHub Desktop.
Matlab Filter Exercise
clear all
close all
clc
elon_ori = imread('elon.jpg');
elon = elon_ori(:, :, 1);
filter_size_3 = 3;
filter_size_7 = 7;
filter_size_13 = 13;
sigma_size = 0.5;
laplacian_alpha = 0.2;
filter_type_average = 'average';
filter_type_gaussian = 'gaussian';
filter_type_laplacian = 'laplacian';
filter_type_prewitt = 'prewitt';
filter_type_sobel = 'sobel';
h_average_3 = fspecial(filter_type_average, filter_size_3);
h_average_7 = fspecial(filter_type_average, filter_size_7);
h_average_13 = fspecial(filter_type_average, filter_size_13);
h_gaussian_3 = fspecial(filter_type_gaussian, filter_size_3, sigma_size);
h_gaussian_7 = fspecial(filter_type_gaussian, filter_size_7, sigma_size);
h_gaussian_13 = fspecial(filter_type_gaussian, filter_size_13, sigma_size);
h_laplacian_3 = fspecial(filter_type_laplacian, laplacian_alpha);
h_prewitt = fspecial(filter_type_prewitt);
h_sobel = fspecial(filter_type_sobel);
r_average_3 = imfilter(elon, h_average_3);
r_average_7 = imfilter(elon, h_average_7);
r_average_13 = imfilter(elon, h_average_13);
r_gaussian_3 = imfilter(elon, h_gaussian_3);
r_gaussian_7 = imfilter(elon, h_gaussian_7);
r_gaussian_13 = imfilter(elon, h_gaussian_13);
r_laplacian_3 = imfilter(elon, h_laplacian_3);
r_prewitt = imfilter(elon, h_prewitt);
r_sobel = imfilter(elon, h_sobel);
subplot(3, 4, 1); imshow(elon); title('Original');
subplot(3, 4, 2); imshow(r_average_3); title('Average 3');
subplot(3, 4, 3); imshow(r_average_7); title('Average 7');
subplot(3, 4, 4); imshow(r_average_13); title('Average 13');
subplot(3, 4, 5); imshow(elon); title('Original');
subplot(3, 4, 6); imshow(r_gaussian_3); title('Gaussian 3');
subplot(3, 4, 7); imshow(r_gaussian_7); title('Gaussian 7');
subplot(3, 4, 8); imshow(r_gaussian_13); title('Gaussian 13');
subplot(3, 4, 9); imshow(elon); title('Original');
subplot(3, 4, 10); imshow(r_laplacian_3); title('Laplacian 3');
subplot(3, 4, 11); imshow(r_prewitt); title('Prewitt with Alpha 0.2');
subplot(3, 4, 12); imshow(r_sobel); title('Sobel');
@rexlow
Copy link
Author

rexlow commented Mar 5, 2018

filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment