You are on page 1of 2

Experiment No.

-3

AIM: Some Basic Relationship between Pixels

Lab Objectives
This objective of this lab is to understand
1. Determine the convolution and Circular convolution.
2. Determine the Correlation and Circular Correlation.

Activity1: Write a program to create a cirle in image and cameraman image was inserted in the
circle.
Program:
clc;clearall;closeall;
x=imread('cameraman.tif');
y=uint8(ones(256,256));
[r,c]=size(x);
for i=1:r
for j=1:c
R=((j-128).^2+(i-128).^2).^0.5;
if(R>100)
x(i,j)=0;
end
end
end
imshow(x);

2-D Convolution
The 2-D Convolution block computes the two-dimensional convolution of two
input matrices. Assume that matrix A has dimensions (Ma, Na) and matrix B has
dimensions (Mb, Nb). When the block calculates the full output size, the equation
for the 2-D discrete convolution is.

conv2
Two-dimensional convolution
C = conv2(A,B) computes the two-dimensional convolution of matrices A and B. If
one of these matrices describes a two-dimensional finite impulse response (FIR)
filter, the other matrix is filtered in two dimensions.
The size of C in each dimension is equal to the sum of the corresponding
dimensions of the input matrices, minus one. That is, if the size of A is [ma,na] and
the size of B is [mb,nb], then the size of C is [ma+mb-1,na+nb-1].

141001
C = conv2(hcol,hrow,A) convolves A first with the vector hcol along the rows and
then with the vector hrow along the columns. If hcol is a column vector and row is
a row vector, this case is the same as C = conv2(hcol*hrow,A).
C = conv2(...,'shape') returns a subsection of the two-dimensional convolution, as
specified by the shape parameter:

Activity2: Write a program to determine the Linear Convolution of


x(m, n) = [1 2;34]and y(m, n) = [5 6;7 8]

clc;clearall;closeall;
x=[1 2;3 4];
y=[5 6;7 8];
X1=fft2(x);
A=ifft2(X1.*y)

A=2.5 8.5
16.5 22.0

2-D Correlation
Compute two-dimensional cross-correlation of two input matrices
The 2-D Correlation block computes the two-dimensional cross-correlation of two input matrices.
Assume that matrix A has dimensions (Ma, Na) and matrix B has dimensions (Mb, Nb). When
the block calculates the full output size, the equation for the two-dimensional discrete crosscorrelation
isWhere andIf the data type of the input is floating point, the output of the block is the same data
type.The dimensions of the output are dictated by the Output size parameter and the sizes of the
inputsat ports I1 and I2. For example, assume that the input at port I1 has dimensions (Ma, Na) and
theinput at port I2 has dimensions (Mb, Nb). If, for the Output size parameter, you choose Full, the
output is the full two-dimensional cross-correlation with dimensions (Ma+Mb-1, Na+Nb-1). If,
for the Output size parameter, you choose Same as input port I1, the output is the central part of
the cross-correlation with the same dimensions as the input at port I1. If, for the Output size
parameter, you choose Valid, the output is only those parts of the cross-correlation that are
computed without the zero-padded edges of any input. This output has dimensions (Ma-Mb+1,
Na-Nb+1). However, if all (size(I1)<size(I2)), the block errors out.
If you select the Normalized output check box, the block's output is divided by

Activity3: Write a program to determine the circular Correlation of two


functions
x(m, n) = [1 2;3 4]and y(m, n) = [5 6; 7 8]

clc;
clearall;
closeall;
x=[1 2 0;3 4 0;0 0 0];
y=[5 6 0;7 8 0;0 0 0];
X=fliplr(x);
X1=flipud(X);
X2=fft2(X1);
Y=fft2(y);
A=ifft2(X2.*Y)

Output:A = 81423
182039
303870

141001

You might also like