Jump to content


Check out our Community Blogs





- - - - -

Matlab Skin Detection Without Using Any Inbuilt Filters For Videos

Posted by SkHacker, 30 July 2012 · 5757 views

matlab detection filters videos
Matlab Skin Detection Without Using Any Inbuilt Filters For Videos Matlab Skin Detector without using any inbuilt Filter

Developers FB contact: https://www.facebook.../saurabhhacker2

Many Matlab programs have been developed till now to detect human skin. They all uses high-tech programming styles.
I never liked to use functions that are inbuilt and people uses them even if the dint know their details.
So i tried to develop a program that does not uses any inbuilt filter for the detection part.
Although i have use functions of matlab that are used to capture video from my laptop camera.

I have also included the Matlab program for our aim.

vid = videoinput('winvideo', 1, 'YUY2_640x480');

This line creates an object for video input in matlab using the driver 'winvideo' of matlab.
The number '1' stands for the 1st camera. In case if we are having another cameras like external camera, we can change this number to '2', '3', etc. such that the cameras are arranged in an array.
The string 'YUY2_640x480' represents the type of video quality to be captured



set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval =5;

The are the extra settings for runnig the webcam using the object 'vid' .
The property 'FrameGrabInterval' specifies the speed of the object vid o take photo frames from the camera.



start(vid)

It starts the vid object to take input from the camera.



while(vid.FramesAcquired<=50)

This while loop will run untill the camera has not captured 50 frames.
For infinite loop you can write as 'while(1)' .



imge = getsnapshot(vid);

Here we take a snapshot of image coming to the vid object and storing it to a variable 'imge'.
Now the variable 'imge' becomes a 3 dimensional matrix of which the first layer is the red component of the image, similarly the 2nd layer is the green and the 3rd layer is the blue intensity.



gray=rgb2gray(imge);

Now we change the image to a gray scale image.
It look same as the black and white movies that our grand parents used to see.



ir=imge(:,:,1);
ig=imge(:,:,2);

As we have discussed different layers of image, here we extract those layers in different variable for our use.
ir holds the red component of the image and
ig holds the green component of the image



[r c d]=size(imge);

Here we are extracting the dimension of the image, r as number of rows c as number of columns and d as number of layers where d=3 for a RGB image.


for i=1:r
	for j=1:c
		if gray(i,j)>50 && gray(i,j)<100 && ir(i,j)>70 && ir(i,j)<180 && ig(i,j)>20
			temp(i,j)=255;
		else
			temp(i,j)=0;
		end
	end
end

This for loop checks the value of red and green values for each pixel of the image and creates a new image 'temp' which is a black and white image where white represents the skin and black represents the non-skin.
If the logic 'gray(i,j)>50 && gray(i,j)<100 && ir(i,j)>70 && ir(i,j)<180 && ig(i,j)>20' is satisfied the we consider the current pixel is a part of human skin, so temp is assigned the value 255 (i.e. for white color).


subplot(1,1,1);imshow(temp);title('My Edge Detection')
end
stop(vid);
flushdata(vid);
clear all

We use the function 'subplot' to plot the resultant image 'temp' on the output window.
Instead we can also use 'imshow(temp)' function.


Hope u find this useful and interesting.
If you face any complexity in executing this program please post your comments, because this program is a fully tested one.

Matlab 3D using Red-Cyan Images from two webcams: http://forum.codecal.../#axzz2Ia7rCwBZ

Attached Files



  • 1



My Picture

Search My Blog

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download