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

📄 lhiquery.m

📁 This code can parse any image in matlab. Very elaborate code
💻 M
字号:
function [D, j] = LHIquery(D, fieldName, content, method)
%
% This function provides basic query functionalities. It allows you to
% locate images with certain objects.
%
% [D, j] = LHIquery(D, fieldName, content, method)
%
%    D:         database struct
%    fieldName: can be any of the fields in the struct at the object level.
%    content:   a string describing the desired field you are looking for.
%               you can use the characters '+' and '-' within the content string in
%               order to perform 'and' and 'not' operations.
%    method:    when selected 'exact', the content must be match exactly
%             Methods:
%               [] = default = substring matching (air => chair)
%               'exact' = strings should match exactly
%               'word'  = the field should match words (air ~=> chair) 
% 
% The function LMquery searchs for images in the database.
% Queries can be done on any field of the struct array.
% The fields for an image are:
%    filename
%    folder
%    source.sourceImage
%    source.sourceAnnotation
%    object(:).name
%    object(:).parts
%    object(:).verified
%    object(:).date
%    
%
% Look at the results of these two lines (HOMEIMAGES should be set with the path of the database):
% LHIdbshowobjects(LHIquery(D, 'object.name', 'plate+license'), HOMEIMAGES);
% LHIdbshowobjects(LHIquery(D, 'object.name', 'plate-license'), HOMEIMAGES);
%
% Performs an OR function. This will select objects that belong to one of this groups: 1) side views
% of cars, 2) buildings 3) roads or 4) trees.
% [D,j] = LHIquery(D, 'object.name', 'car+side,building,road,tree');
%
% To make AND queries of different objects within an image, you can chain several queries. 
% For instance, to get images that have cars, buildings and roads:
%    [Dfoo,j1] = LMquery(D, 'object.name', 'building');
%    [Dfoo,j2] = LMquery(D, 'object.name', 'road');
%    j = intersect(j1,j2);
%    LHIshow(LHIquery(D(j), 'object.name', 'car,building,road'));
%
% You can query other fields. The next lines allow you to select from the
% database, all the polygons that have been verified and that are not
% marked as deleted. This is something you might want to do often:
%    D = LHIquery(D, 'object.verified', '1');
%    D = LHIquery(D, 'object.deleted', '0');
%
% or D = LHIquery(LHIquery(D, 'object.verified', '1'), 'object.deleted', '0');
%
% You can also query based on the date of annotation:
%    LHIshow(LHIquery(database, 'date', '13-Jan'));
% [in the case of dates, D is an exception about the meaning of the
% character '-'. Here is just a separation between day and month].
%
% More examples:
% Queries for objects
% [Dj,j] = LHIquery(D, 'object.name', 'building');
% LHIdbshowscenes(D(j), HOMEIMAGES); % this shows all the objects in the images that contain buildings
% LHIdbshowscenes(Dj, HOMEIMAGES); % this shows only the buildings
%
% Queries for images in specific folders. 
% [Dj,j] = LHIquery(D, 'folder', '05june05_static_indoor');
% LHIdbshowscenes(D(j), HOMEIMAGES); % this shows all the objects
%
% The next example shows the annotated objects from images that come from the web:
% [Dj,j] = LHIquery(D, 'folder', 'web');
% LHIdbshowscenes(D(j), HOMEIMAGES); % this shows all the objects
%
% look for a specific image file:
% [Dj,j] = LHIquery(D, 'filename', 'p1010843.jpg');
% LHIdbshowscenes(D(j), HOMEIMAGES); % this shows all the objects
%
% look for objects annotated by one user:
% [Dj,j] = LHIquery(D, 'object.polygon.username', 'atb');
% LHIdbshowscenes(Dj, HOMEIMAGES); % this shows all the objects annotated by one user
%
% look for objects by viewpoint:
% [D,j] = LHIquery(D, 'object.viewpoint.azimuth', '0', 'exact');
%

if (nargin < 4)
    method = '';
end

% Parse query
%if length(strfind(fieldName, 'date'))>0
%    query{1} = {['+' lower(content)]};
%else
%    query = parseContent(content);
%end

% Parse query
if length(strfind(fieldName, 'date'))>0
    query{1} = {['+' lower(content)]};
elseif strcmp(method,'exact')
    query{1} = {['+' lower(content)]};
else
    query = parseContent(content);
end


% Parse queried field
fieldName = ['annotation.' fieldName];
fieldName = parseContent(fieldName, '.');

% Locate the images that verify the query
Nimages = length(D);
queriedImages = logical(zeros(Nimages,1));

for i = 1:Nimages
    v = D(i);
    
    vn = queryfields(v, fieldName, query, method);

    if length(vn)>0
        queriedImages(i)=1;
        D(i) = vn;
    end
end

disp(sprintf('%d matches out of %d', sum(queriedImages), length(D)))

D = D(queriedImages);
j = find(queriedImages);


function [vn, jc] = queryfields(v, fieldName, query, method);

vn = [];
jc = [];
depthfield = length(fieldName);

if depthfield == 1
    % End recursion
    if isfield(v, fieldName{1}{1}(2:end))
        jc = findobject({v.(fieldName{1}{1}(2:end))}, query, method);
        vn = v(jc);
    end
else
    if isfield(v, fieldName{1}{1}(2:end))
        % Recursive call
        N = length(v);
        q = logical(zeros(N,1));
        for i = 1:N
            vi = getfield(v, {i}, fieldName{1}{1}(2:end));
            vi = queryfields(vi, fieldName(2:end), query, method);
            q(i) = length(vi)>0;
            v(i).(fieldName{1}{1}(2:end)) = vi;
        end
        jc = find(q);
        vn = v(jc);
    end
end


⌨️ 快捷键说明

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