Sei sulla pagina 1di 36

%-- 17-02-2016 00:56 --%

%-- 17-02-2016 22:46 --%


a=[2 3 4;4 5 6;5 6 7]
a.^2
1./a
inv(a)
aa
a
log10(a)
loga(10)
log(10)
a'
flipud(a)
fliplr(a)
rot90(a)
a
a(4)
reshape(a,1,9)
reshape(9,1)
reshape(a,9,1)
a(:,:,1)=[1 2 3;4 5 6;7 8 9]
a(:,:,2)=zeros(3,3)
a(:,:,3)=ones(3,3)
plot(a,tan(a))
a
imread('WIN_20160213_21_06_01_Pro.jpg')
a=imread('WIN_20160213_21_06_01_Pro.jpg')
imshow(a)
subplot(331);imshow(a)
subplot(332);imshow('WIN_20160213_21_06_13_Pro.jpg')
iminfo('WIN_20160213_21_06_01_Pro.jpg')
imfinfo('WIN_20160213_21_06_01_Pro.jpg')
size(a)
colormap(jet)
colormap(spring)
impixelinfo
a=uint8(zeros(256,256));
imshow(a)
subplot(333);imshow(uint8(255*ones(256,256)))
imshow(a)
impixel(1 256 256)
impixel(1,250,200)
impixelinfo
impixel(a,250,250)
impixel('WIN_20160213_21_06_01_Pro.jpg',250,250)
b=imread('WIN_20160213_21_06_01_Pro.jpg')
impixel(b,250,250)
iminfo(b)
imfinfo(b)
imfinfo('WIN_20160213_21_06_01_Pro.jpg')
x=rgb2gray(b)
figure,imshow(x)
[y,map]=rgb2ind(b)
colormap(jet)
figure,imshow(x)
colormap(spring)
figure,imshow(x)
[RGB,m,dith] = parse_inputs(varargin{:});
[y,ymap
[y,ymap]=rgb2ind(b)

[y,ymap]=rgb2ind(b,65536)
figure,imshow(y)
[y,ymap]=rgb2ind(b,6)
figure,imshow(y,ymap)
[y,ymap]=rgb2ind(b,65536)
figure,imshow(y,ymap)
z=ind2rgb(y,ymap)
figure,imshow(z)
z=ind2gray(y,ymap)
figure,imshow(z)
gh=double(b)
imshow(gh)
imshow(gh/255)
imshow(z)
ab=im2double(z)
figure,imshow(ab)
abc=z>0.5
abc=z>120
abc=z>1000
abc=z<0.5
z
abc=z>40000
figure,imshow(abc)
xy=mod(z,2)
figure,imshow(xy)
ayz=mod(floor(z/2),2)
figure,imshow(ayz)
ayz=mod(floor(z/40000),2)
figure,imshow(ayz)
close all
clc
ayz=mod(floor(z/4000000),2)
figure,imshow(ayz)
ayz=mod(floor(z/400000),2)
ayz=mod(floor(z/400),2)
figure,imshow(ayz)
q=double(ayz)
figure,imshow(ayz)
figure,imshow(b)
figure,imshow(z)
z=imresize(z/2);imshow(z)
z=imresize(z/2),imshow(z)
z=imresize(z/2)
xyz=imresize(z/2)
z=imresize(z,1/2);
figure,imshow(z)
z=imresize(z,1/20);
figure,imshow(z)
figure,imagesc(z)
a=double(z)
xy=mod(a,2)
figure,imshow(xy)
xy=imresize(xy,10);
figure,imshow(xy)
xy2=mod(floor(a/2),2)
figure,imshow(xy2)
figure,imshow(z)
a=imresize(a,10);
figure,imshow(a)
a=double(z)

xy2=mod(floor(a/128),2)
figure,imshow(xy2)
xy2=imresize(xy2,10);imshow(xy2)
clise all
close all
figure,imshow(xy2)
a=double(z/255)
figure,imshow(a)
imshow(z/255);
z=double(z)
a=double(z/255)
figure,imshow(a)
cd=im2double(z)
%-- 22-02-2016 10:17 --%
%-- 22-02-2016 11:30 --%
x=videoinput('winvideo')
preview(x)
snapshot
snapshot(x)
snapshot(x,[512,512])
subplot(1,2,1)
;preview(x)
b=imread('WIN_20160213_21_06_01_Pro.jpg')
imtool(b):
imshow(b)
imcrop(b,0,0,256,256)
imcrop(b,[0,0,256,256])
imresize(b,0.5)
imshow(b)
figure, imshow(b)
figure,imshow(c=imresize(b,0.5))
c=imresize(b,0.5
c=imresize(b,0.5)
imshow(c)
figure,imshow(c)
imresize(b,[200,200])
imshow(imresize(b,[200,200]))
imshow(b,[200,NaN])
d=im2bw(c);imshow(d)
imshow(b,[200,NaN])
imshow(b,[NaN],500)
imshow(b,[NaN,500])
imresize(b,[0.5,'nearest'])
imresize(d,[0.5,'nearest'])
imtool(d)
imresize(d,0.5,'nearest')
e=imresize(d,0.5,'nearest');imshow(e)
figure,imshow(d)
e=imresize(d,0.5,'bilinear');imshow(e)
convert
t=convert(b);
imtool(t)
bwlabel(t)
%-- 23-02-2016 12:02 --%
B=bwboundaries(t)
b=imread('WIN_20160213_21_06_01_Pro.jpg');d=im2bw(b);B=bwboundaries(t)
b=imread('WIN_20160213_21_06_01_Pro.jpg');d=im2bw(b);B=bwboundaries(d)
imshow(B)
%-- 23-02-2016 19:34 --%
x=videoinput('winvideo');preview(x)

rand(4,5)
format long
rand(3,3)
eye(3)
a=rand(10,1)
b=sort(a)
vid = videoinput('winvideo', 1, 'MJPG_1280x720');
vid.ReturnedColorspace = 'rgb';
% clears any data logged by vid prior to this.
flushdata(vid);
% start preview
preview(vid);
%% iterate over the frames
frames = 100 ;
for i = 1:frames
%
how to get a frame from the video
videoframe = getsnapshot(vid) ;
%
output the frame to the video
vid_out( : , : , : , i ) = videoframe ;
end
stoppreview(vid)
pause(5) ;
implay(vid_out) ;
frames = 100 ;
% read video and make video file reader
% this will read videos stored in our computer , recordings from movies or
% a movie itself.
videoFReader = vision.VideoFileReader('steve jobs.avi');
% make a video file player
videoPlayer = vision.VideoPlayer;
%% iterate over the frames
while ~isDone(videoFReader)
%
how to get a frame from the video
videoframe = step(videoFReader);
%any image processing operation can be done on this frame/image(videoframe)
%
pause
pause(.01)
%
output the frame to the video
step(videoPlayer,videoframe);
end vid = videoinput('winvideo', 1, 'MJPG_1280x720');
vid.ReturnedColorspace = 'rgb';
% clears any data logged by vid prior to this.
flushdata(vid);
% start preview
preview(vid);
%% iterate over the frames
frames = 100 ;
for i = 1:frames
%
how to get a frame from the video
videoframe = getsnapshot(vid) ;
%
output the frame to the video
vid_out( : , : , : , i ) = videoframe ;
end
stoppreview(vid)
pause(5) ;
implay(vid_out) ;
vid = videoinput('winvideo', 1, 'MJPG_1280x720');
vid.ReturnedColorspace = 'rgb';
% clears any data logged by vid prior to this.
flushdata(vid);

% start preview
preview(vid);
%% iterate over the frames
frames = 100 ;
for i = 1:frames
%
how to get a frame from the video
videoframe = getsnapshot(vid) ;
%
output the frame to the video
vid_out( : , : , : , i ) = videoframe ;
end
stoppreview(vid)
pause(5) ;
implay(vid_out) ;
vid_out( : , : , : , i )
vid_out( : , : , : , 2 )
z=vid_out( : , : , : , 2 );imshow(z)
imc = imcrop(im); % this will open an interactive crop window
mean_rmin = mean(min(imc(:,:,1))); % mean of minimums of red component
mean_rmax = mean(max(imc(:,:,1)));
mean_gmin = mean(min(imc(:,:,2)));
mean_gmax = mean(max(imc(:,:,2)));
mean_bmin = mean(min(imc(:,:,3)));
mean_bmax = mean(max(imc(:,:,3)));
var_r = 5;
var_g = 5;
var_b = 5;
% now applying the threshold( note this method is much faster than for loop
% method
im = ( im(:,:,1) > mean_rmin-var_r & im(:,:,1) < mean_rmax+var_r & im(:,:,2) > m
ean_gmin-var_g & im(:,:,2) < mean_gmax+var_g & im(:,:,3) > mean_bmin-var_b & im(
:,:,3) < mean_bmax+var_b );
imshow(im);
%% Section2 Removing noise 1
se = strel('disk',3); % define srtucturing element for use in imerode, imdilate
etc.
im2 = imerode(im, se);
imtool(im2);
se = strel('disk',4);
im3 = imdilate(im2, se);
imtool(im3);
% also explore imopen and imclose
%% Section3 Removing noise 2
p = 1600;
im5 = bwareaopen(im, p); % removes part with pixels less than p
imtool(im5);
im6 = imfill(im5, 'holes');% fills holes
imtool(im6);
%% Section4 Using Region Properties
lb = bwlabel(im6); % label matrix
imtool(lb);
s = regionprops(lb, 'Centroid', 'Area'); % see help for more properties
area1 = s(1).Area;
area2 = s(2).Area;
centroid1 = s(1).Centroid;
centroid2 = s(2).Centroid;
% how will you find the shape of the region ?
im=z;imc = imcrop(im); % this will open an interactive crop window
mean_rmin = mean(min(imc(:,:,1))); % mean of minimums of red component
mean_rmax = mean(max(imc(:,:,1)));
mean_gmin = mean(min(imc(:,:,2)));

mean_gmax = mean(max(imc(:,:,2)));
mean_bmin = mean(min(imc(:,:,3)));
mean_bmax = mean(max(imc(:,:,3)));
var_r = 5;
var_g = 5;
var_b = 5;
% now applying the threshold( note this method is much faster than for loop
% method
im = ( im(:,:,1) > mean_rmin-var_r & im(:,:,1) < mean_rmax+var_r & im(:,:,2) > m
ean_gmin-var_g & im(:,:,2) < mean_gmax+var_g & im(:,:,3) > mean_bmin-var_b & im(
:,:,3) < mean_bmax+var_b );
imshow(im);
%% Section2 Removing noise 1
se = strel('disk',3); % define srtucturing element for use in imerode, imdilate
etc.
im2 = imerode(im, se);
imtool(im2);
se = strel('disk',4);
im3 = imdilate(im2, se);
imtool(im3);
% also explore imopen and imclose
%% Section3 Removing noise 2
p = 1600;
im5 = bwareaopen(im, p); % removes part with pixels less than p
imtool(im5);
im6 = imfill(im5, 'holes');% fills holes
imtool(im6);
%% Section4 Using Region Properties
lb = bwlabel(im6); % label matrix
imtool(lb);
s = regionprops(lb, 'Centroid', 'Area'); % see help for more properties
area1 = s(1).Area;
area2 = s(2).Area;
centroid1 = s(1).Centroid;
centroid2 = s(2).Centroid;
% how will you find the shape of the region ?
area1
area
%-- 24-02-2016 15:42 --%
vid=videoinput('winvideo',1,'YUY_320X240');
set=(vid,'FramesPerTrigger',inf);
set(vid,'Returned Colorspace','rgb');
vid.FrameGrabInterval=5;
start(vid);
while(vid.FramesAcquired<=100)
data=getssnapshot(vid);
diff_im=imsubtract(data(::,l),rgb@gray(data)):
diff_im=medfilt(diff_im[3,3]);
diff_im=im2bw(diff_im,0.18);
diff_im=bwareaopen(diff_im,300);
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid');
imshow(data);
hold on
for object=1:length(stats)
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position','bb',Edgecolor','r','Linewidth',2)
plot(bc(1),bc(2),'-m+')
end

hold off
end
stop(vid);
FLUSHDATA(vid);
imaqinfo(1);
imaqhw();
imaqhwinfo();
vid=videoinput('winvideo');
set=(vid,'FramesPerTrigger',inf);
set(vid,'Returned Colorspace','rgb');
vid.FrameGrabInterval=5;
start(vid);
while(vid.FramesAcquired<=100)
data=getssnapshot(vid);
diff_im=imsubtract(data(::,l),rgb@gray(data)):
diff_im=medfilt(diff_im[3,3]);
diff_im=im2bw(diff_im,0.18);
diff_im=bwareaopen(diff_im,300);
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid');
imshow(data);
hold on
for object=1:length(stats)
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position','bb',Edgecolor','r','Linewidth',2)
plot(bc(1),bc(2),'-m+')
end
hold off
end
stop(vid);
FLUSHDATA(vid);
clc
cleat all
clear all
clc
close all;
clear all;
location1=[];
location2=[];
%vid_obj=videoinput('winvideo',1,'YUY2_640x480');
vid_obj=videoinput('winvideo',2,'RGB24_352x288');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('target_image.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);

location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
function centres=findcentre(snap1)
min_area=1100;
location1=[];
location2=[];
rr=snap1(:,:,1);
gg=snap1(:,:,2);

bb=snap1(:,:,3);
redz=((rr>=80) & (rr<=255) & (gg>=0) & (gg<=50) & (bb>=0) & (bb<=50));
% figure,imshow(redz);
%title('before filter');
%redz=medfilt2(redz);
%figure,imshow(redz);
%title('after filter');
%
redz = bwareaopen(redz,10); %% 10 se kam pixels ko hatao
%
figure,imshow(redz);
%
title('area open');
se=strel('disk',5);
redz=imclose(redz,se);
%figure,imshow(redz);
redz=imfill(redz,'holes'); %closed component ke ander vali noise ka removal
%figure,imshow(redz);
L1 = bwlabel(redz);%connected componenets label
a1 = regionprops(L1, 'Area');
area=[a1.Area]
f1=find(area>min_area);
im1=ismember(L1,f1);% agar l1 ,f1 ka member hai
L1=im1.*L1;
c1= regionprops(L1, 'Centroid');
g1=[c1.Centroid];
g1(isnan(g1))=[]; %remove nan error
counter=1;
for i=1:length(g1)
if mod(i,2)~=0
location1(counter,2)=g1(i);
else
location1(counter,1)=g1(i);
counter=counter+1;
end
end
bluez=((rr>=0) & (rr<=55) & (gg>=0) & (gg<=55) & (bb>=65) & (bb<=200));
%figure,imshow(bluez);
%title('before filter');
bluez=medfilt2(bluez);
%figure,imshow(bluez);
title('after filter');
%
redz = bwareaopen(redz,10); %% 10 se kam pixels ko hatao
%
figure,imshow(redz);
%
title('area open');
se=strel('disk',5);
bluez=imclose(bluez,se);
%figure,imshow(bluez);
title('image closing');
bluez=imfill(bluez,'holes'); %connected component ke ander vali noise ka removal
%figure,imshow(bluez);
title('image after filling holes ')
L1 = bwlabel(bluez);
a1 = regionprops(L1, 'Area');
area=[a1.Area]
f1=find(area>min_area);
im1=ismember(L1,f1);%% returns 1 jaha pe area required limit mein hai
L1=im1.*L1;
c1= regionprops(L1, 'Centroid');
g1=[c1.Centroid];
g1(isnan(g1))=[]; %remove nan eroor
counter=1;
for i=1:length(g1)

if mod(i,2)~=0
location2(counter,2)=g1(i);
else
location2(counter,1)=g1(i);
counter=counter+1;
end
end
location1
location2
centres=vertcat(location1,location2);
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('target_image.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))

'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
clc
close all;
clear all;
location1=[];
location2=[];
%vid_obj=videoinput('winvideo',1,'YUY2_640x480');
vid_obj=videoinput('winvideo',2,'RGB24_352x288');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('WIN_20160213_21_906_01_Pro.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else

diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');

base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);

end
end
break;
end
delete(vid_obj);
%-- 24-02-2016 16:08 --%
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);

temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)

snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
%-- 24-02-2016 16:11 --%
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)

[xxx yyy k]=size(snap1);


figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end

delete(vid_obj);
%-- 24-02-2016 16:12 --%
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure

imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))

location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
%-- 24-02-2016 16:14 --%
clc
close all;
clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findCentre(snap1);

[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findCentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;
if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
%-- 24-02-2016 16:19 --%
clc
close all;

clear all;
location1=[];
location2=[];
vid_obj=videoinput('winvideo',1,'YUY2_640x480');
set(vid_obj,'FramesPerTrigger',25);
triggerconfig(vid_obj, 'manual');
start(vid_obj);
set(vid_obj,'returnedcolorspace','rgb');
flag=1;
'get ready for hand gestures'
temp=imread('chandan.jpg');
base_image(:,:,:,flag)=imresize(temp,[288 352]);
while(1)
snap1=getsnapshot(vid_obj);
figure,imshow(snap1)
[xxx yyy k]=size(snap1);
figure,imshow(base_image(:,:,:,flag));
title('base image');
centres=findcentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2);
location2=centres(3:4,1:2);
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2)
pre1=location1(2,2)-location1(1,2);
pre2=location2(2,2)-location2(1,2);
else
diff=100000;
end
if(diff<0.3)
'resizing mode'
while(diff<0.3)
snap1=getsnapshot(vid_obj);
centres=findcentre(snap1);
[r1 c1]=size(centres);
if((r1==4)&(c1==2))
location1=centres(1:2,1:2)
location2=centres(3:4,1:2)
slope1=(location1(1,1)-location1(2,1))/(location1(1,2)-location1(2,2));
slope2=(location2(1,1)-location2(2,1))/(location2(1,2)-location2(2,2));
diff=abs(slope1-slope2);
distance1=location1(2,2)-location1(1,2);
distance2=location2(2,2)-location2(1,2);
change1=distance1-pre1
change2=distance2-pre2
if((change1>5)&(change2>5))
'enlarge operation'
mid_pointx=(location1(1,2)+location1(2,2))/2;
mid_pointy=(location1(1,1)+location2(1,1))/2;
temp=imcrop(base_image(:,:,:,flag),[mid_pointx-50,mid_pointy-50,200,200]);
temp=imresize(temp,[xxx,yyy]);
flag=flag+1;
base_image(:,:,:,flag)=temp;
%figure
imshow(base_image(:,:,:,flag));
elseif((change2<-5)&(change1<-5))
'decrease operation'
flag=flag-1;

if(flag<1)
flag=1;
end
imshow(base_image(:,:,:,flag));
end
pre1=distance1;
pre2=distance2;
else
diff=100000;
end
pause(0.2);
end
end
break;
end
delete(vid_obj);
%-- 24-02-2016 16:26 --%
%start
%clear and filter any warnings and error
clear
[status, message, messageid] = rmdir('training_data','s');
%image size in pixel wxh pixels
image_size_w = 30;
image_size_h = 40;
%directory of training images
directory = 'D:\MATLAB CODES';
%directory = 'training_signals';
folder = dir(directory);
%directory of training images that converted to data
data_output = 'training_data';
mkdir(data_output);
for mao=1:size(folder),
%read content of directory folder and check for sub folder
temp_name = fullfile(directory, folder(mao).name);
chck = isdir(temp_name);
if ((chck == 1) && (mao > 2))
%get all list of jpg file type
images = dir(fullfile(temp_name, '*.jpg'));
%for mao1=1:10,
for mao1=1:size(images),
%get filename of each images, read and convert to double
temp_name1 = fullfile(temp_name, images(mao1).name);
x = imread(temp_name1);
%start to track hand
warning off stats:kmeans:EmptyCluster;
rawImage = x;
I = rawImage;
cform = makecform('srgb2lab');
J = applycform(I,cform);
ab = double(J(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 2;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',2);
pixel_labels = reshape(cluster_idx,nrows,ncols);
segmented_images = cell(1,2);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors

color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
mean_cluster_value = mean(cluster_center,2);
[tmp, idx] = sort(mean_cluster_value);
hand_cluster_num = idx(2);
K = segmented_images{hand_cluster_num};
L = im2bw(segmented_images{hand_cluster_num},0.000);
s = regionprops(rgb_label, I, {'Centroid','BoundingBox'});
% s(hand_cluster_num).Centroid
% s(hand_cluster_num).BoundingBox
centroid_x = uint16(s(hand_cluster_num).Centroid(1));
centroid_y = uint16(s(hand_cluster_num).Centroid(2));
cropped_x = uint16(s(hand_cluster_num).BoundingBox(1))+1;
cropped_y = uint16(s(hand_cluster_num).BoundingBox(2))+1;
cropped_w = uint16(s(hand_cluster_num).BoundingBox(4))-2;
cropped_h = uint16(s(hand_cluster_num).BoundingBox(5))-2;
% apply gaussian blur to remove noise
PSF = fspecial('gaussian',7,10);
L = imfilter(L,PSF,'symmetric','conv');
% cropped region of interest from main image
M = L( cropped_y : (cropped_y+cropped_h), cropped_x: (cropped_x+cropped_w) );
% trim leading and leading zeroes
M(:, logical(sum(abs(M)) == 0)) = [];
cropped_h = size(M,1);
cropped_w = size(M,2);
non_zeroes = find(sum(abs(L))~=0);
cropped_x = non_zeroes(1);
% fill holes to remove flares
M = imfill(M, 'holes');
y = M;
z = imresize(y, [40 30]);
z = z(:);
filename = strcat(data_output,'\',images(mao1).name,'.mat');
save(filename, 'z');
imshow(L);
hold on;
plot(centroid_x, centroid_y, 'bo');
rectangle('Position', [ cropped_x cropped_y cropped_w cropped_h ], 'EdgeColor','
y');
hold off;
end
end
end
folder_data_output = dir(data_output);
final_training_data_input = 0;
for mao=1:size(folder_data_output),
%read content of folder_data_output folder
temp_name = fullfile(data_output, folder_data_output(mao).name);
%cat all 1D and form an input for training
if (mao == 3)
load(temp_name,'z');
final_training_data_input = z;
elseif (mao > 3)
load(temp_name,'z');
final_training_data_input = cat(2, final_training_data_input, z);
end
end
%save final_training_data_input for training

save('training_data_input.mat', 'final_training_data_input');
%clear and load final_training_data_input
clear
load('training_data_input.mat', 'final_training_data_input');
%-- 24-02-2016 16:38 --%
%-- 26-02-2016 21:13 --%
[status, message, messageid] = rmdir('training_data','s');
%image size in pixel wxh pixels
image_size_w = 30;
image_size_h = 40;
%directory of training images
directory = 'D:\MATLAB CODES';
%directory = 'training_signals';
folder = dir(directory);
%directory of training images that converted to data
data_output = 'training_data';
mkdir(data_output);
for mao=1:size(folder),
%read content of directory folder and check for sub folder
temp_name = fullfile(directory, folder(mao).name);
chck = isdir(temp_name);
if ((chck == 1) && (mao > 2))
%get all list of jpg file type
images = dir(fullfile(temp_name, '*.jpg'));
%for mao1=1:10,
for mao1=1:size(images),
%get filename of each images, read and convert to double
temp_name1 = fullfile(temp_name, images(mao1).name);
x = imread(temp_name1);
%start to track hand
warning off stats:kmeans:EmptyCluster;
rawImage = x;
I = rawImage;
cform = makecform('srgb2lab');
J = applycform(I,cform);
ab = double(J(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 2;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',2);
pixel_labels = reshape(cluster_idx,nrows,ncols);
segmented_images = cell(1,2);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
mean_cluster_value = mean(cluster_center,2);
[tmp, idx] = sort(mean_cluster_value);
hand_cluster_num = idx(2);
K = segmented_images{hand_cluster_num};
L = im2bw(segmented_images{hand_cluster_num},0.000);
s = regionprops(rgb_label, I, {'Centroid','BoundingBox'});
% s(hand_cluster_num).Centroid
% s(hand_cluster_num).BoundingBox
centroid_x = uint16(s(hand_cluster_num).Centroid(1));
centroid_y = uint16(s(hand_cluster_num).Centroid(2));

cropped_x = uint16(s(hand_cluster_num).BoundingBox(1))+1;
cropped_y = uint16(s(hand_cluster_num).BoundingBox(2))+1;
cropped_w = uint16(s(hand_cluster_num).BoundingBox(4))-2;
cropped_h = uint16(s(hand_cluster_num).BoundingBox(5))-2;
% apply gaussian blur to remove noise
PSF = fspecial('gaussian',7,10);
L = imfilter(L,PSF,'symmetric','conv');
% cropped region of interest from main image
M = L( cropped_y : (cropped_y+cropped_h), cropped_x: (cropped_x+cropped_w) );
% trim leading and leading zeroes
M(:, logical(sum(abs(M)) == 0)) = [];
cropped_h = size(M,1);
cropped_w = size(M,2);
non_zeroes = find(sum(abs(L))~=0);
cropped_x = non_zeroes(1);
% fill holes to remove flares
M = imfill(M, 'holes');
y = M;
z = imresize(y, [40 30]);
z = z(:);
filename = strcat(data_output,'\',images(mao1).name,'.mat');
save(filename, 'z');
imshow(L);
hold on;
plot(centroid_x, centroid_y, 'bo');
rectangle('Position', [ cropped_x cropped_y cropped_w cropped_h ], 'EdgeColor','
y');
hold off;
end
end
end
folder_data_output = dir(data_output);
final_training_data_input = 0;
for mao=1:size(folder_data_output),
%read content of folder_data_output folder
temp_name = fullfile(data_output, folder_data_output(mao).name);
%cat all 1D and form an input for training
if (mao == 3)
load(temp_name,'z');
final_training_data_input = z;
elseif (mao > 3)
load(temp_name,'z');
final_training_data_input = cat(2, final_training_data_input, z);
end
end
%save final_training_data_input for training
save('training_data_input.mat', 'final_training_data_input');
%clear and load final_training_data_input
clear
load('training_data_input.mat', 'final_training_data_input');
%-- 09-03-2016 12:28 --%
%-- 09-03-2016 14:07 --%
%-- 09-03-2016 19:02 --%
%-- 10-03-2016 15:21 --%
%-- 10-03-2016 18:53 --%
a=imread('WIN_20160213_21_06_01_Pro.jpg')
%-- 11-03-2016 10:17 --%
Y = sqrt(1 - Z. 2).*sin(theta);
surf(X, Y, Z); axis square
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);

Z = X. 2 - Y. 2;
mesh(X, Y, Z)
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);
Z = X.^2 - Y.^2;
mesh(X, Y, Z)
%-- 21-03-2016 22:08 --%
[X,Y] = meshgrid(-2:.1:2, -2:.1:2);
Z = X.^2 - Y.^2;
mesh(X, Y, Z)
%-- 22-03-2016 20:27 --%
%-- 23-03-2016 14:37 --%
a=imread('dataset (3).jpg');imshow(a)
x=a[N,:]
x=a(N,:)
N=100000
x=a(N,:)
N=500
x=a(N,:)
W=rand(10,784)
Y=rand(1,N)
S=W*x
S=W.*x
S=Wx
x
x=a(N,:)
size(a)
a=imread('dataset (3).jpg');imshow(a)
N=500
x=a(N,:)
x
W=rand(10,784)
Y=rand(1,N)
S=W*x
x
w
WW
W
size(x)
size(a)
x
size(a)
a=double(a/255)
imshow(a)
size(a)
a'=a(:,:,1);imshow(a')
a(:,:,1)
imshow(a(:,:,1))
b=(a(:,:,1))
size(b)
n=480
w=rand(10,606)
Y=rand(1,480)
s=w*b
y=exp(s)
size(y)
Y=rand(480,1)
y=(y*Y)/sum(y,axis=0)
z=(y*Y)/sum(y,axis=0)
z=y*Y
%-- 24-03-2016 08:49 --%

b
a=imread('dataset (3).jpg');imshow(a)
b=a(:,:,1);imshow(b)
a=double(a/255)
imshow(a)
b=a(:,:,1);imshow(b)
size(b)
w=rand(10,480);
load('matlab.mat')
%-- 24-03-2016 09:45 --%
load('matlab.mat')
b
imshow(b)
%-- 24-03-2016 13:14 --%
load('matlab.mat')
imshow(b)
s=w*b
s=b*w
size(b)
size(w)
w=rand(480,10)
s=b*w
imshow(s)
size(s)
y=exp(s)
size(Y)
size(y)
z=rand(1,480)
sum(y)
y_prod=z*y/sum(y)
z*y
y*z
size(y)
z=rand(1,606)
y_prod=z*y/sum(y)
loss=-log(y_prod)
z*y
size(z*y)
x2=z*y;x3=sum(y)
x2=z*y
size(x3)
x3=sum(y)
size(y)
x3=sum(sum(y))
y_prod=x2/x3
loss=-log(y_prod)
x4=sum(loss)+k*sum(w*w)
k=20; x4=sum(loss)+k*sum(w*w)
size(w*w)
size(w)
w1=rand(1,480)
k=20; x4=sum(loss)+k*sum(w1*w)
k=0.0001; x4=sum(loss)+k*sum(w1*w)
k=.00000000000001; x4=sum(loss)+k*sum(w1*w)
sum(loss)
*sum(w1*w)
sum(w1*w)
k=-0.1; x4=sum(loss)+k*sum(w1*w)
k=.09; x4=sum(loss)+k*sum(w1*w)
k=-0.09; x4=sum(loss)+k*sum(w1*w)

k=-0.099999999; x4=sum(loss)+k*sum(w1*w)
k=-0.09999; x4=sum(loss)+k*sum(w1*w)
k=-0.0999; x4=sum(loss)+k*sum(w1*w)
k=-0.099; x4=sum(loss)+k*sum(w1*w)
k=-0.0995; x4=sum(loss)+k*sum(w1*w)
k=-0.0991; x4=sum(loss)+k*sum(w1*w)
k=-0.0989; x4=sum(loss)+k*sum(w1*w)
k=-0.0985; x4=sum(loss)+k*sum(w1*w)
k=-0.0984; x4=sum(loss)+k*sum(w1*w)
%-- 24-03-2016 16:38 --%
%-- 24-03-2016 19:31 --%
%-- 24-03-2016 21:58 --%
%-- 25-03-2016 09:36 --%
load('matlab.mat')
imshow(a)
b=a(:,:,1);imshow(b)
size(b)
w=rand(10,606);y=rand(480,1);
for 1:100
for 1:100,
for 1:100, s=w*b
for 1:100, s=w*b;y=
for 1:100, s=w*b;y_prod=exp(s);y_prod=y_prod*y/(sum(sum(y_prod)));loss=-log(y_pr
od);loss=sum(loss);loss=loss
%-- 29-03-2016 16:50 --%
%-- 30-03-2016 18:57 --%
%-- 30-03-2016 21:51 --%
%-- 01-04-2016 20:50 --%
load('matlab.mat');
show('matlab.mat');
imshow(a)
%-- 01-04-2016 22:09 --%
%-- 02-04-2016 11:35 --%
%-- 02-04-2016 17:52 --%
%-- 02-04-2016 23:54 --%
%-- 03-04-2016 13:55 --%
im=imread('WIN_20160213_21_06_22_Pro (2).jpg');imshow(im)
%-- 03-04-2016 20:08 --%
%-- 03-04-2016 23:17 --%
%-- 04-04-2016 12:32 --%
%-- 06-04-2016 18:42 --%
%-- 08-04-2016 23:36 --%
%-- 09-04-2016 07:10 --%
%-- 09-04-2016 11:04 --%
%-- 09-04-2016 15:12 --%
%-- 13-04-2016 12:30 --%
%-- 15-04-2016 09:06 --%
%-- 07-05-2016 11:58 --%
%-- 03-04-2016 20:08 --%
%-- 09-05-2016 22:40 --%
%-- 14-05-2016 00:31 --%
factor(123)
factor(123456789)
factor(16)
syms x y
(x - y)*(x - y) 2
(x - y)*(x - y)^2
expand(ans)
factor(ans)
simplify((x^3-y^3)/(x-y))

simple(sin(x)*cos(y)+cos(x)*sin(y))
cos(pi/2)
cos(sym('pi/2))
cos(sym('pi/2'))
(1/2)+(1/3)
sym(ans)
vpa('sqrt(2)'., 50)
vpa('sqrt(2)', 50)
vpa('3^45')
3^45
vpa(3^45)
whos
solve('x^2 \\]77- 2*x - 4 = 0 )
solve('x^2-2*x-4=0 )
solve('x^2-2*x-4=0')
solve('2*x -log(y) = 1','y')
solve('2*x -log(y) = 1','x')
[x, y] = solve('x^2 - y = 2', 'y - 2*x = 5')
x(1)
x(1)*x(2)
solve(ans)
simplify(x(1)*x(2))
sol= solve('x^2 - y = 2', 'y - 2*x = 5')
sol.x
sol.y
solve('sin(x) = 2 - x')
solve('exp(-x) = sin(x)')
fzero(inline('exp(-x) - sin(x)'), 0.5)
fzero(inline('exp(-x) - sin(x)'), 3)
fzero(inline('exp(-x) - sin(x)'), 6)
fzero(inline('exp(-x) - sin(x)'), 9)
f = inline('x^2 + x + 1', 'x');f(4)
f1 = inline(vectorize('x^2 + x + 1', 'x');f1(1:5)
f1 = inline(vectorize('x^2 + x + 1', 'x'));f1(1:5)
f1 = inline(vectorize('x^2 + x + 1'), 'x');f1(1:5)
ezplot('sin(x)^2/(x^2)',[-2,2])
%-- 14-05-2016 13:02 --%
%-- 15-05-2016 22:51 --%
%-- 16-05-2016 12:40 --%
ezplot('sin(x)^2/(x^2)',[-2,2])
ezplot('sin(x)/x',[-2,2])
figure,ezplot('sin(x)^2/(x^2)',[-2,2])
ezplot('(x)^2+x+1',[-2,2])
title 'parabola'
axis([-2 2 2.5 3.5])
axis([-2 2 1 3])
axis([-2 2 2.5 3.5])
ezplot('(x)^2+x+1',[-2,2])
title 'parabola'
%-- 16-05-2016 14:00 --%
%-- 17-05-2016 19:33 --%
factor(x^4-y^4)
syms x
factor(x^4-y^4)
syms x y
factor(x^4-y^4)
syms x y z
factor(x^3+y^3+z^3-3*x*y*z)
syms x y
factor(x^2+y^2)

ezplot('exp(-x)', [0 10])
hold on
ezplot('sin(x)', [0 10])
ezplot('tan(x)',[0 10])
X = 0:0.1:10;
plot(X, exp(-X), X, sin(X))
hold off
plot(X, exp(-X), X, sin(X))
%-- 19-05-2016 16:48 --%
%-- 22-05-2016 06:58 --%
%-- 23-05-2016 13:02 --%
%-- 26-05-2016 11:21 --%
%-- 26-05-2016 11:35 --%
%-- 26-05-2016 20:11 --%
jdhcuyjwef
f;ewrfcewfdkewc /
%-- 30-05-2016 17:56 --%
sinelimit(10)
sinelimit(5)
function y = sinelimit(c)
% SINELIMIT computes sin(x)/x for x = 10 (-b),
% where b = 1, ..., c.
format long
b = 1:c;
x = 10.^(-b);
y = (sin(x)./x)';
sinelimit(5)
sinelimit(10)
[X,Y] = meshgrid(-1:.1:1, -1:.1:1);
mesh(X, Y, sqrt(max(1 - X. 2 - Y. 2, 0)))
syms x y; ezsurf(sin(x)*sin(y), [-3*pi 3*pi -3*pi 3*pi])
f = inline( [x(1) - x(1) 2 - 2*x(1)*x(2); x(2) - x(2) 2 2*x(1)*x(2)] , t , x );
for a = 0:1/12:13/12
for b = 0:1/12:13/12
[t, xa] = ode45(f, [0 3], [a,b]);
plot(xa(:, 1), xa(:, 2))
echo off
end
end
axis([0 13/12 0 13/12])
f = inline('[x(1) - x(1)^2 - 2*x(1)*x(2); x(2) - x(2)^2 2*x(1)*x(2)]', 't', 'x');
for a = 0:1/12:13/12
for b = 0:1/12:13/12
[t, xa] = ode45(f, [0 3], [a,b]);
plot(xa(:, 1), xa(:, 2))
echo off
end
end
axis([0 13/12 0 13/12])
f = inline('[x(1) - x(1)^2 - 2*x(1)*x(2); x(2) - x(2)^2 -2*x(1)*x(2)]', 't', 'x'
);
for a = 0:1/12:13/12
for b = 0:1/12:13/12
[t, xa] = ode45(f, [0 3], [a,b]);
plot(xa(:, 1), xa(:, 2))
echo off
end
end

axis([0 13/12 0 13/12])


%-- 02-06-2016 05:16 --%
%-- 05-06-2016 19:42 --%
%-- 19-06-2016 02:43 --%
%-- 20-06-2016 14:31 --%
arduino_gettingstarted
arduinouno_gettingstarted
ver
clc
mex -setup
%-- 21-06-2016 16:47 --%
%-- 23-06-2016 23:16 --%
%-- 23-06-2016 23:25 --%
%-- 24-06-2016 23:03 --%
ver
mex - setup
%-- 01-07-2016 20:34 --%
[W s v]=svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x');
%-- 07-07-2016 21:10 --%
%-- 28-07-2016 20:09 --%
v = zeros(10, 1);A=rand(10,10);
for i = 1:10
for j = 1:10
v(i) = v(i) + A(i, j) * x(j);
end
end
v = zeros(10, 1);A=rand(10,10);x=rand(10,1)
for i = 1:10
for j = 1:10
v(i) = v(i) + A(i, j) * x(j);
end
end
v
a=[1 2 3]
b=[1;2;3]
a.*b
a*b
ab
b=A*x
sum(b)
log(x)
x^2
submit
%-- 06-08-2016 14:39 --%
pwd
%-- 08-08-2016 13:28 --%
pwd
cd 'C:Users/Dell/Desktop'
ls
CD 'C:Users/Dell/Desktop'
cd 'C:Users/Dell/Desktop'
pwd
cd 'C:Users/Dell/Desktop'
load video.mat
load('video.mat')
A=magic(3)
max(A,[],1)
max(A,[],2)
a=rand(3,3)
floor(a)

ceil(a)
[r,c]=find(A>=7)
find(A,3)
find(a<0.5)
a
[r,c]=find(A<=7)
val=max(a)
[val,ind]=max(a)
a=rand(3)
a=rand(3,1)
a=rand(1,3)
val=max(a)
[val,ind]=max(a)
A
B=[1 2 3 ;4 5 6;7 8 9]
A.*B
A./B
format long
A./B
format short
1./a
1./A
1./B
log(A)
log(A.*B)
exp(log(log(log(A.*B))))
i
0.7321+0.0000i
X= exp(log(log(log(A.*B))))
X(1,1)
max(rand(3),rand(3))
A(:)
max(max())
max(max(A))
A=magic(9)
sum(A,1)
sum(A,2)
eye(9)
A.*eye(9)
pinv(A.*eye(9))
b= pinv(A.*eye(9))
(A.*eye(9))*b
pinv(eye(9))
sum(sum(A.eye(9)))
sum(sum(A.*eye(9)))
sum(sum(A./eye(9)))
sum(sum(A.^eye(9)))
sum(sum(A.+eye(9)))
sum(sum(A+eye(9)))
sum(sum(A-eye(9)))
sum(sum(A&eye(9)))
sum(sum(A||eye(9)))
A/eye(9)
A||eye(9)
flipud(eye(9))
t=[0:0.01:0.98]
y1=sin(2*pi*4*t)
plot(t,y1)
y2=cos(2*pi*4*t);plot(t,y2);hold on;plot(t,y2,'r')
hold on

plot(t,y1)
hold on
plot(t,y2)
plot(t,y2,'r')
xlabel('time')
ylabel('value')
plot(t,y1)
hold on
plot(t,y2)
hold on
plot(t,y2,'r')
xlabel(''time)
xlabel('time')
ylabel('value')
legend('sin','cos')
plot(t,y1)
hold on
plot(t,y2,'r')
xlabel('time')
ylabel('value')
title('my plot')
legend('sin','cos')
cd 'C:Users/Dell/Documents/Matlab';print -dpng 'myplot.pngcdc'
cd( 'C:Users/Dell/Documents/Matlab');print -dpng 'myplot.pngcdc'
help plot
help cd
cd
figure(1);plot(t,y1)
figure(2);plot(t,y2)
subplot(1,2,1)
plot(t,y1)
subplot(1,2,2);plot(t,y2)
axis([0.5 1 -1 1])
subplot(1,2,1);axis([0.5 1 -1 1])
xlabel('time')
ylabel('value')
subplot(1,2,1);xlabel('time');ylabel('value')
subplot(1,2,2);xlabel('time');ylabel('value')
title('cos curve')
subplot(1,2,1);title('sin curve')
clf;
A=magic(5)
imagesc(A)
imagesc(A),colorbar
imagesc(A),colorbar,colormap gray;
imagesc(magic(15))
imagesc(magic(20)),colorbar,colormap rgb;
imagesc(magic(20)),colorbar,colormap RGB
gray2rgb
colormap(spring)
colormap(rgb)
colormap(jet)
x=imagesc(magic(20));
colormap(gray)
imagesc(magic(16))
imagesc(magic(15))
for i=1:20
subplot(1,20,i+2);imagesc(magic(i+2))
end
clf;

for i=1:10,
v(i)=2^i;
end;
v=
v
costfunctionJ
X=[1 1;1 2;1 3]
y=[1 ;2;3]
theta=[0;1]
j=costfunctionJ(X,y,theta)
theta=[0;0]
j=costfunctionJ(X,y,theta)
warmUpExercise()
warmUpExercise
clear;
clc
warmUpExercise
%-- 09-08-2016 15:47 --%
warmUpExercise
plotData
%-- 09-08-2016 16:11 --%
plotData
%-- 09-08-2016 16:12 --%
plotData
X
data = load('ex1data1.txt');
X = data(:, 1); y = data(:, 2)
X
size(X)
size(y)
plotData
x
computeCost
y
size(y)
computeCost
length(y)
computeCost
submit
chandan.kr.eee15@itbhu.ac.in
disp(1)
gradientDescent
a=[1;2]
a(1)
a(1,1)
a(2,1)
gradientDescent
format long
gradientDescent
clc
gradientDescent
x
X
size(X)
y
size(y)
X=[ones(97,1),X]
format short
size(X)
computeCost

theta=[0;0]
computeCost(X,y,theta)
theta=[1;2]
computeCost(X,y,theta)
computeCost
computeCost(X,y,theta)
computeCost(X,y,[0;0])
gradientDescent
1.3703e+03
1.3703e-03
1.37e+04
gradientDescent
plotData
gradientDescent
%-- 10-08-2016 11:22 --%
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx
gradientDescent
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx
gradientDescent
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx
gradientDescent
plotData
gradientDescent
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx
submit
chandan.kr.eee15@itbhu.ac.in
J5QeCMHP3DEIzDTx

Potrebbero piacerti anche