Use of a particular file from bunch of files

I want to use a particular file from a bunch of files. So far I have used the following steps,
1) read and convert the image to binary
2) labeling the image using bwlabel()
3) used regionprops with BoundingBox attribute.
4) write each components to a new file based upon BoundingBox.
Now I have 11 files but I only need the file that has the face portion so that I can detect the edge of the particular file. How do I do that?

 Accepted Answer

If you did the conversion to binary correctly, the binary image would identify only the faces and so you'd have an image with just face. Maybe do color classification, or use the Computer Vision System Toolbox which identifies faces.

7 Comments

My code so far::
function [s,j]= ext_imgg( input_args )
imagen=imread(input_args);
if size(imagen,3)==3 % RGB image
imagen=rgb2gray(imagen);
end
%% Convert to inverted binary image
threshold = graythresh(imagen);
imagen =~im2bw(imagen,threshold);
%imagen=imagen > 25;
%% Remove all object containing fewer than 150 pixels
imagen = bwareaopen(imagen,150);
pause(1)
%% labeling components
[L Ne]=bwlabel(imagen);
propied=regionprops(L,'BoundingBox');
figure
imshow(~imagen);
title('Input Image with objects Marked')
hold on
%% using bounding box
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
pause (1)
j=0;
s=char();
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
%figure,imshow(~n1);
s1='im';
s2=num2str(j);
s3='.jpg';
str=strcat(s1,s2,s3);
s=char(s,str);
imwrite(~n1,str,'jpg');
pause(0.5)
j=j+1;
end
end
By doing this I am getting the face in one of the files (though in binary format). Now how am I supposed to work on that particular file, discarding others? And should I make any changes to the code so that the efficiency gets better?
I don't understand why you can't just work on it. Who's forcing you to work on any other files once you've found the one you want? What does "discard" mean - delete from disk? Or ignore? Once you've found the file you want, just work on it. Don't read in anymore images. It seems rather obvious.
Sayak
Sayak on 1 Nov 2012
Edited: Sayak on 1 Nov 2012
Actually by doing this I am getting more than one files (perfectly 11) where one of them contains the face. Now I am programmatically unable to find the one with the face.
Look one of the box contains the face only, I want to use only that part of the image. Thats the problem.How to work on the image file that contains the face only?
You're using a poor method to begin with. Why don't you use an established method like the Viola Jones method?
Thanks for the guidance. I did not know about the method but it helped me a lot. Now under the same context I have another query [How to use a particular file from bunch of files ?]
I have a folder with many files. Some of the file contains the name human1.jpg, human2.jpg human3.jpg and so on. Now I want to work with those file only whose file name has a string 'human'. How do I do that? Any help is appreciated.
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F You can specify the file pattern when you call dir:
filePattern = fullfile(folder, 'human*.jpg');
fileNames = dir(filePattern);
ooh. Simple use of wildcard. How did I miss that? Anyways, thanks for the answer and that awesome link.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!