// Caps holes taking values (weighted by distance) from neighborhood // for interpolation; filter can cap holes as large as filterHalfSize*2; // multiple passes could be needed. public static FloatMap CapHoles(FloatMap imgfIn, int filterHalfSize) { bool thereAreStillHoles = true; while (thereAreStillHoles) { imgfIn = MapUtils.capHoles(imgfIn, filterHalfSize, out thereAreStillHoles); } return(imgfIn); }
void checkSpikes(object sender, MouseEventArgs e) { var typedSender = sender as Control; int w = _imgfs[0].W; int h = _imgfs[0].H; float xProp = (float)w / (float)typedSender.Width; float yProp = (float)h / (float)typedSender.Height; int x = (int)(e.X * xProp); int y = (int)(e.Y * yProp); Console.WriteLine("[{0},{1}] -> [{2},{3}]", e.X, e.Y, x, y); Console.WriteLine("spike: {0}", MapUtils.GetSpikeHeight(_maxMap, x, y)); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if ((_fileNames == null) || (_fileNames.Length <= 3)) { return; } _imgfs.Clear(); int fileCount = _fileNames.Length; float progressStep = 100.0f / (fileCount * 2.0f); float progress = 0; backgroundWorker1.ReportProgress((int)progress, "converting"); // for each selected file for (int fileIdx = 0; fileIdx < fileCount; ++fileIdx) { string fileName = _fileNames[fileIdx]; // load bitmap using (var _bmp = new Bitmap(fileName)) { if (fileIdx == 0) { _h = _bmp.Height; _w = _bmp.Width; } else { if ((_h != _bmp.Height) || (_w != _bmp.Width)) { MessageBox.Show("Images must have same size!"); return; } } FloatMap imgf; // get luminance map imgf = MapUtils.HalfMap(MapUtils.Bmp2Map(_bmp), PreShrinkTimes); _imgfs.Add(imgf); } // update and report progress progress += progressStep; backgroundWorker1.ReportProgress((int)progress); // check for cancellation if (backgroundWorker1.CancellationPending) { return; } } List <FloatMap> newImgfs = new List <FloatMap>(); backgroundWorker1.ReportProgress((int)progress, "getting contrast"); // for each luminance map foreach (var imgf in _imgfs) { // get contrast, then shrink result (averaging pixels) FloatMap newImgf = MapUtils.HalfMap(MapUtils.GetMultiResContrastEvaluation(imgf, MultiResSteps), ShrinkContrastTimes); newImgfs.Add(newImgf); // update and report progress progress += progressStep; backgroundWorker1.ReportProgress((int)progress); // check for cancellation if (backgroundWorker1.CancellationPending) { return; } } _imgfs = newImgfs; smoothDepth(); smoothDepth(); _maxMap = getMaxMap(); // smooth for (int i = 0; i < BlurTimes; ++i) { _maxMap = MapUtils.GaussianBlur(_maxMap, BlurSigma); } // filter out spikes _maxMap = MapUtils.SpikesFilter(_maxMap, SpikeFilterTreshold); // cap holes _maxMap = MapUtils.CapHoles(_maxMap, CapHolesFilterEmisize); // TODO: correct the bell-distorsion savePLY(); saveObj(); }