Ignore:
Timestamp:
2015-05-20T23:25:37+12:00 (9 years ago)
Author:
davidb
Message:

Changes resulting from writing the TPDL submission

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/nz-flag-design/trunk/similarity-2d/flag-processing.js

    r29806 r29906  
    251251    }
    252252
    253     console.log("Product for HSL histogram: " + quant_product);
     253    //console.log("Product for HSL histogram: " + quant_product);
    254254
    255255    return quant_product;
     
    283283   
    284284    var imageObj = new Image();
     285
    285286    imageObj.onload = function() {
    286287        callback_count++;
     
    333334        if (clicked_on_count==2) {
    334335            // trigger comparison
    335             alert("Similarity score: " + quantizedColourHistogramComparison(flag_comparison_array[0],flag_comparison_array[1]));
     336            alert("Similarity score: " + quantizedColourHistogramComparison(flag_comparison_array[0],flag_comparison_array[1]) + "%");
    336337            clicked_on_count=0;
    337338        }
     
    346347   
    347348   
    348     imageObj.src   = img_url;
    349     imageObj.title = title.toUpperCase();
     349    imageObj.src     = img_url;
     350        imageObj.height  = 216;
     351    imageObj.title   = title.toUpperCase();
    350352    imageObj.country = imageObj.title;
    351     imageObj.id    = "flag-img-" + i;
     353    imageObj.id      = "flag-img-" + i;
    352354
    353355    $displayDiv.append(imageObj);
     
    358360
    359361
     362function calcSimilarityValuesChain(newFlagQuantHSLHist,
     363                   chain_count, img_obj_list, img_obj_list_len,
     364                   progressVal, progress_step,
     365                   $progressArea,$progressBar)
     366{
     367    var imgObj = img_obj_list[chain_count];
     368
     369    var existingQuantHSLHist = imgObj.quantHSLHist;
     370
     371    var similarity_score = quantizedColourHistogramComparison(newFlagQuantHSLHist,existingQuantHSLHist);
     372    similarity_score = Math.round(similarity_score * 100) / 100; // round to 2 decimal places
     373    similarity_score *= 100; // express as percentage
     374
     375    imgObj.similarityScore = similarity_score;
     376        var img_title = imgObj.country;
     377
     378        if (isoCountryCodes != null) {
     379        var country_code = imgObj.country;
     380        img_title = isoCountryCodes[country_code] + " (" + country_code + ")";
     381    }
     382    imgObj.title = img_title + ", Similarity score: " + similarity_score + "%";
     383    if (similarity_score>50) {
     384        //imgObj.style.display = "block";
     385        //imgObj.style.visibility = "visible";
     386    }
     387    else {
     388        //imgObj.style.display = "none";
     389        //imgObj.style.visibility = "hidden";
     390    }
     391
     392
     393
     394    if (chain_count < img_obj_list_len-1) {
     395    progressVal += progress_step;   
     396    if ($progressBar.progressbar) {
     397        $progressBar.progressbar('value',progressVal);
     398    }
     399
     400    setTimeout(function()
     401           { calcSimilarityValuesChain(newFlagQuantHSLHist,
     402                           chain_count+1,img_obj_list, img_obj_list_len,
     403                           progressVal, progress_step,
     404                           $progressArea,$progressBar)
     405               }
     406           ,1 // any time delay causes break in 'rendering' thread, even 0!
     407           );
     408
     409    }
     410    else {
     411    // done
     412    $progressArea.find('span:first').text("Done.");
     413    if (img_obj_list_len>show_progress) {
     414        progressVal = 100;
     415        if ($progressBar.progressbar) {
     416        $progressBar.progressbar('value',progressVal);
     417        }
     418        $progressArea.slideUp();
     419    }
     420    }
     421
     422}
    360423
    361424function calcSimilarityValues(newFlagQuantHSLHist, $displayDiv,$progressArea,$progressBar)
     
    368431
    369432    var img_obj_list_len = img_obj_list.length;
     433    console.log("*** img obj list len = " + img_obj_list_len);
    370434
    371435    if (img_obj_list_len==0) {
     
    377441    }
    378442
    379     var progress_step = 100.0 / img_obj_list_len;
    380    
    381443    for (var i=0; i<img_obj_list.length; i++) {
    382444    var imgObj = img_obj_list[i];
     445    imgObj.style.display = "inline";
     446    //imgObj.style.visibility = "visible";
     447    }
     448
     449    var progress_step = 100.0 / img_obj_list_len;
     450/*
     451    var chain_count=0;
     452
     453    setTimeout(function() {
     454    calcSimilarityValuesChain(newFlagQuantHSLHist,
     455                  chain_count, img_obj_list, img_obj_list_len,
     456                  progressVal, progress_step,
     457                  $progressArea,$progressBar)
     458        }
     459    ,100
     460    );
     461*/
     462   
     463
     464    for (var i=0; i<img_obj_list.length; i++) {
     465    var imgObj = img_obj_list[i];
    383466
    384467    var existingQuantHSLHist = imgObj.quantHSLHist;
    385468
    386469    var similarity_score = quantizedColourHistogramComparison(newFlagQuantHSLHist,existingQuantHSLHist);
     470    similarity_score = Math.round(similarity_score * 100) / 100; // round to 2 decimal places
     471    similarity_score *= 100; // express as percentage
     472
    387473    imgObj.similarityScore = similarity_score;
    388     imgObj.title = imgObj.country + ", Similarity score: " + similarity_score;
     474        var img_title = imgObj.country;
     475
     476        if (isoCountryCodes != null) {
     477        var country_code = imgObj.country;
     478        img_title = isoCountryCodes[country_code] + " (" + country_code + ")";
     479    }
     480    imgObj.title = img_title + ", Similarity score: " + similarity_score + "%";
     481    if (similarity_score>50) {
     482        //imgObj.style.display = "inline";
     483        //imgObj.style.visibility = "visible";
     484    }
     485    else {
     486        //imgObj.style.display = "none";
     487        //imgObj.style.visibility = "hidden";
     488    }
    389489
    390490    progressVal += progress_step;   
    391     console.log("*** i = " + i);
    392     console.log("*** pbar = " + $progressBar.progressbar);
     491    //console.log("*** i = " + i);
     492    //console.log("*** pbar = " + $progressBar.progressbar);
    393493    if ($progressBar.progressbar) {
    394494        $progressBar.progressbar('value',progressVal);
     
    402502    $progressArea.slideUp();
    403503    }
     504
     505
    404506}
    405507
Note: See TracChangeset for help on using the changeset viewer.