PROJECT REPORT
EC1758 Digital Image Processing
July-Dec 2018
PROJECT BY:-
• SIDHARTH DHAMMI 159108130
• SNEHA SINGH 159108171
• HARSH SHAH 159108169
• MANASI SINGH 159108066
1. BILINEAR INTERPOLATION:
BI.m
im = imread('DIP.jpeg');
out = bilinearInterpolation(im, [270 396]);
figure;
imshow(im);
figure;
imshow(out);
bilinearInterpolation.m
function [out] = bilinearInterpolation(im, out_dims)
%// Get some necessary variables first
in_rows = size(im,1);
in_cols = size(im,2);
out_rows = out_dims(1);
out_cols = out_dims(2);
%// Let S_R = R / R'
S_R = in_rows / out_rows;
%// Let S_C = C / C'
S_C = in_cols / out_cols;
%// Define grid of co-ordinates in our image
%// Generate (x,y) pairs for each point in our image
[cf, rf] = meshgrid(1 : out_cols, 1 : out_rows);
%// Let r_f = r'*S_R for r = 1,...,R'
%// Let c_f = c'*S_C for c = 1,...,C'
rf = rf * S_R;
cf = cf * S_C;
%// Let r = floor(rf) and c = floor(cf)
r = floor(rf);
c = floor(cf);
%// Any values out of range, cap
r(r < 1) = 1;
c(c < 1) = 1;
r(r > in_rows - 1) = in_rows - 1;
c(c > in_cols - 1) = in_cols - 1;
%// Let delta_R = rf - r and delta_C = cf - c
delta_R = rf - r;
delta_C = cf - c;
%// Final line of algorithm
%// Get column major indices for each point we wish
%// to access
in1_ind = sub2ind([in_rows, in_cols], r, c);
in2_ind = sub2ind([in_rows, in_cols], r+1,c);
in3_ind = sub2ind([in_rows, in_cols], r, c+1);
in4_ind = sub2ind([in_rows, in_cols], r+1, c+1);
%// Now interpolate
%// Go through each channel for the case of colour
%// Create output image that is the same class as input
out = zeros(out_rows, out_cols, size(im, 3));
out = cast(out, class(im));
for idx = 1 : size(im, 3)
chan = double(im(:,:,idx)); %// Get i'th channel
%// Interpolate the channel
tmp = chan(in1_ind).*(1 - delta_R).*(1 - delta_C) + ...
chan(in2_ind).*(delta_R).*(1 - delta_C) + ...
chan(in3_ind).*(1 - delta_R).*(delta_C) + ...
chan(in4_ind).*(delta_R).*(delta_C);
out(:,:,idx) = cast(tmp, class(im));
end
INPUT IMAGE:
OUTPUT IMAGE:
1. USING imresize():
resize.m
I = imread('DIP.jpeg');
J = imresize(I,0.3);
figure
imshow(I)
title('Original Image');
figure
imshow(J)
title('Resized Image');
INPUT IMAGE:
OUTPUT IMAGE:
2. DIFFERENCE BETWEEN BILINEAR AND BICUBIC INTERPOLATION:
Bilinear interpolation is a relatively simple technique, not much more complicated than
"nearest neighbour" interpolation—where pixel gaps are filled in by simply copying adjacent
pixels. For every "missing" pixel (the pixels that have to be created to blow up the image)
the bilinear method takes the four points that are closest at the diagonal corners and
averages their values out to produce the middle pixel. Bicubic interpolation, in contrast,
takes not only the four closest diagonal pixels, but their closest points as well, for a total of
16 pixels.
PART II
1. ADDITION OF IMAGE:
imgadd.m
I = imread('DIPs1.jpg');
J = imread('DIPm.jpeg');
K = imadd(I,J,'uint8');
imshow(K,[])
INPUT IMAGES:
OUTPUT IMAGE:
2. IMAGE SUBTRACTION:
imgsub.m
I = imread('DIPh.jpeg');
background = imopen(I,strel('disk',15));
J = imsubtract(I,background);
figure
imshow(J)
INPUT IMAGE:
OUTPUT IMAGE: