Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MATLAB CODE
% Problem #1 - High Boost Filtering
% ----------------------------------clc;clear all;
x=imread('hw2_1.bmp','bmp');
figure;
subplot(1,2,1);
imshow(x);
xlabel('Original Image');
% convert image to HSV
[h,s,v]=rgb2hsv(x);
% Generate a high pass kernel with a=1
a=1;
hpf = [-1 -1 -1;-1 a+8 -1 ;-1 -1 -1];
% Convolve the kernel with the image
z = conv2(v,hpf,'same');
sizez = size(z);
%linear stretch or just
% If any of element in z is less than 0, the element becomes 0.
% If any of element in z is greater than 1, the element becomes 1.
less0 = find(z < 0);
z(less0) = 0;
more1 = find(z > 1);
z(more1) = 1;
y1 = hsv2rgb(h,s,z); % convert back to RGB
subplot(1,2,2);
imshow(y1);
title('Sharpened Image');
Problem 2:
a. Reduce the noise with box filter 3x3, 5x5, 7x7
MATLAB CODE
%Problem3: - Frequency Domain Transformation
%
clc, clear all, close all;
I = load('2_1.asc');
%creat blurred image
f = conv2(I, 1/9*ones(3,3));
figure
subplot(1,3,1);
imshow(f);
xlabel('Original Blurred Image');
% Laplacian mask
h = [0 -1 0; -1 5 -1; 0 -1 0];
% zero padding.
[m,n]=size(f);
[mh,nh]=size(h);
newf=[f;zeros(mh-1,n)];
newf=[newf zeros(m+mh-1,nh-1)];
newh=[h;zeros(m-1,nh)];
newh=[newh zeros(m+mh-1,n-1)];
% DFT of image and mask
H=fft2(newh);
F=fft2(newf);
% Multiply these two DFTs
Y=H.*F;
% IDFT of the result
y=ifft2(Y);
subplot(1,3,2);
imshow(y);
xlabel('Sharpening Image by using frequency domain transformation');
subplot(1,3,3)
t=conv2(f,h);
imshow(t);
xlabel('Sharpening Image by directly 2-D convolution');
Problem4:
a.
b. Plot g(q) over this range for several values of between 5 and 50
Comment: these functions is greatest near zero frequency, and decreases to 0.01 near the ends of the array
c.
MATLAB CODE
%Problem 4: - Frequency Domain Transformation
%a
%----------------------------------------------------clc;clear;close all;
x=imread('HW2_4.jpg');
figure;
subplot(1,2,1);imshow(x);xlabel('The original image');
%Sharpen using high boost filter
% convert image to HSV
[h,s,v]=rgb2hsv(x);
% Generate a high pass kernel with a=1
a=1;
hpf = [-1 -1 -1;-1 a+8 -1 ;-1 -1 -1];
% Convolve the kernel with the image
z = conv2(v,hpf,'same');
sizez = size(z);
%linear stretch or just
% If any of element in z is less than 0, the element becomes 0.
% If any of element in z is greater than 1, the element becomes 1.
less0 = find(z < 0);
z(less0) = 0;
more1 = find(z > 1);
z(more1) = 1;