public void DistBetwTwoClasses(int n1, int n2, double[][] arr, List <Myimage> temp1, List <Myimage> temp2) { for (int j = 0; j < n1; j++) { for (int k = 0; k < n2; k++) { { arr[j][k] = PerceptiveHash.hamming(temp1[j].Hash, temp2[k].Hash); } } } }
public void DistAtOneClass(int n, double[][] arr, List <Myimage> temp) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { { if (j != k) { arr[j][k] = PerceptiveHash.hamming(temp[j].Hash, temp[k].Hash); } } } } }
public string Recognize(Myimage X) { Myimage k = new Myimage(); double min = PerceptiveHash.hamming(X.Hash, etal1[0].Hash); for (int i = 0; i < etal1.Count; i++) { Int64 h = PerceptiveHash.hamming(X.Hash, etal1[i].Hash); if (min >= h) { min = h; k = etal1[i]; } } return(k.DirectoryPath); }
public void CheckHash(RadioButton rb1, RadioButton rb2, RadioButton rb3, RadioButton rb4, BitmapImage bm1, Myimage m) { if (rb1.IsChecked == true) { m.Hash = PerceptiveHash.aHash(bm1); } if (rb2.IsChecked == true) { m.Hash = PerceptiveHash.pHash(bm1); } if (rb3.IsChecked == true) { m.Hash = PerceptiveHash.dHash(bm1); } if (rb4.IsChecked == true) { m.Hash = PerceptiveHash.gHash(bm1); } }
public void FindGroup() { rez = new List <Int64>(); string s = Interaction.InputBox("Enter % of similarity"); double perc = int.Parse(s); perc = Math.Round(perc * 0.64); ListOfClusters.Clear(); for (int k = 0; k < imglist.Count; k++) { ListOfClusters.Add(new Cluster()); } List <Myimage> tmp = new List <Myimage>(); for (int i = 0; i < imglist.Count; i++) { prbar.Dispatcher.Invoke(() => prbar.Value++, DispatcherPriority.Background); int p = 0; for (int k = 0; k < ListOfClusters.Count; k++) { if (ListOfClusters[k].ImgInCluster.Contains(imglist[i])) { p++; } } if (p == 0) { ListOfClusters[i].ImgInCluster.Add(imglist[i]); tmp.Add(imglist[i]); } for (int j = 0; j < imglist.Count; j++) { Int64 ham = PerceptiveHash.hamming(imglist[i].Hash, imglist[j].Hash); if ((ham <= (64 - perc)) && (i != j) && (!tmp.Contains(imglist[j]))) { ListOfClusters[i].ImgInCluster.Add(imglist[j]); tmp.Add(imglist[j]); } } } }
public void FindSimilar(Myimage m) { wrp.Children.Clear(); string s = Interaction.InputBox("Enter % of similarity"); double perc = int.Parse(s); perc = Math.Round(perc * 0.64); List <Myimage> similarList = new List <Myimage>(); for (int j = 0; j < imglist.Count; j++) { Int64 ham = PerceptiveHash.hamming(m.Hash, imglist[j].Hash); if (ham <= (64 - perc)) { similarList.Add(imglist[j]); } } for (int i = 0; i < similarList.Count; i++) { Uri uriSource = new Uri(similarList[i].ImagePath); bm1 = new BitmapImage(); bm1.BeginInit(); bm1.UriSource = uriSource; bm1.EndInit(); System.Windows.Controls.Image im = new System.Windows.Controls.Image(); im.Source = bm1; im.Width = 100; im.Height = 75; im.MouseEnter += new MouseEventHandler(OnMouseEnterHandler); im.MouseLeave += new MouseEventHandler(OnMouseLeaveHandler); ToolTip tooltip = new ToolTip { Content = similarList[i].ImagePath }; im.ToolTip = tooltip; im.Margin = new Thickness(5, 5, 5, 5); wrp.Children.Add(im); scrollv.ScrollToBottom(); } }
public void clusterDend() { ListOfClusters.Clear(); iterations = new List <Iteration>(); // ListOfObj = new List<Myimage>(); // ListOfObj = imglist.GetRange(0, imglist.Count); for (int k = 0; k < imglist.Count; k++) { ListOfClusters.Add(new Cluster()); ListOfClusters[k].ImgInCluster.Add(imglist[k]); } n = 1; double[,] data = new double[imglist.Count, imglist.Count]; for (int i = 0; i < imglist.Count; i++) { for (int j = 0; j < imglist.Count; j++) { data[i, j] = PerceptiveHash.hamming(imglist[i].Hash, imglist[j].Hash); } } RowsCount = imglist.Count; ColumnsCount = imglist.Count; List <List <double> > matrix = new List <List <double> >(RowsCount + 1); for (int i = 0; i < RowsCount; i++) { var list = new List <double>(ColumnsCount); for (int j = 0; j < ColumnsCount; j++) { list.Add(data[i, j]); } matrix.Add(list); } var list1 = new List <double>(ColumnsCount); for (int j = 0; j < ColumnsCount; j++) { list1.Add(j); } matrix.Add(list1); order = new List <List <int> >(); for (int i = 0; i < imglist.Count; i++) { order.Add(new List <int>()); order[i].Add(i); } orderlist = new List <Order>(); max = 0; iterations.Add(new Iteration { Clusters = Copy2(ListOfClusters) }); while (ListOfClusters.FindAll(i => (i.ImgInCluster.Count != 0)).Count != n) { min = MinValue(matrix, out index1, out index2); if (min > max) { max = min; } double d1 = 0; double d2 = 0; for (int i = 0; i < ColumnsCount; i++) { if (index1 != i) { d1 = matrix[index1][i]; d2 = matrix[index2][i]; matrix[index1][i] = (d1 + d2) / 2; matrix[i][index1] = (d1 + d2) / 2; } } orderlist.Add(new Hashes.Order { set1 = Copy(order[Convert.ToInt32(matrix[RowsCount][index1])]), set2 = Copy(order[Convert.ToInt32(matrix[RowsCount][index2])]), dist = min }); order[Convert.ToInt32(matrix[RowsCount][index1])].AddRange(order[Convert.ToInt32(matrix[RowsCount][index2])]); order[Convert.ToInt32(matrix[RowsCount][index2])].Clear(); ListOfClusters[Convert.ToInt32(matrix[RowsCount][index1])].ImgInCluster.AddRange(ListOfClusters[Convert.ToInt32(matrix[RowsCount][index2])].ImgInCluster); ListOfClusters[Convert.ToInt32(matrix[RowsCount][index2])].ImgInCluster.Clear(); iterations.Add(new Iteration { Clusters = Copy2(ListOfClusters) }); RemoveRow(index2, matrix); RemoveColumn(index2, matrix); } PaintDend(); }