public List<ImageRecord> QueryImage(string queryImagePath, object argument = null) { List<ImageRecord> rtnImageList = new List<ImageRecord>(); CEDD_Descriptor.CEDD cedd = new CEDD_Descriptor.CEDD(); int goodMatchDistance = 35; if (argument != null && argument is Int32) goodMatchDistance = (int)argument; double[] queryCeddDiscriptor; using (Bitmap bmp = new Bitmap(Image.FromFile(queryImagePath))) { queryCeddDiscriptor = cedd.Apply(bmp); } Stopwatch sw = Stopwatch.StartNew(); BKTree<CEDDTreeNode> ceddTree = null; if (!CacheHelper.Get<BKTree<CEDDTreeNode>>("CeddIndexTree", out ceddTree)) { CEDDRepository<BKTree<CEDDTreeNode>> repo = new CEDDRepository<BKTree<CEDDTreeNode>>(); ceddTree = repo.Load(); if (ceddTree == null) throw new InvalidOperationException("Please index CEDD with BK-Tree before querying the Image"); CacheHelper.Add<BKTree<CEDDTreeNode>>(ceddTree, "CeddIndexTree"); } sw.Stop(); Debug.WriteLine("Load tooked {0} ms", sw.ElapsedMilliseconds); CEDDTreeNode queryNode = new CEDDTreeNode { Id = 0, ImagePath = queryImagePath, CEDDDiscriptor = queryCeddDiscriptor }; sw.Reset(); sw.Start(); Dictionary<CEDDTreeNode, Int32> result = ceddTree.query(queryNode, goodMatchDistance); sw.Stop(); Debug.WriteLine("Query tooked {0} ms", sw.ElapsedMilliseconds); foreach (KeyValuePair<CEDDTreeNode, Int32> ceddNode in result) { ImageRecord rec = new ImageRecord { Id = ceddNode.Key.Id, ImageName = ceddNode.Key.ImageName, ImagePath = ceddNode.Key.ImagePath, Distance = ceddNode.Value }; rtnImageList.Add(rec); } rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList(); return rtnImageList; }
/* public static float[] calculateInputVector_SURFHist(Bitmap img) { // Resize and create integral image int width = 300; int height = (300 * img.Height) / img.Width; IntegralImage iimg; Console.WriteLine(width.ToString() + "x" + height.ToString()); // Debug using (Bitmap resized = new Bitmap(width, height)) using(Graphics g = Graphics.FromImage(resized)) { g.DrawImage(img, 0, 0, width, height); iimg = IntegralImage.FromImage(resized); } // Extract the interest points var ipts = FastHessian.getIpoints(0.0002f, 5, 2, iimg); // Describe the interest points SurfDescriptor.DecribeInterestPoints(ipts, false, false, iimg); // Create global represesntation by histogram int n = ipts.First().descriptorLength; float[] resultArray = new float[n]; System.Threading.Tasks.Parallel.ForEach(ipts, currentElement => { for (int i = 0; i < n; i++) { resultArray[i] += currentElement.descriptor[i]; } }); // Debug Console.WriteLine(ipts.Count.ToString()); foreach (float f in resultArray) { Console.Write(f.ToString() + " "); } Console.WriteLine(); return resultArray; } */ /// <summary> /// Citation : S. Α. Chatzichristofis and Y. S. Boutalis, /// “CEDD: COLOR AND EDGE DIRECTIVITY DESCRIPTOR - A COMPACT DESCRIPTOR FOR IMAGE INDEXING AND RETRIEVAL.” /// « 6th International Conference in advanced research on Computer Vision Systems ICVS 2008 », /// May 12 to May 15, 2008, Santorini, Greece /// </summary> /// <param name="img"></param> /// <returns></returns> public static float[] calculateCEDD(Bitmap img) { float[] result = new float[144]; CEDD_Descriptor.CEDD cedd = new CEDD_Descriptor.CEDD(); result = convertDoublesToFloats(cedd.Apply(img)); /*/ Debug foreach (float c in result) Console.Write(c + " "); Console.WriteLine("\n\n"); */ return result; }
public List <ImageRecord> QueryImage(string queryImagePath, object argument = null) { List <ImageRecord> rtnImageList = new List <ImageRecord>(); CEDD_Descriptor.CEDD cedd = new CEDD_Descriptor.CEDD(); int goodMatchDistance = 35; if (argument != null && argument is Int32) { goodMatchDistance = (int)argument; } double[] queryCeddDiscriptor; using (Bitmap bmp = new Bitmap(Image.FromFile(queryImagePath))) { queryCeddDiscriptor = cedd.Apply(bmp); } Stopwatch sw = Stopwatch.StartNew(); BinaryAlgoRepository <List <CEDDRecord> > repo = new BinaryAlgoRepository <List <CEDDRecord> >(); List <CEDDRecord> AllImage = (List <CEDDRecord>)repo.Load(); sw.Stop(); Debug.WriteLine("Load tooked {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); foreach (var imgInfo in AllImage) { double[] ceddDiscriptor = imgInfo.CEDDDiscriptor; var dist = CEDD_Descriptor.CEDD.Compare(queryCeddDiscriptor, ceddDiscriptor); if (dist < goodMatchDistance) { imgInfo.Distance = dist; rtnImageList.Add(imgInfo); } } sw.Stop(); Debug.WriteLine("Query tooked {0} ms", sw.ElapsedMilliseconds); rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList(); return(rtnImageList); }
public List<ImageRecord> QueryImage(string queryImagePath, object argument = null) { List<ImageRecord> rtnImageList = new List<ImageRecord>(); CEDD_Descriptor.CEDD cedd = new CEDD_Descriptor.CEDD(); int goodMatchDistance = 35; if (argument != null && argument is Int32) goodMatchDistance = (int)argument; double[] queryCeddDiscriptor; using (Bitmap bmp = new Bitmap(Image.FromFile(queryImagePath))) { queryCeddDiscriptor = cedd.Apply(bmp); } Stopwatch sw = Stopwatch.StartNew(); BinaryAlgoRepository<List<CEDDRecord>> repo = new BinaryAlgoRepository<List<CEDDRecord>>(); List<CEDDRecord> AllImage = (List<CEDDRecord>)repo.Load(); sw.Stop(); Debug.WriteLine("Load tooked {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); foreach (var imgInfo in AllImage) { double[] ceddDiscriptor = imgInfo.CEDDDiscriptor; var dist = CEDD_Descriptor.CEDD.Compare(queryCeddDiscriptor, ceddDiscriptor); if (dist < goodMatchDistance) { imgInfo.Distance = dist; rtnImageList.Add(imgInfo); } } sw.Stop(); Debug.WriteLine("Query tooked {0} ms", sw.ElapsedMilliseconds); rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList(); return rtnImageList; }
public List <ImageRecord> QueryImage(string queryImagePath, object argument = null) { List <ImageRecord> rtnImageList = new List <ImageRecord>(); CEDD_Descriptor.CEDD cedd = new CEDD_Descriptor.CEDD(); int goodMatchDistance = 35; if (argument != null && argument is Int32) { goodMatchDistance = (int)argument; } double[] queryCeddDiscriptor; using (Bitmap bmp = new Bitmap(Image.FromFile(queryImagePath))) { queryCeddDiscriptor = cedd.Apply(bmp); } Stopwatch sw = Stopwatch.StartNew(); BKTree <CEDDTreeNode> ceddTree = null; if (!CacheHelper.Get <BKTree <CEDDTreeNode> >("CeddIndexTree", out ceddTree)) { CEDDRepository <BKTree <CEDDTreeNode> > repo = new CEDDRepository <BKTree <CEDDTreeNode> >(); ceddTree = repo.Load(); if (ceddTree == null) { throw new InvalidOperationException("Please index CEDD with BK-Tree before querying the Image"); } CacheHelper.Add <BKTree <CEDDTreeNode> >(ceddTree, "CeddIndexTree"); } sw.Stop(); Debug.WriteLine("Load tooked {0} ms", sw.ElapsedMilliseconds); CEDDTreeNode queryNode = new CEDDTreeNode { Id = 0, ImagePath = queryImagePath, CEDDDiscriptor = queryCeddDiscriptor }; sw.Reset(); sw.Start(); Dictionary <CEDDTreeNode, Int32> result = ceddTree.query(queryNode, goodMatchDistance); sw.Stop(); Debug.WriteLine("Query tooked {0} ms", sw.ElapsedMilliseconds); foreach (KeyValuePair <CEDDTreeNode, Int32> ceddNode in result) { ImageRecord rec = new ImageRecord { Id = ceddNode.Key.Id, ImageName = ceddNode.Key.ImageName, ImagePath = ceddNode.Key.ImagePath, Distance = ceddNode.Value }; rtnImageList.Add(rec); } rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList(); return(rtnImageList); }
public static double[] CalculateCEDDescriptor(Bitmap bitmap) { CEDD_Descriptor.CEDD CEDD = new CEDD_Descriptor.CEDD(); return CEDD.Apply(bitmap); }