QList<int> indexProperty(const QString &propName, QHash<QString, int> &valueMap, QHash<int, QVariant> &reverseLookup) const

Convert metadata values associated with propName to integers. Each unique value gets its own integer. This is useful in many classification problems where nominal data (e.g "Male", "Female") needs to represented with integers ("Male" = 0, "Female" = 1). valueMap and reverseLookup are created to allow easy conversion to the integer replacements and back.

  • function definition:

    QList<int> indexProperty(const QString &propName, QHash<QString, int> &valueMap, QHash<int, QVariant> &reverseLookup) const
    
  • parameters:

    Parameter Type Description
    propName const QString & Metadata key
    valueMap QHash<QString, int> & A mapping from metadata values to the equivalent unique index. QStrings are used instead of QVariant so comparison operators can be used. This is filled in by the function and can be provided empty.
    reverseLookup QHash<int, QVariant> & A mapping from the unique index to the original value. This is the reverse mapping of the valueMap. This is filled in by the function and can be provided empty.
  • output: (QList<int>) Returns a list of unique integers that can be mapped to the metadata values associated with propName. The integers can be mapped to their respective values using valueMap and the values can be mapped to the integers using reverseLookup.

  • example:
    Template t1, t2, t3, t4;
    
    t1.file.set("Key", QString("Class 1"));
    t2.file.set("Key", QString("Class 2"));
    t3.file.set("Key", QString("Class 3"));
    t4.file.set("Key", QString("Class 1"));
    
    TemplateList tList(QList<Template>() << t1 << t2 << t3 << t4);
    
    QHash<QString, int> valueMap;
    QHash<int, QVariant> reverseLookup;
    tList.indexProperty("Key", valueMap, reverseLookup); // returns [0, 1, 2, 0]
    valueMap; // returns QHash(("Class 1", 0)("Class 2", 1)("Class 3", 2))
    reverseLookup; // QHash((0, QVariant(QString, "Class 1")) (2, QVariant(QString, "Class 3")) (1, QVariant(QString, "Class 2")))
    

QList<int> indexProperty(const QString &propName, QHash<QString, int> *valueMap=NULL, QHash<int, QVariant> *reverseLookup=NULL) const

Shortcut to call indexProperty without valueMap or reverseLookup arguments.

  • function definition:

    QList<int> indexProperty(const QString &propName, QHash<QString, int> * valueMap=NULL,QHash<int, QVariant> * reverseLookup = NULL) const
    
  • parameters:

    Parameter Type Description
    propName const QString & Metadata key
    valueMap QHash<QString, int> * (Optional) A mapping from metadata values to the equivalent unique index. QStrings are used instead of QVariant so comparison operators can be used. This is filled in by the function and can be provided empty.
    reverseLookup QHash<int, QVariant> * (Optional) A mapping from the unique index to the original value. This is the reverse mapping of the valueMap. This is filled in by the function and can be provided empty.
  • output: (QList<int>) Returns a list of unique integers that can be mapped to the metadata values associated with propName. The integers can be mapped to their respective values using valueMap (if provided) and the values can be mapped to the integers using reverseLookup (if provided).

QList<int> applyIndex(const QString &propName, const QHash<QString, int> &valueMap) const

Apply a mapping to convert non-integer values to integers. Metadata values associated with propName are mapped through the given valueMap.

  • function definition:

    QList<int> applyIndex(const QString &propName, const QHash<QString, int> &valueMap) const
    
  • parameters:

    Parameter Type Description
    propName const QString & Metadata key
    valueMap const QHash<QString, int> & (Optional) A mapping from metadata values to the equivalent unique index. QStrings are used instead of QVariant so comparison operators can be used.
  • output: (Qlist<int>) Returns a list of integer values. The values are ordered in the same order as the Templates in the list. The values are calculated like so:

    1. If the value is found in the valueMap, its integer mapping is appened to the list.
    2. If the value is not found in the valueMap, -1 is appened to the list.
  • example:

    Template t1, t2, t3, t4;
    
    t1.file.set("Key", QString("Class 1"));
    t2.file.set("Key", QString("Class 2"));
    t3.file.set("Key", QString("Class 3"));
    t4.file.set("Key", QString("Class 1"));
    
    TemplateList tList(QList<Template>() << t1 << t2 << t3 << t4);
    
    QHash<QString, int> valueMap;
    valueMap.insert("Class 1", 0);
    valueMap.insert("Class 2", 1);
    
    tList.applyIndex("Key", valueMap); // returns [0, 1, -1, 0]
    

T bytes() const

Get the total number of bytes in the TemplateList.

  • function definition:

    template <typename T> T bytes() const
    
  • parameters: NONE

  • output: (T) Returns the sum of the bytes in each of the Templates in the list. T is a user specified type. It is expected to be numeric (int, float etc.)
  • see: bytes
  • example:
    Template t1, t2;
    
    t1.append(Mat::ones(1, 1, CV_8U)); // 1 byte
    t1.append(Mat::ones(2, 2, CV_8U)); // 4 bytes
    t2.append(Mat::ones(3, 3, CV_8U)); // 9 bytes
    t2.append(Mat::ones(4, 4, CV_8U)); // 16 bytes
    
    TemplateList tList(QList<Template>() << t1 << t2);
    tList.bytes(); // returns 30
    

QList<Mat> data(int index = 0) const

Get a list of matrices compiled from each Template in the list.

  • function definition:

    QList<cv::Mat> data(int index = 0) const
    
  • parameters:

    Parameter Type Description
    index int (Optional) Index into each Template to select a Mat. Default is 0.
  • output: (QList<Mat>) Returns a list of Mats. One Mat is supplied by each Template in the image at the specified index.

  • example:
    Template t1, t2;
    
    t1.append(Mat::ones(1, 1, CV_8U));
    t1.append(Mat::zeros(1, 1, CV_8U));
    t2.append(Mat::ones(1, 1, CV_8U));
    t2.append(Mat::zeros(1, 1, CV_8U));
    
    TemplateList tList(QList<Template>() << t1 << t2);
    tList.data(); // returns ["1", "1"];
    tList.data(1); // returns ["0", "0"];
    

QList<TemplateList> partition(const QList<int> &partitionSizes) const

Divide the TemplateList into a list of TemplateLists partitions.

  • function defintion:

    QList<TemplateList> partition(const QList<int> &partitionSizes) const
    
  • parameters:

    Parameter Type Description
    partitionSizes QList<int> A list of sizes for the partitions. The total number of partitions is equal to the length of this list. Each value in this list specifies the number of Mats that should be in each template of the associated partition. The sum of values in this list must equal the number of Mats in each Template in the original TemplateList.
  • output: (QList<TemplateList>) Returns a QList of TemplateLists of partitions. Each partition has length equal to the number of templates in the original TemplateList. Each Template has length equal to the size specified in the associated value in partitionSizes.

  • example:
    Template t1, t2, t3;
    
    t1.append(Mat::ones(1, 1, CV_8U));
    t1.append(2*Mat::ones(1, 1, CV_8U));
    t1.append(3*Mat::ones(1, 1, CV_8U));
    
    t2.append(4*Mat::ones(1, 1, CV_8U));
    t2.append(5*Mat::ones(1, 1, CV_8U));
    t2.append(6*Mat::ones(1, 1, CV_8U));
    
    t3.append(7*Mat::ones(1, 1, CV_8U));
    t3.append(8*Mat::ones(1, 1, CV_8U));
    t3.append(9*Mat::ones(1, 1, CV_8U));
    
    TemplateList tList(QList<Template>() << t1 << t2 << t3);
    
    QList<TemplateList> partitions = tList.partition(QList<int>() << 1 << 2); // split into 2 partitions. 1 with 1 Mat and 1 with 2 Mats.
    
    partitions[0]; // returns [("1"), ("4"), ("7")]
    partitions[1]; // returns [("2", "3"), ("5", "6"), ("8", "9")]
    

FileList files() const

Get a list of all the Files in the TemplateList

  • function definition:

    FileList files() const
    
  • parameters: NONE

  • output: (FileList) Returns a FileList with the file of each Template in the TemplateList.
  • example:
    Template t1("picture1.jpg"), t2("picture2.jpg");
    
    t1.file.set("Key", QVariant::fromValue<float>(1));
    t2.file.set("Key", QVariant::fromValue<float>(2));
    
    TemplateList tList(QList<Template>() << t1 << t2);
    
    tList.files(); // returns ["picture1.jpg[Key=1]", "picture2.jpg[Key=2]"]
    

FileList operator()()

Shortcut call to files

  • function definition:

    FileList operator()() const
    
  • parameters: NONE

  • output: (FileList) Returns a FileList with the file of each Template in the TemplateList.
  • example:
    Template t1("picture1.jpg"), t2("picture2.jpg");
    
    t1.file.set("Key", QVariant::fromValue<float>(1));
    t2.file.set("Key", QVariant::fromValue<float>(2));
    
    TemplateList tList(QList<Template>() << t1 << t2);
    
    tList.files(); // returns ["picture1.jpg[Key=1]", "picture2.jpg[Key=2]"]
    

QMap<T, int> countValues(const QString &propName, bool excludeFailures = false) const

Get the frequency of each unique value associated with a provided metadata key.

  • function definition:

template QMap countValues(const QString &propName, bool excludeFailures = false) const

  • parameters:

    Parameter Type Description
    propName const QString & Metadata key
    excludeFailures bool (Optional) Exclude File metadata if the File has fte equal to true. Default is false
  • output: (QMap<<T, int>) Returns a mapping between unique metadata and their frequency.

  • example:
    Template t1, t2, t3, t4;
    
    t1.file.set("Key", QString("Class 1"));
    t2.file.set("Key", QString("Class 2"));
    t3.file.set("Key", QString("Class 3"));
    t4.file.set("Key", QString("Class 1"));
    
    TemplateList tList(QList<Template>() << t1 << t2 << t3 << t4);
    
    tList.countValues<QString>("Key"); // returns QMap(("Class 1", 2), ("Class 2", 1), ("Class 3", 1))
    

TemplateList reduced() const

Reduce the Templates in the TemplateList by merging them together.

  • function definition:

    TemplateList reduced() const
    
  • parameters: NONE

  • output: (TemplateList) Returns a TemplateList with a single Template. The Template is the result of calling merge on every Template.
  • see: merge
  • example:
    Template t1("picture1.jpg"), t2("picture2.jpg");
    
    t1.file.set("Key1", QString("Value1"));
    t2.file.set("Key2", QString("Value2"));
    
    TemplateList tList(QList<Template>() << t1 << t2);
    
    TemplateList reduced = tList.reduced();
    reduced.size(); // returns 1
    reduced.files(); // returns ["picture1.jpg;picture2.jpg[Key1=Value1, Key2=Value2, separator=;]"]
    

QList<int> find(const QString &key, const T &value)

Get the indices of every Template that has a provided key value pairing in its metadata

  • function definition:

    template<typename T> QList<int> find(const QString &key, const <tt>T</tt> &value)
    
  • parameters:

    Parameter Type Description
    key const QString & Metadata key to search for
    value const T & Value to search for. Both the key and value must match. T is a user specified type.
  • output: (QList<int>) Returns a list of indices for Templates that contained the key-value pairing in their metadata

  • example:
    Template t1, t2, t3;
    
    t1.file.set("Key", QString("Value1"));
    t2.file.set("Key", QString("Value2"));
    t3.file.set("Key", QString("Value2"));
    
    TemplateList tList(QList<Template>() << t1 << t2 << t3);
    tList.find<QString>("Key", "Value2"); // returns [1, 2]