Documente Academic
Documente Profesional
Documente Cultură
AIM:
Original Image
Compressed Image
Symbol Weights:
n
pr ( r k ) = k for k =0,1,2, , L1
MN
Average Length of Code:
L1
Lavg= l ( r k ) pr (r k )
k=0
Entropy H Equation:
L1
H= pr (r k ) log 2 p r (r k )
k=0
clc;
close all;
im=[5 100 200 3; 6 5 4 2; 100 2 3 46; 2 2 5 3];
m1=max(max(im));
s=1:m1;
[m,n]=size(im);
p=zeros(1,m1);
for k=1:m1
for i=1:m
for j=1:n
if (im(i,j)==k)
p(k)=p(k)+1;
end
end
end
p1(k)=p(k)/(m*n);
end
im1=im(:);
dict=huffmandict(s,p1);
hcode=huffmanenco(im1,dict);
dsig=huffmandeco(hcode,dict);
k=1;
for i=1:m
for j=1:n
res(i,j)=dsig(k);
k=k+1;
end
end
res=res';
figure; imagesc(im);title('Original Image');
figure; imagesc(res);title('Decoded Image');
num=m*n*8;
den=length(hcode);
CR=num/den
len=zeros(1,m1);
for i=1:m1
len(i)= length(dict{i,2});
end
lavg=sum(len.*p1);
for i=1:m1
if (p1(i)~=0)
H= sum(p1(i).*log10(p1(i))/0.3010);
end
end
H=-H
E=(H/lavg)*100
Compression
E=
8.6965
[Information]
H=
0.2500
[Entropy]
CR = 2.7826
[Compression Ratio]
Experiment 2
AIM:
B pq= p q
A mn cos
m=0 n=0
p=
(2 m+1) p
(2n+1)q 0 p M 1
cos
,
2M
2N
0 q N1
1 / M , p=0
1/ N , q=0
, =
2 /M , 1 p M 1 q 2/ N , 1 q N1
single image. For typical images, many of the DCT coefficients have values close to zero; these
coefficients can be discarded without seriously affecting the quality of the reconstructed image.
Root Mean Square Error
It is measure of estimator which suggests the accuracy of registration with respect to reference
image. It should be near to zero for best match.
1
2
RMSE=
(x (i , j ) y (i, j))
MN i =1 j=1
Peak Signal to Noise Ratio
It is a ratio of maximum possible power of signal to power of corrupting noise that affects the
fidelity of representation. Its range is wide so it is expressed as logarithmic scale. Maximum value of
PSNR indicates good match between the two images.
n
PSNR=10 log 10
(2 1)
MSE
%no zig-zag
psn=PSNR(im,im_dct);
psnr_Value =
RMSE =
81.5724
0.0214
Experiment 3
AIM:
Long runs are rare in certain types of data. For example, ASCII plaintext seldom contains long
runs. In the previous example, the last run (containing the character t) was only a single character in
length; a 1-character run is still a run. Both a run count and a run value must be written for every 2character run. To encode a run in RLE requires a minimum of two characters worth of information;
therefore, a run of single characters actually takes more space. For the same reasons, data consisting
entirely of 2-character runs remains the same size after RLE encoding.
In our example, encoding the single character at the end as two bytes did not noticeably hurt our
compression ratio because there were so many long character runs in the rest of the data. But observe how
RLE encoding doubles the size of the following 14-character string:
Xtmprsqzntwlfb
After RLE encoding, this string becomes:
1X1t1m1p1r1s1q1z1n1t1w1l1f1b
k=1;
temp=[temp t];
temp1=temp;
temp2=cat(1,temp2,temp1)
end
end
[r1 c1]=size(temp2);
for i=1:r1
for j=1:c1
temp3=[temp3 temp2(i,j)];
end
end
cr=length(x)/length(temp3)
temp2 =
cr =
5
2
0
1
4
2
3
1
2
4
4]
1.3000
Input Data
Output Data
Compression Ratio
5.2112
Experiment 4
Template matching is a technique in digital image processing for finding small parts of an image
which match a template image. It can be used in manufacturing as a part of quality control, a way to
navigate a mobile robot, or as a way to detect edges in images.
Target image: original image bigger one
Template image: which is to be matched smaller one
Correlation based Template matching
Let F= {F1,F2,.. Fn} is the original image and f = {f1,f2.fn} is the template image.
n
SSD= ( F jf j )2
j=1
f i f )
(F i F)(
NCC=
i=1
2
(Fi F)
i=1
i=1
(f i f )2
Let F= {F1,F2,.. Fn} is the original image and f = {f1,f2.fn} is the template image.
The SSD and NCC both estimate the degree of linear dependence between the corresponding pixel
brightness values being compared.
The range of NCC is -1 to +1.
The value closer to 1 indicates the better match.
rectangle('Position',[x,y,c_c_im,r_c_im],'LineWidth',2,'LineStyle','--','EdgeColor','r');
for j=1:c_n-c_t+1
mean_1=0;
for i1=1:r_t
for j1=1:c_t
mean_1=mean_1+(n_image(i+i1-1,j+j1-1));
end
end
mean_vect(i,j)= mean_1/(r_t*c_t);
end
end
%% ------------------------------------------------denominator_left-term--------------------------------------for i=1:r_n-r_t+1
for j=1:c_n-c_t+1
diff_sqr_l=0;
for i1=1:r_t
for j1=1:c_t
diff_sqr_l =diff_sqr_l+(n_image(i+i1-1,j+j1-1)-mean_vect(i,j));
end
end
diff_sqr_sqrt_l(i,j)=sqrt(diff_sqr_l);
end
end
%%--------------------------------------------------template mean-----------------------------------------------temp_mean=0;
for i1=1:r_t
for j1=1:c_t
temp_mean = temp_mean +t_image(i1,j1);
end
end
temp_mean=temp_mean/(r_t*c_t);
%%-----------------------------template-matrix for numerator multiplication-------------------------------for i1=1:r_t
for j1=1:c_t
temp_mat(i1,j1) = t_image(i1,j1)-temp_mean;
end
end
%% -------------------------------------------denominator_right-term------------------------------------------diff_sqr_r=0;
for i=1:r_t
for j=1:c_t
diff_sqr_r =diff_sqr_r+ (t_image(i,j)-temp_mean);
end
end
diff_sqr_sqrt_r = sqrt(diff_sqr_r);
%% -------------------------------------------NCC formula implementation-----------------------------------for i=1:r_n-r_t+1
for j=1:c_n-c_t+1
temp=0;
for i1=1:r_t
for j1=1:c_t
numer_l(i1,j1)=(n_image(i+i1-1,j+j1-1)-mean_vect(i,j));
denom_l(i1,j1)=numer_l(i1,j1)^2;
end
end
temp1=numer_l.*temp_mat;
numer_l_s = sum(sum(temp1));
denom_l_s = sqrt(sum(sum(denom_l)));
denom_r=diff_sqr_sqrt_r;
NCC_s (i,j)=numer_l_s /(denom_l_s + denom_r);
end
end
%%--------------------------- Location finding and making ractangular boundary-------------------------max_val=max(max(NCC_s));
[y,x]=find(NCC_s ==(max_val));
figure;imshow(uint8(n_image));hold on;
rectangle('Position',[x,y,c_t,r_t],'LineWidth',2,'LineStyle','--','EdgeColor','r');
Experiment 5
AIM:
f
i
ISC represents the percentage of the match of each bit each other in the two-bit column.
For the Template image, the binary codes is defined as
biF = 1, if Fi +1 Fi
0, otherwise
The increment sign correlation coefficient (ISC) is defined as follows.
bif = 1, if f i+1 f i
0, otherwise
isc_temp=0;isc=[];figure_isc=zeros(r_n,c_n);
for i=1:r_n-1
for j=1:c_n-1
if(n_image(i,j)>n_image(i,j+1))
figure_isc(i,j)=1;
else
figure_isc(i,j)=0;
end
end
end
%%
-------------------------------------------ISC-formula-------------------------------------------------for i=1:r_n-r_t+1
for j=1:c_n-c_t+1
isc_temp=0;
for i1=1:r_t
for j1=1:c_t
isc_temp = isc_temp+((template_isc(i1,j1)*figure_isc(i1+i-1,j1+j-1))+((1-figure_isc(i1+i1,j1+j-1))*(1-template_isc(i1,j1))));
end
end
isc(i,j)=isc_temp/(r_t*c_t);
end
end
%% ------------------------------Location finding and making ractangular boundary----------------------max_val=max(max(isc));
[y,x]=find(isc ==(max_val));
figure;imshow(uint8(n_image));hold on;
rectangle('Position',[x,y,c_t,r_t],'LineWidth',2,'LineStyle','--','EdgeColor','r');
Figure 18 Template
Image
Figure 16 Original Input Image
Experiment 6
AIM:
Short Description:
Following are the steps which is being implemented in this practical.
intermediate Images:
numTeeth = 40
Experiment 7
Region Filling
Bounding Box
break
else
fl=im_texto;%Only one line.
re=[ ];
end
end
function img_out=clip(img_in)
[f c]=find(img_in);
img_out=img_in(min(f):max(f),min(c):max(c));%Crops image
function letter=read_letter(imagn,num_letras)
global templates
comp=[ ];
for n=1:num_letras
sem=corr2(templates{1,n},imagn);
comp=[comp sem];
end
vd=find(comp==max(comp));
%*-*-*-*-*-*-*-*-*-*-*-*-*if vd==1
letter='A';
elseif vd==2
letter='B';
elseif vd==3
letter='C';
elseif vd==4
letter='D';
elseif vd==5
letter='E';
elseif vd==6
letter='F';
elseif vd==7
letter='G';
elseif vd==8
letter='H';
elseif vd==9
letter='I';
elseif vd==10
letter='J';
elseif vd==11
letter='K';
elseif vd==12
letter='L';
elseif vd==13
letter='M';
elseif vd==14
letter='N';
elseif vd==15
letter='O';
elseif vd==16
letter='P';
elseif vd==17
letter='Q';
elseif vd==18
letter='R';
elseif vd==19
letter='S';
elseif vd==20
letter='T';
elseif vd==21
letter='U';
elseif vd==22
letter='V';
elseif vd==23
letter='W';
elseif vd==24
letter='X';
elseif vd==25
letter='Y';
elseif vd==26
letter='Z';
%*-*-*-*-*
elseif vd==27
letter='1';
elseif vd==28
letter='2';
elseif vd==29
letter='3';
elseif vd==30
letter='4';
elseif vd==31
letter='5';
elseif vd==32
letter='6';
elseif vd==33
letter='7';
elseif vd==34
letter='8';
elseif vd==35
letter='9';
else
letter='0';
end
Experiment 8
AIM:
Diameter: 76.43
Radius: 38.22
Area: 4587
erimentExperiment 9
AIM:
figure,imshow(Im_2);
Im_2_part=Im_2(1:50,1:50);
for q=n-50:-1:n/2
SAD=0;
for i=1:50
for j=1:50
SAD=SAD+abs(double(Im_1(i,q+j))-double(Im_2_part(i,j)));
end
end
SAD2(q)=SAD;
end
e=min(SAD2(n/2:n-50));
q=1:n-50;
figure,stem(q,SAD2);
z=find(SAD2==e);
for i=1:m
for j=1:z
timg(i,j)=(In_Im_1(i,j));
end
end
for i=1:m
for j=1:n
timg(i,z+j)=(In_Im_2(i,j));
end
end
figure,imshow(uint8(timg));
Image:
x 10
10
0
0
50
100
150
200
250
300
Experiment 10
AIM: Write a MATLAB program to detect touching objects and determine its
feature vector from an input image.