2017-04-05 8 views
0

私は最も礼儀正しいウェブの色を抽出した画像を持っています。 そして私は、同じ構造を含む画像(Artworks)を持つデータベースを持っています。 色の出現によって最も近い画像を知るために、(データベースに多くの画像があるため、パフォーマンスの面で)高速な方法があるかどうかを知りたいと思います。 Iは、例えば、(データ用)C#およびMongoDBの埋め込み文書のMongo DBクエリと出現回数

を使用: 試験イメージ:DBに

{ 
    Artist : ArtistTest 
    Artworks : 
    [ 
     { 
      Title : test1, 
      MostColors : [ 
          { 
           Color : Blue, 
           Occurence : 10 
          }, 
          { 
           Color : Green, 
           Occurence : 5 
          }, 
          { 
           Color : Red, 
           Occurence : 2 
          } 
      ] 
     } 
    ] 
} 

画像:理論的に

{ 
    Artist : ArtistTrain1 
    Artworks : 
    [ 
     { 
      Title : train11, 
      MostColors : [ 
          { 
           Color : Black, 
           Occurence : 20 
          }, 
          { 
           Color : Yellow, 
           Occurence : 3 
          }, 
          { 
           Color : Green, 
           Occurence : 1 
          } 
      ] 
     }, 
     { 
      Title : train12, 
      MostColors : [ 
          { 
           Color : Red, 
           Occurence : 30 
          }, 
          { 
           Color : Green, 
           Occurence : 10 
          }, 
          { 
           Color : Purple, 
           Occurence : 5 
          } 
      ] 
     } 
    ] 
}, 
{ 
    Artist : ArtistTrain2 
    Artworks : 
    [ 
     { 
      Title : train21, 
      MostColors : [ 
          { 
           Color : Green, 
           Occurence : 15 
          }, 
          { 
           Color : Red, 
           Occurence : 5 
          }, 
          { 
           Color : Blue, 
           Occurence : 1 
          } 
      ] 
     }, 
     { 
      Title : train22, 
      MostColors : [ 
          { 
           Color : Blue, 
           Occurence : 30 
          }, 
          { 
           Color : Green, 
           Occurence : 1 
          }, 
          { 
           Color : Red, 
           Occurence : 1 
          } 
      ] 
     }, 
     { 
      Title : train23, 
      MostColors : [ 
          { 
           Color : Red, 
           Occurence : 30 
          }, 
          { 
           Color : Blue, 
           Occurence : 10 
          }, 
          { 
           Color : Green, 
           Occurence : 5 
          } 
      ] 
     } 
    ] 
} 

結果のために(第1の最も近いです):

ArtistTrain2.train22 
ArtistTrain2.train23 
ArtistTrain2.train21 
ArtistTrain1.train12 
ArtistTrain1.train11 

あなたはどう思いますか? (私は注文についてはわからない)

ありがとう。

答えて

0

私は自分の問題の回避策を見つけると思います。私は各アートワークオカレンスの重み付け平均を計算します(重みは、テスト画像で最も使用される色で除算します(例:3:青、2:緑、1:赤)

mongoシェルで: :

db.ArtCollection.find({$or : [ 
     {"Artworks.MostColors.Color" : {$elemMatch : {$eq:"Blue"}}}, 
     {"Artworks.MostColors.Color" : {$elemMatch : {$eq:"Green"}}}, 
     {"Artworks.MostColors.Color" : {$elemMatch : {$eq:"Red"}}} 
    ]}).forEach(function(doc) 
    { doc.Artworks.forEach(function(art) 
     { 
     print (art.Title); 
     var sum = 0; 
     for(var ii =0; ii<art.MostColors.length;ii++) { 
      var coeff = 0; 
      if (art.MostColors[ii].Color == 'Blue') 
      { coeff = 3;} 
      else if (art.MostColors[ii].Color == 'Green') 
      { coeff = 2;} 
      else if (art.MostColors[ii].Color == 'Red')  
      { coeff = 1;} 
      sum+=art.MostColors[ii].Occurence*coeff;  
     } 
     print(' -- '+sum); 
     }) 
    }) 

私は

List<string> stirngcolor = new List<string>() { "Blue", "Green", "Red" };// 
Dictionary<string, double> dicoCoeff = new Dictionary<string, double>(); 
int coeffValue = 0; 
// Determine the weight of color (by occurrence decending) 
for (int i = stirngcolor.Count; i > 0; i--) 
{ 
    dicoCoeff.Add(stirngcolor[i - 1], coeffValue++); 
} 

var collection = _database.GetCollection<Artist>(collectionDb); 
var request = from x in collection.AsQueryable() 
      where x.Artworks.Any(child => 
       child.MostColors.Any(c => stirngcolor.Contains(c.color)) 
      ) 
      select x; 

List<Artist> artistList = request.ToList(); 
#region art 
foreach (Artist artistValue in listPaletet) 
{ 
    foreach (ArtWork art in artistValue.Artworks) 
    { 
     double sum = 0; 
     for (int ii = 0; ii < art.MostColors.Count; ii++) 
     { 
      double coeff = 0; 
      #region coeff 
      if (dicoCoeff.ContainsKey(art.MostColors[ii].color)) 
      { 
       coeff = dicoCoeff[art.MostColors[ii].color]; 
      } 
      #endregion 
      sum += art.MostColors[ii].occurrence * coeff; 
     } 
     art.colorScore = sum; 
     artList.Add(art); 
    } 
} 
#endregion 
(LINQを使用して)C#でこのプリンシペを翻訳します
関連する問題