Thursday, 21 April 2016

Single Channel Queuing System

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n, tba[10],st[10],at[10],tsb[10],tcw[10],tse[10],tcss[10];
    clrscr();
    printf("enter no. of customers:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("\n customer %d",i+1);
        printf("\nTime between arrivals:");
        scanf("%d",&tba[i]);
        printf("Service time:");
        scanf("%d",&st[i]);
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            at[0]=0;
            tsb[0]=0;
            tse[0]=tsb[0]+st[0];
            tcw[0]=0;
            tcss[0]=tse[0]-at[0];
        }
        else
        {
            at[i]=at[i-1]+tba[i];
            if(at[i]<=tse[i-1])
                tsb[i]=tse[i-1];
            else
                tsb[i]=at[i];
            tse[i]=tsb[i]+st[i];
            tcw[i]=tsb[i]-at[i];
            tcss[i]=st[i]+tcw[i];
        }
    }
    printf("Cus\t Tba\t St\t At\t Tsb\t Tcw\t Tse\t Tcss\n");
    printf("---------------------------------------------------------------------\n");
    for(i=0;i<n;i++)
    {
        printf("%d\t  %d\t  %d\t  %d\t %d\t  %d\t %d\t  %d\n",i+1,tba[i],st[i],at[i],tsb[i],tcw[i],tse[i],tcss[i]);
    }
    getch();
}

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