1) How do I download
a single folder using the LabelMe Matlab toolbox?
HOMEIMAGES =
'/desired/path/to/Images';
HOMEANNOTATIONS = '/desired/path/to/Annotations';
folderlist = {'05june05_static_street_porter'};
LMinstall (folderlist, HOMEIMAGES,
HOMEANNOTATIONS);
2) How do I get all
of the object names in a folder?
If you want to know all of the different object descriptions that have been provided within a folder, you can use the command LMobjectnames. This can be useful to understand the object categories available.
HOMEANNOTATIONS = 'http://labelme.csail.mit.edu/Annotations';
HOMEIMAGES = 'http://labelme.csail.mit.edu/Images';
D = LMdatabase(HOMEANNOTATIONS, {'static_nature_web_outdoor_animal'});
[names, counts] = LMobjectnames(D);
3) How do I label a
subset of the images?
HOMEANNOTATIONS = 'http://labelme.csail.mit.edu/Annotations';
HOMEIMAGES = 'http://labelme.csail.mit.edu/Images';
D = LMdatabase(HOMEANNOTATIONS,
{'spatial_envelope_256x256_static_8outdoorcategories'});
for i = 1:length(D);
folderlist{i} = D(i).annotation.folder;
filelist{i}
= D(i).annotation.filename;
end
LMthumbnailsbar(folderlist(1:500), filelist(1:500),
'page1.html', HOMEIMAGES);
LMthumbnailsbar(folderlist(501:1000), filelist(501:1000),
'page2.html', HOMEIMAGES);
This code will create two pages: page1.html and page2.html
4) How do I download
only the images that contain ‘cars’ (or some other object)?
First you have to create the index (this will take few minutes)
HOMEANNOTATIONS = 'http://labelme.csail.mit.edu/Annotations';
HOMEIMAGES = 'http://labelme.csail.mit.edu/Images';
D = LMdatabase(HOMEANNOTATIONS);
Then, you can create the list of images that you want using
the function LMquery.
If you only want pictures containing cars:
[Q,j] = LMquery(D, 'object.name', 'car');
clear folderlist filelist
for i = 1:length(Q);
folderlist{i} = Q(i).annotation.folder;
filelist{i} = Q(i).annotation.filename;
end
And now you can download those images onto your local machine with the LMinstall
command:
HOMEIMAGES = '/desired/path/to/Images';
HOMEANNOTATIONS = '/desired/path/to/Annotations';
LMinstall (folderlist, filelist, HOMEIMAGES, HOMEANNOTATIONS);
5) How do I
crop all of the objects and save each one as an image?
Use the function LMobjectcrop, then loop on all images and objects:
for n = 1:length(D)
if isfield(D(n).annotation, ‘object’)
for m = 1:length(D(n).annotation.object)
imgCrop
= LMobjectcrop(img, D(n).annotation,
m);
%
save imgCrop in some local
folder
end
end
end
6) How do I remove all objects that are too small?
Use the function addsmallobjectlabel:
D = addsmallobjectlabel(D, height, width);
This function will add the label ‘smallobject’
to objects smaller than [height x width] pixels.
Then you can use LMquery to get
rid of the small objects:
D = LMquery(D, ‘object.name’, ‘-smallobject’);
Many images are already fully annotated. In order to find those images, you can use the command LMlabeledarea. This function will return, for each image in the dataset, the percentage of pixels that are labeled:
relativearea = LMlabeledarea(D, objectname);
The scene description is stored in the field: D.annotation.scenedescription. So, to get all the kitchen images, you can do the query:
Dq = LMQuery(D, 'scenedescription', 'kitchen');
You can find a detailed example of using Wordnet with LabelMe in this Matlab script:
http://labelme.csail.mit.edu/LabelMeToolbox/demoWordnet.m
The toolbox does not require installation of Wordnet.