Sunday, 19 July 2015

MATLAB PROGRAM RUN LENGTH ENCODING



/*MATLAB PROGRAM RUN LENGTH ENCODING*/

% Run Length Encoder
% EE113D Project
function encoded = RLE_encode(input)
my_size = size(input);
length = my_size(2);
run_length = 1;
encoded = [];
for i=2:length
if input(i) == input(i-1)
run_length = run_length + 1;
else
encoded = [encoded input(i-1) run_length];
run_length = 1;
end
end
if length > 1
    % Add last value and run length to output
encoded = [encoded input(i) run_length];
else
    % Special case if input is of length 1
encoded = [input(1) 1];
end


OUTPUT

>>RLE_encode([1 0 0 0 0 2 2 2 1 1 3])
ans =
     1     1     0     4     2     3     1     2     3     1
>>RLE_encode([0 0 0 0 0 0 0 0 0 0 0])
ans =
     0    11
>>RLE_encode([0 1 2 3 4 5 6 7 8 9])
ans =
    0     1     1     1     2     1     3     1     4     1     5     1     6     1     7     1     8     1     9     1



MATLAB PROGRAM FOR REGION GROWING




/*MATLAB PROGRAM for Region Growing*/

clc
clear all
b=imread('cameraman.tif')
subplot(1,2,1)
imshow(b);
title('Original Image')
a=b;
max=251;
min=7;
t=55;l=2;
[row,col]=size(a);
for k=2:255
for l=2:255
if(k<=row-1&&l<=col-1)
if(abs(a(k,l)-a(k+1,l))<=t)
f(k,l)=0;
end
if(abs(a(k,l)-a(k-1,l))<=t)
f(k,l)=0;
end
if(abs(a(k,l)-a(k,l+1))<=t)
f(k,l)=0;
end
if(abs(a(k,l)-a(k,l-1))<=t)
f(k,l)=0;
end
if(abs(a(k,l)-a(k+1,l))>t)
f(k,l)=200;
end
if(abs(a(k,l)-a(k-1,l))>t)
f(k,l)=200;
end
if(abs(a(k,l)-a(k,l+1))>t)
f(k,l)=200;
end
if(abs(a(k,l)-a(k,l-1))>t)
f(k,l)=200;
end
end
end
end
subplot(1,2,2)    
imshow(f)
title('Segmentd Image using Threshold=55')


OUTPUT