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); }
public double CalculateSimilarity(RgbProjections compare) { double num = RgbProjections.CalculateProjectionSimilarity(this.horizontalProjection, compare.horizontalProjection); double num1 = RgbProjections.CalculateProjectionSimilarity(this.verticalProjection, compare.verticalProjection); return(Math.Max(num, num1)); }
public ComparableImage(FileInfo file) { if (file == null) { throw new ArgumentNullException("file"); } if (!file.Exists) { throw new ArgumentNullException("file"); } this.file = file; using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(file.FullName), 100, 100)) { this.projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap)); } }
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()); }
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; }
public double CalculateSimilarity(RgbProjections compare) { double num = RgbProjections.CalculateProjectionSimilarity(this.horizontalProjection, compare.horizontalProjection); double num1 = RgbProjections.CalculateProjectionSimilarity(this.verticalProjection, compare.verticalProjection); return Math.Max(num, num1); }