Ejemplo n.º 1
0
        public List <DTOs.ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List <ImageRecord> rtnImageList = new List <ImageRecord>();

            RgbProjections queryProjections;

            using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(queryImagePath), 100, 100))
            {
                queryProjections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
            }
            BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >();
            List <RGBProjectionRecord> AllImage = repo.Load();

            foreach (var imgInfo in AllImage)
            {
                var dist = imgInfo.RGBProjection.CalculateSimilarity(queryProjections);
                if (dist > 0.8d)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }
            rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList();
            return(rtnImageList);
        }
Ejemplo n.º 2
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List<PHashImageRecord> listOfRecords = new List<PHashImageRecord>();
            string compressHash = string.Empty;
            int totalFileCount = imageFiles.Length;
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    compressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
                }

                PHashImageRecord record = new PHashImageRecord
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CompressHash = compressHash
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository<List<PHashImageRecord>> repo = new BinaryAlgoRepository<List<PHashImageRecord>>();
            repo.Save(listOfRecords);
        }
Ejemplo n.º 3
0
        public void IndexFiles(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null)
        {
            List<RGBProjectionRecord> listOfRecords = new List<RGBProjectionRecord>();

            RgbProjections projections = null;
            int totalFileCount = imageFiles.Length;
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100))
                {
                    projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
                }

                RGBProjectionRecord record = new RGBProjectionRecord
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    RGBProjection = projections
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository<List<RGBProjectionRecord>> repo = new BinaryAlgoRepository<List<RGBProjectionRecord>>();
            repo.Save(listOfRecords);
        }
Ejemplo n.º 4
0
        public List<ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List<ImageRecord> rtnImageList = new List<ImageRecord>();

            string queryImageCompressHash;
            using (Bitmap bmp = new Bitmap(System.Drawing.Image.FromFile(queryImagePath)))
            {
                queryImageCompressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
            }
            BinaryAlgoRepository<List<PHashImageRecord>> repo = new BinaryAlgoRepository<List<PHashImageRecord>>();
            List<PHashImageRecord> AllImage = repo.Load();
            foreach (var imgInfo in AllImage)
            {
                var dist = SimilarImage.CompareHashes(queryImageCompressHash, imgInfo.CompressHash);
                if (dist > 0.8)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }

            rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList();

            return rtnImageList;
        }
Ejemplo n.º 5
0
        public List <ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List <ImageRecord> rtnImageList = new List <ImageRecord>();

            double[,] queryHistogram;
            using (Image img = Image.FromFile(queryImagePath))
            {
                queryHistogram = BhattacharyyaCompare.Bhattacharyya.CalculateNormalizedHistogram(img);
            }
            BinaryAlgoRepository <List <BhattacharyyaRecord> > repo = new BinaryAlgoRepository <List <BhattacharyyaRecord> >();
            List <BhattacharyyaRecord> AllImage = repo.Load();

            foreach (var imgInfo in AllImage)
            {
                double[,] norHist = SingleToMulti(imgInfo.NormalizedHistogram);
                var dist = BhattacharyyaCompare.Bhattacharyya.CompareHistogramPercDiff(queryHistogram, norHist);
                if (dist < 3)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }
            rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList();
            return(rtnImageList);
        }
Ejemplo n.º 6
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List <CEDDRecord> listOfRecords = new List <CEDDRecord>();

            double[] ceddDiscriptor = null;
            int      totalFileCount = imageFiles.Length;
            CEDD     cedd           = new CEDD();

            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id             = i,
                    ImageName      = fi.Name,
                    ImagePath      = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository <List <CEDDRecord> > repo = new BinaryAlgoRepository <List <CEDDRecord> >();

            repo.Save(listOfRecords);
        }
Ejemplo n.º 7
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List<CEDDRecord> listOfRecords = new List<CEDDRecord>();

            double[] ceddDiscriptor = null;
            int totalFileCount = imageFiles.Length;
            CEDD cedd = new CEDD();
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository<List<CEDDRecord>> repo = new BinaryAlgoRepository<List<CEDDRecord>>();
            repo.Save(listOfRecords);
        }
Ejemplo n.º 8
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List <PHashImageRecord> listOfRecords = new List <PHashImageRecord>();
            string compressHash   = string.Empty;
            int    totalFileCount = imageFiles.Length;

            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    compressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
                }

                PHashImageRecord record = new PHashImageRecord
                {
                    Id           = i,
                    ImageName    = fi.Name,
                    ImagePath    = fi.FullName,
                    CompressHash = compressHash
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository <List <PHashImageRecord> > repo = new BinaryAlgoRepository <List <PHashImageRecord> >();

            repo.Save(listOfRecords);
        }
Ejemplo n.º 9
0
        public List <ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List <ImageRecord> rtnImageList = new List <ImageRecord>();

            string queryImageCompressHash;

            using (Bitmap bmp = new Bitmap(System.Drawing.Image.FromFile(queryImagePath)))
            {
                queryImageCompressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
            }
            BinaryAlgoRepository <List <PHashImageRecord> > repo = new BinaryAlgoRepository <List <PHashImageRecord> >();
            List <PHashImageRecord> AllImage = repo.Load();

            foreach (var imgInfo in AllImage)
            {
                var dist = SimilarImage.CompareHashes(queryImageCompressHash, imgInfo.CompressHash);
                if (dist > 0.8)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }

            rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList();

            return(rtnImageList);
        }
Ejemplo n.º 10
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List <BhattacharyyaRecord> listOfRecords = new List <BhattacharyyaRecord>();

            Double[,] normalizedHistogram = new double[16, 16];
            int totalFileCount = imageFiles.Length;

            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Image img = Image.FromFile(fi.FullName))
                {
                    normalizedHistogram = Bhattacharyya.CalculateNormalizedHistogram(img);
                }

                BhattacharyyaRecord record = new BhattacharyyaRecord
                {
                    Id                  = i,
                    ImageName           = fi.Name,
                    ImagePath           = fi.FullName,
                    NormalizedHistogram = MultiToSingle(normalizedHistogram)
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository <List <BhattacharyyaRecord> > repo = new BinaryAlgoRepository <List <BhattacharyyaRecord> >();

            repo.Save(listOfRecords);
        }
Ejemplo n.º 11
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List<BhattacharyyaRecord> listOfRecords = new List<BhattacharyyaRecord>();

            Double[,] normalizedHistogram = new double[16,16];
            int totalFileCount = imageFiles.Length;
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Image img = Image.FromFile(fi.FullName))
                {
                    normalizedHistogram = Bhattacharyya.CalculateNormalizedHistogram(img);
                }

                BhattacharyyaRecord record = new BhattacharyyaRecord
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    NormalizedHistogram = MultiToSingle(normalizedHistogram)
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository<List<BhattacharyyaRecord>> repo = new BinaryAlgoRepository<List<BhattacharyyaRecord>>();
            repo.Save(listOfRecords);
        }
Ejemplo n.º 12
0
        public void IndexFiles(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null)
        {
            List <RGBProjectionRecord> listOfRecords = new List <RGBProjectionRecord>();

            RgbProjections projections    = null;
            int            totalFileCount = imageFiles.Length;

            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100))
                {
                    projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
                }

                RGBProjectionRecord record = new RGBProjectionRecord
                {
                    Id            = i,
                    ImageName     = fi.Name,
                    ImagePath     = fi.FullName,
                    RGBProjection = projections
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >();

            repo.Save(listOfRecords);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public void IndexFilesAsync(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag <RGBProjectionRecord> listOfRecords = new ConcurrentBag <RGBProjectionRecord>();

            RgbProjections projections    = null;
            int            totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100))
                {
                    projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                RGBProjectionRecord record = new RGBProjectionRecord
                {
                    Id            = nextSequence,
                    ImageName     = fi.Name,
                    ImagePath     = fi.FullName,
                    RGBProjection = projections
                };

                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >();

            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 15
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag <BhattacharyyaRecord> listOfRecords = new ConcurrentBag <BhattacharyyaRecord>();

            Double[,] normalizedHistogram = new double[16, 16];
            int totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();


            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Image img = Image.FromFile(fi.FullName))
                {
                    normalizedHistogram = Bhattacharyya.CalculateNormalizedHistogram(img);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                BhattacharyyaRecord record = new BhattacharyyaRecord
                {
                    Id                  = nextSequence,
                    ImageName           = fi.Name,
                    ImagePath           = fi.FullName,
                    NormalizedHistogram = MultiToSingle(normalizedHistogram)
                };
                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository <List <BhattacharyyaRecord> > repo = new BinaryAlgoRepository <List <BhattacharyyaRecord> >();

            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 16
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag <PHashImageRecord> listOfRecords = new ConcurrentBag <PHashImageRecord>();

            string compressHash   = string.Empty;
            int    totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope: long nextSequence;
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    compressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                PHashImageRecord record = new PHashImageRecord
                {
                    Id           = nextSequence,
                    ImageName    = fi.Name,
                    ImagePath    = fi.FullName,
                    CompressHash = compressHash
                };

                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository <List <PHashImageRecord> > repo = new BinaryAlgoRepository <List <PHashImageRecord> >();

            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 17
0
        public void IndexFilesAsync(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag<RGBProjectionRecord> listOfRecords = new ConcurrentBag<RGBProjectionRecord>();

            RgbProjections projections = null;
            int totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100))
                {
                    projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                RGBProjectionRecord record = new RGBProjectionRecord
                {
                    Id = nextSequence,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    RGBProjection = projections
                };

                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository<List<RGBProjectionRecord>> repo = new BinaryAlgoRepository<List<RGBProjectionRecord>>();
            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 18
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag <CEDDRecord> listOfRecords = new ConcurrentBag <CEDDRecord>();

            double[] ceddDiscriptor = null;
            int      totalFileCount = imageFiles.Length;
            CEDD     cedd           = new CEDD();

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id             = nextSequence,
                    ImageName      = fi.Name,
                    ImagePath      = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository <List <CEDDRecord> > repo = new BinaryAlgoRepository <List <CEDDRecord> >();

            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 19
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag<PHashImageRecord> listOfRecords = new ConcurrentBag<PHashImageRecord>();

            string compressHash = string.Empty;
            int totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope: long nextSequence;
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    compressHash = SimilarImage.GetCompressedImageHashAsString(bmp);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                PHashImageRecord record = new PHashImageRecord
                {
                    Id = nextSequence,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CompressHash = compressHash
                };

                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository<List<PHashImageRecord>> repo = new BinaryAlgoRepository<List<PHashImageRecord>>();
            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 20
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag<CEDDRecord> listOfRecords = new ConcurrentBag<CEDDRecord>();

            double[] ceddDiscriptor = null;
            int totalFileCount = imageFiles.Length;
            CEDD cedd = new CEDD();

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id = nextSequence,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository<List<CEDDRecord>> repo = new BinaryAlgoRepository<List<CEDDRecord>>();
            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 21
0
        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;
        }
Ejemplo n.º 22
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag<BhattacharyyaRecord> listOfRecords = new ConcurrentBag<BhattacharyyaRecord>();

            Double[,] normalizedHistogram = new double[16, 16];
            int totalFileCount = imageFiles.Length;

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Image img = Image.FromFile(fi.FullName))
                {
                    normalizedHistogram = Bhattacharyya.CalculateNormalizedHistogram(img);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                BhattacharyyaRecord record = new BhattacharyyaRecord
                {
                    Id = nextSequence,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    NormalizedHistogram = MultiToSingle(normalizedHistogram)
                };
                listOfRecords.Add(record);

                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository<List<BhattacharyyaRecord>> repo = new BinaryAlgoRepository<List<BhattacharyyaRecord>>();
            repo.Save(listOfRecords.ToList());
        }
Ejemplo n.º 23
0
        public List<DTOs.ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List<ImageRecord> rtnImageList = new List<ImageRecord>();

            RgbProjections queryProjections;

            using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(queryImagePath), 100, 100))
            {
                queryProjections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
            }
            BinaryAlgoRepository<List<RGBProjectionRecord>> repo = new BinaryAlgoRepository<List<RGBProjectionRecord>>();
            List<RGBProjectionRecord> AllImage = repo.Load();
            foreach (var imgInfo in AllImage)
            {
                var dist = imgInfo.RGBProjection.CalculateSimilarity(queryProjections);
                if (dist > 0.8d)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }
            rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList();
            return rtnImageList;
        }
Ejemplo n.º 24
0
        public List<ImageRecord> QueryImage(string queryImagePath, object argument = null)
        {
            List<ImageRecord> rtnImageList = new List<ImageRecord>();

            double[,] queryHistogram;
            using (Image img = Image.FromFile(queryImagePath))
            {
                queryHistogram = BhattacharyyaCompare.Bhattacharyya.CalculateNormalizedHistogram(img);
            }
            BinaryAlgoRepository<List<BhattacharyyaRecord>> repo = new BinaryAlgoRepository<List<BhattacharyyaRecord>>();
            List<BhattacharyyaRecord> AllImage = repo.Load();
            foreach (var imgInfo in AllImage)
            {
                double[,] norHist = SingleToMulti(imgInfo.NormalizedHistogram);
                var dist = BhattacharyyaCompare.Bhattacharyya.CompareHistogramPercDiff(queryHistogram, norHist);
                if (dist < 3)
                {
                    imgInfo.Distance = dist;
                    rtnImageList.Add(imgInfo);
                }
            }
            rtnImageList = rtnImageList.OrderBy(x => x.Distance).ToList();
            return rtnImageList;
        }