SKIN DETECTION school project

Can anyone find any error in this code to do skin detection=




Uploading: Captura de ecrã 2021-12-13, às 15.58.02.png…

Please post the code as text instead of pictures. Why do you think that there is any error in the code ? Is it logic error or syntax error ?

Can anyone find any error in this code to do skin detection=

from a glance at a bunch of images: no, no I cant.

Octave usually tries tells to tell you where errors occur. please edit your post to include the actual code, then please directly copy/paste any error messages your receive.

function execute_alg(alg=2)
n_images = dir(‘InputImages’);
for i= 1:size(n_images,1)
if ~strcmpi(n_images(i).name, ‘.’) && ~strcmpi(n_images(i).name, ‘…’)
tic
if alg == 1
img = SD_hsv(strcat(‘InputImages/’, n_images(i).name));
elseif alg == 2
img = SD_ycbcr(strcat(‘InputImages/’,n_images(i).name));
end
toc
imwrite(img, strcat(‘OutputImages/’, n_images(i).name));
fprintf(‘Application paused. Press some key to continue\n’)
pause;
end
end

function [Y, Cb, Cr] = rgb2ycbcr(img)
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);

Y = 0.299R + 0.587G + 0.114*B;
Cb = (B-Y) * 0.564 + 128;
Cr = (R-Y) * 0.713 + 128;

end

function out = SD_hsv(img, smooth= false)
img =imread(‘InputImages’);
[m,n,_] = size(img);
out=ones(m,n);
hsv=rgb2hsv(img);
h=hsv(:,:,1);
s=hsv(:,:,2);

[r c v]=find(h>0.10 | s<=0.27 | s>0.78);
numid=size(r,1);

for i=1:numid
out(r(i),c(i))=0;
end
if smooth
fil = ones(3) * 1/9;
out = filter2(fil, out);
end

subplot(1,2,1)
imshow(img);
subplot(1,2,2)
imshow(out);

function bin = SD_ycbcr(img, smooth= false)
img = imread(‘img_addr.jpg’);
[h,w,_] = size(img);
bin = zeros(h,w);
[Y, Cb, Cr] = rgb2ycbcr(img);
[y,b,r] = find((138 < Cr & Cr < 180) & Y > 80 & ( Cb > 85 & Cb < 135)); %Define os intervalos dos parametros do algoritmo

numid=size(y,1);

for i=1:numid
bin(y(i),b(i))=1;
end

if smooth
fil = ones(3) * 1/9;
bin = filter2(fil, bin);
end

subplot(1,2,1)
imshow(bin);
subplot(1,2,2)
imshow(img)

end


Gives me this error

it appears that it has issue with the type of images you want it to read and write.

what are they? (DS_STORE?) how were they created? Can you first convert them to a supported format as suggested in the warning message?

I took a picture with the macbook app (photobooth) and save as jpg

not familiar with photobooth, but is it actually writing a jpg file or are you just saving it named jpg?

it is writing a jpg file

If I download any photo from the internet, it happens the same thing
So I don´t think the problem is with my picture

oh, wait. google tells me

The Finder automatically places a .DS_Store file into every folder you have opened. .DS_Store files are created by the Finder during its normal course of operation. These files hold view options, including the positions of icons, size of the Finder window, window backgrounds plus many more properties but are hidden from the user’s view.

If I had to guess, you’re processing the entire folder, and your Mac has put non-image files in there, possibly a hidden system file. that breaks the script. restrict the search to just jpg files and you’re probably okay.

1 Like

Yes!! I put the name of the file and it doesn’t make an error! Thank you so much!!

Another thing, if I run the SD_ycbcr and SD_hsv function, the command window doesn´t stop! It is not supposed right?

guessing what you mean by ‘command window doesn’t stop’ - check for missing semicolons. images are stored as very large arrays. semicolons tell octave to suppress output from that line. if you don’t tell it that, it may be trying to show a long list of a lot of data.

you can step through your code using breakpoints in the editor or ‘keyboard’ commands in the code. then see which line is triggering the problem output.

Does anyone know how can I convert the pixels that represent the skin to get back to the normal colors??