You are on page 1of 7

MID SEM LAB

AKASH MOHAN SINGH 19419MCA010

QUESTION 1 to 3
img=rgb2gray(imread("akash8.jpg"));

i1=imresize(img,[512,512]);

i2=imresize(img,[512,512]);

i3=imresize(img,[512,512]);

I=imresize(img,[512,512]);

x=rand(size(i1));

i1(x(:)>0.95)=255;

x1=rand(size(i2));

i2(x(:)<0.05)=0;

gauss = imnoise(i3,'gaussian',0.01);

[r, c]=size(I);

I=im2double(I);

k=0.08; %here we have claculated value k by k=b-I(i, j)

%uniform noise introduction

U = min(1, I + k * rand(size(I)));

subplot(221);

title("salt"); imshow(i1);
subplot(222);

title("peper"); imshow(i2);

subplot(223);

title("gausian"); imshow(gauss);

subplot(224);

title("uniform"); imshow(U);

Question 4 REMOVING NOISE


img=rgb2gray(imread("akash8.jpg"));
i1=imresize(img,[512,512]);
i2=imresize(img,[512,512]);
i3=imresize(img,[512,512]);
I=imresize(img,[512,512]);

Is=i1;
x=rand(size(i1));
i1(x(:)>0.95)=255;
min=@(x)min(x(:));
min_im=nlfilter(Is,[3 3],min);

ip=i2;
x1=rand(size(i2));
i2(x(:)<0.05)=0;
max=@(x)max(x(:));
max_im=nlfilter(ip,[3 3],max);

gauss = imnoise(i3,'gaussian',0.01);
sigma=3;
cutoff = ceil(3*sigma);
h=fspecial('gaussian',2*cutoff+1,sigma);
out = conv2(i3,h,'same');
out1 = conv2(gauss,h,'same');
w = wiener2(gauss,[5,5]);
surf(1:2*cutoff+1,1:2*cutoff+1,h)

subplot(221);
imshow(min_im); title("REMOVED SALT NOISE");

subplot(222);
imshow(max_im); title("REMOVED PEPPER NOISE");
subplot(223);
imshow(w); title("REMOVED GAUSS");
subplot(224);
imshow(I); title("REMOVED UNIFORM");
HALF MAN coding and Compression Ratio
img=rgb2gray(imread("abhif.jpg"));

i1=imresize(img,[512,512]);

i2=imresize(img,[512,512]);

i3=imresize(img,[512,512]);

i4=imresize(img,[512,512]);

Is=i1;

x=rand(size(i1));

i1(x(:)>0.95)=255;

min=@(x)min(x(:));

min_im=nlfilter(Is,[3 3],min);

I=min_im;

ip=i2;

x1=rand(size(i2));

i2(x(:)<0.05)=0;

max=@(x)max(x(:));

max_im=nlfilter(ip,[3 3],max);

gauss = imnoise(i3,'gaussian',0.01);

sigma=3;

cutoff = ceil(3*sigma);

h=fspecial('gaussian',2*cutoff+1,sigma);
out = conv2(i3,h,'same');

out1 = conv2(gauss,h,'same');

w = wiener2(gauss,[5,5]);

surf(1:2*cutoff+1,1:2*cutoff+1,h)

[row, col]=size(I);

figure,subplot(1,2,1),imshow(I);

title('Original Image');

I1d=I(:);

Totalcount=row*col;

c=1;

sig=0;

%cumulative probability.

for i=0:255

k=I==i;

count(c)=sum(k(:));

prob(c)=count(c)/Totalcount;

sig=sig+prob(c);

cumpro(c)=sig;

c=c+1;

end

sym = [0:255];

%Huffman code Dictionary

dict = huffmandict(sym,prob);

%function which converts Array to vector

vec_size = 1;
for p = 1:row

for q = 1:col

newvec(vec_size) = I(p,q);

vec_size = vec_size+1;

end

end

%Huffman Encoding

hcode = huffmanenco(newvec,dict);

%Huffman Decoding

dhsig1 = huffmandeco(hcode,dict);

%convertion dhsig1 double to dhsig uint8

dhsig = uint8(dhsig1);

%vector to Array conversion

dec_row=sqrt(length(dhsig));

dec_col=dec_row;

%variables using to convert vector 2 Array

A_row = 1;

A_col = 1;

vec_si = 1;

for x = 1:row

for y = 1:col

back(x,y)=dhsig(vec_si);

A_col = A_col+1;

vec_si = vec_si + 1;

end

A_row = A_row+1;

end

%converting image from grayscale to decoded

[deco, map] = gray2ind(back,256);


decoded = ind2rgb(deco,map);

subplot(1,2,2),imshow(decoded);title('Decoded image');

un_compress=numel(de2bi(I1d));

compress=numel(hcode);

r=un_compress/compress;

fprintf('\nCompression ratio\n');

disp(r);

You might also like