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

📄 lhireplacepartname.m

📁 This code can parse any image in matlab. Very elaborate code
💻 M
字号:
function D = LHIreplaceobjectname(D, name1, name2, method, querymethod)
% Replace an object name by another name.
% It is not case sensitive.
%
% D = LHIreplaceobjectname(D, 'person walking', 'pedestrian')
%
% Reemplaces all the object names that contain the string 'person' by the
% short name 'person'
% D = LHIreplaceobjectname(D, 'person', 'person', 'rename')
%
% To prevent mistake replacement (e.g. intepretate 'basket'-> 'basketball'), 
% use querymethod  'word'
% D = LHIreplaceobjectname(D, 'bakset', 'container', 'rename','word') 
% Detail for querymethod see LHIquery.m
%
% Reemplaces all the object names that contain the strings 'person' or 'pedestrian' by the
% short name 'person'
% D = LHIreplaceobjectname(D, 'person,pedestrian', 'person', 'rename')
%
% It does not modify the annotation files. It only modifies the index
% struct.

if nargin < 4
    method = 'replace';
end

name1 = lower(name1);
name2 = lower(name2);

if nargin < 5
    [d, j] = LHIquery(D, 'object.parts.name', name1);
else
    [d, j] = LHIquery(D, 'object.parts.name', name1, querymethod);
end
clear d

Nimages = length(j);
for n = 1:Nimages
    Nobjects = length(D(j(n)).annotation.object);
    for m = 1:Nobjects
        if nargin < 5
            jc = LHIpartindex(D(j(n)).annotation.object(m),name1);
        else
            jc = LHIpartindex(D(j(n)).annotation.object(m),name1,querymethod);
        end

        for i = jc
            currentname = lower(D(j(n)).annotation.object(m).parts(i).name);
            switch method
                case 'replace'
                    % replace each substring name1 by name2
                    D(j(n)).annotation.object(m).parts(i).name = strrep(currentname, name1, name2);
                case 'rename'
                    % rename the object
                    D(j(n)).annotation.object(m).parts(i).name = name2;
            end
        end
    end
    

end

disp(sprintf('%d entries replaced', Nimages))

⌨️ 快捷键说明

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