Sie sind auf Seite 1von 5

ROMA PATEL

(K00371921)

7.5. CONVOLUTION EXERCISES

E7.1 Develop a program that convolves a test image with a 3 3


uniform impulse response array for three convolution boundary
conditions. Steps:
o (a) Create a 101 101 pixel, real datatype test image consisting
of a 2 2 cluster of amplitude 1.0 pixels in the upper left corner
and a single pixel of amplitude 1.0 in the image center. Set all
other pixels to 0.0.
o (b) Create a 3 3 uniform impulse response array.
o (c) Convolve the source image with the impulse response array
for the following three boundary conditions: enclosed array,
zero exterior, reflected exterior.
o (d) Print a 5 5 pixel image array about the upper left corner
and image center for each boundary condition and explain the
results.
The PIKS API executable example_convolve_boundary performs this
exercise.

Solution)
%example_convolve_boundary
%Prepare impulse response array
clc; clear all;
Ones = ones(3,3);
Imp = imdivide(Ones, 9);
%Prepare source image
Center = imread('roma.jpg');
Center = rgb2gray(Center);
Center = imresize(Center, [101 101]);
%Ctr = Ctr(1:101, 1:101); %image([1 101], [1 101], 0);
Center(51:51, 51:51) = 1;
Center(1:1, 1:2) = 1;
Center(1:2, 1:2) = 1;

ROMA PATEL
(K00371921)
Center(101:101, 101:101) = 1;
subplot(2, 3, 1); imshow(Center); title('Source image'); %imageinfo;
%pause;
%Enclosed array option, with exclusion of IPPL
iptsetpref('UseIPPL', false);
Work = imfilter(Center, Imp, NaN);
Work(isnan(Work)) = 0;
subplot(2, 3, 2); imshow(Work); title('Convolved with enclosed array');%
imageinfo;
%pause;
%Print upper left corner and mid image pixels
iptsetpref('UseIPPL', true);
Work2 = imcrop(Work, [1 1 4 4]);
Work3 = imcrop(Work, [49 49 4 4]);
a1 = mat2str(Work2, 3);
display('Pixel samples of source convolved with enclosed array');
display('s1 = upper left corner, s2 = mid image');
display(a1);
a2 = mat2str(Work3, 3);
display(a2);
%Zero exterior convolution
Work = imfilter(Center, Imp, 0);
subplot(2, 3, 3); imshow(Work, [0 1]); title('Convolved with zero exterior');
%imageinfo;
%pause;
%Print upper left corner and mid image pixels
Work2 = imcrop(Work, [1 1 4 4]);
Work3 = imcrop(Work, [49 49 4 4]);
a1 = mat2str(Work2, 3);
display('Pixel samples of source convolved with zero exterior');
display('s1 = upper left corner, s2 = mid image');
display(a1);
a2 = mat2str(Work3, 3);
display(a2);
%Reflected exterior convolution
Wrk1 = imfilter(Center, Imp, 'symmetric');
subplot(2, 3, 4); imshow(Wrk1); title('Convolved with reflected exterior');
%imageinfo;
%pause;
%Print upper left corner and mid image pixels
Work2 = imcrop(Wrk1, [1 1 4 4]);
Work3 = imcrop(Wrk1, [49 49 4 4]);
a1 = mat2str(Work2, 3);
display('Pixel samples of source convolved with reflected exterior');
display('s1 = upper left corner, s2 = middle of image');
display(a1);
a2 = mat2str(Work3, 3);
display(a2);

ROMA PATEL
(K00371921)

Pixel samples of source convolved with enclosed array


a1 = upper left corner, a2 = mid image
a1 =
[0 15 30 47 51;18 41 55 73 78;33 56 63 70 73;48 72 73 69 69;47 70 70 66 65]
a2
[75 61 52 49 47;89 66 60 58 67;85 67 66 65 76;69 57 60 63 77;55 58 64 71 79]
Pixel samples of source convolved with zero exterior
a1 = upper left corner, a2 = mid image
a1 =
[0 15 30 47 51;18 41 55 73 78;33 56 63 70 73;48 72 73 69 69;47 70 70 66 65]
a2 =
[75 61 52 49 47;89 66 60 58 67;85 67 66 65 76;69 57 60 63 77;55 58 64 71 79]

ROMA PATEL
(K00371921)
Pixel samples of source convolved with reflected exterior
a1 = upper left corner, a2 = middle of image

a1 =
[1 23 45 71 78;26 41 55 73 78;48 56 63 70 73;70 72 73 69 69;70 70 70 66 65]
a2
=[75 61 52 49 47;89 66 60 58 67;85 67 66 65 76;69 57 60 63 77;55 58 64 71 79]
>>

E7.2 Develop a program that convolves an unsigned integer, 8-bit, color


image with a 5 5 uniform impulse response array. Steps:
o (a) Display the source color image.
o (b) Fetch the impulse response array from a data object
repository.
o (c) Convolve the source image with the impulse response array.
o (d) Display the destination image.

Sol)
clc;
clear;
ctr11 = imread('roma.jpg');%filename);
filename = 'roma.jpg';
label = strcat(filename, ' source image');
figure(1);
subplot(1, 2, 1);imshow(ctr11); title(label,'Interpreter','none');
%imageinfo();
%pause
Imp = fspecial('average', 5);
Dst1 = imfilter(ctr11, Imp, 'symmetric');
label = strcat(filename,' uniform filtered');
subplot(1, 2, 2);imshow(Dst1); title(label,'Interpreter','none');
%imageinfo();

ROMA PATEL
(K00371921)

Das könnte Ihnen auch gefallen