exp_4
exp_4
Apply high-pass and Laplacian filters to sharpen image details, analyze before and after
images.
clc;
clear;
close all;
% Read the image
img = imread('image.jpg'); % Replace 'image.jpg' with your image file
if size(img, 3) == 3
img_gray = rgb2gray(img); % Convert to grayscale if RGB
else
img_gray = img;
end
% High-pass filter kernel
hp_filter = [-1 -1 -1; -1 8 -1; -1 -1 -1];
% Apply high-pass filter
high_pass_img = imfilter(img_gray, hp_filter, 'same', 'replicate');
% Laplacian filter kernel
laplacian_filter = [0 -1 0; -1 4 -1; 0 -1 0];
% Apply Laplacian filter
laplacian_img = imfilter(img_gray, laplacian_filter, 'same', 'replicate');
% Sharpened images
sharp_hp = img_gray + high_pass_img;
sharp_lap = img_gray + laplacian_img;
% Display results
figure;
subplot(2,3,1); imshow(img_gray); title('Original Image');
subplot(2,3,2); imshow(high_pass_img, []); title('High-pass Filtered Image');
subplot(2,3,3); imshow(sharp_hp, []); title('High-pass Sharpened Image');
subplot(2,3,4); imshow(laplacian_img, []); title('Laplacian Filtered Image');
subplot(2,3,5); imshow(sharp_lap, []); title('Laplacian Sharpened Image');
% Histogram analysis
figure;
subplot(1,3,1); imhist(img_gray); title('Histogram - Original');
subplot(1,3,2); imhist(sharp_hp); title('Histogram - High-pass Sharpened');
subplot(1,3,3); imhist(sharp_lap); title('Histogram - Laplacian Sharpened');