Last active
January 14, 2022 13:06
-
-
Save gognjanovski/5a4f9bd04ec9c38922c1ae27b748123a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function image_out = processSkinImage(filename) | |
Step 1... | |
% Read the image | |
original = imread(filename); | |
... | |
Step 2... | |
% Resize the image to 50x50 | |
image_resized = imresize(original, scale); | |
[M N Z] = size(image_resized); | |
% Initialize the output image | |
image_out = zeros(height,width); | |
image_out = zeros(M,N); | |
... | |
Step 3... | |
% Convert the image from RGB to YCbCr | |
img_ycbcr = rgb2ycbcr(image_resized); | |
Cb = img_ycbcr(:,:,2); | |
Cr = img_ycbcr(:,:,3); | |
... | |
Step 4... | |
% Get the central color of the image | |
% Expected the hand to be in the central of the image | |
central_color = img_ycbcr(int32(M/2),int32(N/2),:); | |
Cb_Color = central_color(:,:,2); | |
Cr_Color = central_color(:,:,3); | |
% Set the range | |
Cb_Difference = 15; | |
Cr_Difference = 10; | |
... | |
Step 5... | |
% Detect skin pixels | |
[r,c,v] = find(Cb>=Cb_Color-Cr_Difference & Cb<=Cb_Color+Cb_Difference & Cr>=Cr_Color-Cr_Difference & Cr<=Cr_Color+Cr_Difference); | |
... | |
Step 6... | |
% Mark detected pixels | |
for i=1:match_count | |
image_out(r(i),c(i)) = 1; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment