⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lhiinstall.m

📁 This code can parse any image in matlab. Very elaborate code
💻 M
字号:
function LHIinstall(varargin);
%
% Downloads a set of folders from the LabelMe dataset.
%
% 1) Install all the images
%  LHIinstall(subset,HOMEIMAGES, HOMEANNOTATIONS, HOMELABELMAPS);
%
% 2) install only images in the specified folders
%  LHIinstall(subset,folderlist, HOMEIMAGES, HOMEANNOTATIONS, HOMELABELMAPS);
%
% 3) install only the images specified
%  LHIinstall(subset,folders, images, HOMEIMAGES, HOMEANNOTATIONS, HOMELABELMAPS);
%
% HOMEIMAGES, HOMEANNOTATIONS and HOMELABELMAPS point to your local destination folders.
%
% This function is useful if you do not want to download the entire
% dataset. You can first browse the dataset, and when you have decided for
% a set of folders that you want to use, you can use this function to
% download only those folders.
%

% If this function stops working, you might need to download the newest
% version of the toolbox in order to update the web addresses:

webpath = 'http://yoshi.cs.ucla.edu/yao/data/';

Narguments = length(varargin);
webpageimg = [webpath,varargin{1},'/Images'];
webpageanno = [webpath,varargin{1},'/Annotations'];
webpagelabelmap = [webpath,varargin{1},'/LabelMaps'];

switch Narguments
    case {0,1,2,3}
        disp('Example: LHIinstall(subset,HOMEIMAGES,HOMEANNOTATIONS, HOMELABELMAPS);');
        error('Not enough input arguments.')
    case 4
        disp(['Install subset',varargin{1}]);
        HOMEIMAGES = varargin{2};
        HOMEANNOTATIONS = varargin{3};
        HOMELABELMAPS = varargin{4};
        folderlist = urldir(webpageimg, 'DIR');
        folderlist = {folderlist(:).name};
        if strcmp(folderlist{1}(1),'/'); % remove root folder
            folderlist = folderlist(2:end);
        end
    case 5
        folderlist = varargin{2};
        HOMEIMAGES = varargin{3};
        HOMEANNOTATIONS = varargin{4};
        HOMELABELMAPS = varargin{5};
    case 5
        folders = varargin{2};
        filelist = varargin{3};
        folderlist = unique(folders);
        HOMEIMAGES = varargin{4};
        HOMEANNOTATIONS = varargin{5};
        HOMELABELMAPS = varargin{6};
    otherwise
        error('Too many input arguments');
end

Nfolders = length(folderlist);

% create folders:
disp('create folders');
for i = 1:Nfolders
    mkdir(HOMEIMAGES, folderlist{i});
    mkdir(HOMEANNOTATIONS, folderlist{i});
    mkdir(HOMELABELMAPS, folderlist{i});
end


disp('download images and annotations...')
for f = 1:Nfolders
    disp(sprintf('Downloading folder %s (%d/%d)...',  folderlist{f}, f, Nfolders))
    
    wpi = [webpageimg  '/' folderlist{f}];
    wpa = [webpageanno '/' folderlist{f}];
    wpl = [webpagelabelmap '/' folderlist{f}];

    if Narguments~=5
        images = urldir(wpi, 'img');
        if length(images)>0
            images = {images(:).name};
        end
        
        annotations = urldir(wpa, 'txt');
        if length(annotations)>0
            annotations = {annotations(:).name};
        end
        
        labelmaps = urldir(wpl, 'png');
        if length(labelmaps)>0
            labelmaps = {labelmaps(:).name};
        end
    else
        j = strmatch(folderlist{f}, folders, 'exact');
        images = filelist(j);
        annotations = strrep(filelist(j), '.jpg', '.xml');
        labelmaps = strrep(filelist(j), '.jpg', '.png');
    end
    
    
    Nimages = length(images);
    for i = 1:Nimages
        disp(sprintf('    Downloading image %s (%d/%d)...',  images{i}, i, Nimages))
        [F,STATUS] = urlwrite([wpi '/' images{i}], fullfile(HOMEIMAGES,folderlist{f},images{i}));
    end
    
    Nanno= length(annotations);
    for i = 1:Nanno
        disp(sprintf('    Downloading annotation %s (%d/%d)...',  annotations{i}, i, Nanno))
        [F,STATUS] = urlwrite([wpa '/' annotations{i}], fullfile(HOMEANNOTATIONS,folderlist{f},annotations{i}));
        if STATUS == 0
            disp(sprintf('annotation file %s does not exist', annotations{i}))
        end
    end
    
    Nlabel= length(labelmaps);
    for i = 1:Nlabel
        disp(sprintf('    Downloading labelmap %s (%d/%d)...',  labelmaps{i}, i, Nlabel))
        [F,STATUS] = urlwrite([wpl '/' labelmaps{i}], fullfile(HOMELABELMAPS,folderlist{f},labelmaps{i}));
        if STATUS == 0
            disp(sprintf('labelmap file %s does not exist', labelmaps{i}))
        end
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -