iskdaemon icon indicating copy to clipboard operation
iskdaemon copied to clipboard

cluster images by similarity

Open ricardocabral opened this issue 13 years ago • 0 comments

there are already some datastructures on .h.

sample code for imgdb.cpp:

// cluster by similarity. Returns list of list of long ints (img ids)
long_list_2 clusterSim(const int dbId, float thresd, int fast = 0) {
long_list_2 res;        // will hold a list of lists. ie. a list of clusters
sigMap wSigs(dbSpace[dbId]->sigs);      // temporary map of sigs, as soon as an image becomes part of a cluster, it's removed from this map
sigMap wSigsTrack(dbSpace[dbId]->sigs); // temporary map of sigs, as soon as an image becomes part of a cluster, it's removed from this map

for (sigIterator sit = wSigs.begin(); sit != wSigs.end(); sit++) {  // for every img on db
    long_list res2;

    if (fast) {
        res2 =
            queryImgDataForThresFast(&wSigs, (*sit).second->avgl,
            thresd, 1);
    } else {
        res2 =
            queryImgDataForThres(dbId, &wSigs, (*sit).second->sig1,
            (*sit).second->sig2,
            (*sit).second->sig3,
            (*sit).second->avgl, thresd, 1);
    }
    //    continue;
    long int hid = (*sit).second->id;
    //    if ()
    wSigs.erase(hid);
    if (res2.size() <= 1) {
        if (wSigs.size() <= 1)
            break;      // everything already added to a cluster sim. Bail out immediately, otherwise next iteration
        // will segfault when incrementing sit
        continue;
    }
    res2.push_front(hid);
    res.push_back(res2);
    if (wSigs.size() <= 1)
        break;
    // sigIterator sit2 = wSigs.end();
    //    sigIterator sit3 = sit++;
}
return res;
}

ricardocabral avatar Jan 22 '12 18:01 ricardocabral