public void MakeCriterionImages() { FloatMapImage origImage = ((Bitmap)Bitmap.FromFile("chessRGB.jpg")).ToFloatMap(); HybridSpreadingFilter.FilterSelectionCriterion criterion = new HybridSpreadingFilter.FilterSelectionCriterion() { Threshold = CRITERION_THRESHOLD }; criterion.OriginalImage = origImage; criterion.OriginalImageSAT = origImage.Integrate(); int width = (int)origImage.Width; int height = (int)origImage.Height; FloatMapImage criterionImage = new FloatMapImage(origImage.Width, origImage.Height, PixelFormat.Greyscale); float[, ,] sat = criterion.OriginalImageSAT.Image; int minPsfRadius = 1; int maxPsfRadius = 100; int step = 10; for (int psfRadius = minPsfRadius; psfRadius < maxPsfRadius; psfRadius += step) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { criterionImage.Image[x, y, 0] = criterion.SelectFilter(x, y, psfRadius); } } criterionImage.ToBitmap().Save(string.Format("chessRGB_criterion_{0:000}.png", psfRadius), System.Drawing.Imaging.ImageFormat.Png); } }
private void buttonLoad_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Image File"; ofd.Filter = "PNG Files|*.png" + "|PFM Files|*.pfm" + "|Bitmap Files|*.bmp" + "|Gif Files|*.gif" + "|JPEG Files|*.jpg" + "|TIFF Files|*.tif" + "|All Image types|*.png;*.pfm;*.bmp;*.gif;*.jpg;*.tif"; ofd.FilterIndex = 7; ofd.FileName = ""; if (ofd.ShowDialog() != DialogResult.OK) return; if (ofd.FileName.EndsWith(".pfm")) { if (inputHdrImage != null) { inputHdrImage.Dispose(); } inputHdrImage = PortableFloatMap.LoadImage(ofd.FileName); ReplaceLdrImage(ref inputLdrImage, inputHdrImage.ToBitmap(ToneMappingEnabled)); } else { ReplaceLdrImage(ref inputLdrImage, (Bitmap)Image.FromFile(ofd.FileName)); if (inputHdrImage != null) { inputHdrImage.Dispose(); } inputHdrImage = inputLdrImage.ToFloatMap(); } imageTypeComboBox.SelectedIndex = 0; // TODO: select original better updatePictureBoxImage(); if (outputHdrImage != null) { outputHdrImage.Dispose(); } outputHdrImage = null; ReplaceLdrImage(ref outputLdrImage, null); imageSizeLabel.Text = String.Format("{0}x{1}", inputHdrImage.Width, inputHdrImage.Height); }
private void filterImage() { if ((inputLdrImage == null) || (inputLdrImage == null)) return; Cursor.Current = Cursors.WaitCursor; Stopwatch sw = new Stopwatch(); sw.Start(); try { uint width = inputHdrImage.Width; uint height = inputHdrImage.Height; if ((depthMap != null) && ((depthMap.Width != width) || (depthMap.Height != height))) { throw new ArgumentException(String.Format( "Depth map must have the same dimensions as the input image" + " {0}x{1}, but it's size was {2}x{3}.", width, height, depthMap.Width, depthMap.Height)); } AbstractSpreadingFilter filter = GetSpreadingFilter(); filter.Blur = CreateBlurFunction(depthMap); //filter.SpreadOneRoundedPSF = true; outputHdrImage = filter.FilterImage(inputHdrImage, outputHdrImage); ReplaceLdrImage(ref outputLdrImage, outputHdrImage.ToBitmap(ToneMappingEnabled)); imageTypeComboBox.SelectedIndex = 1; // TODO: select the filtered image better updatePictureBoxImage(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error"); } sw.Stop(); labelElapsed.Text = String.Format("Elapsed time: {0:f}s", 1.0e-3 * sw.ElapsedMilliseconds); Cursor.Current = Cursors.Default; }
public void MakeUnthresholdedCriterionImages() { FloatMapImage origImage = ((Bitmap)Bitmap.FromFile("chessRGB.jpg")).ToFloatMap(); HybridSpreadingFilter.FilterSelectionCriterion criterion = new HybridSpreadingFilter.FilterSelectionCriterion() { Threshold = CRITERION_THRESHOLD }; criterion.OriginalImage = origImage; criterion.OriginalImageSAT = origImage.Integrate(); int width = (int)origImage.Width; int height = (int)origImage.Height; FloatMapImage criterionImage = new FloatMapImage(origImage.Width, origImage.Height, PixelFormat.Greyscale); FloatMapImage diffImage = new FloatMapImage(origImage.Width, origImage.Height, PixelFormat.Greyscale); float[, ,] sat = criterion.OriginalImageSAT.Image; int minPsfRadius = 1; int maxPsfRadius = 100; int step = 10; for (int psfRadius = minPsfRadius; psfRadius < maxPsfRadius; psfRadius += step) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float sourceIntensity = origImage.Image[x, y, 0]; int left = MathHelper.Clamp<int>(x - psfRadius - 1, 0, width - 1); int right = MathHelper.Clamp<int>(x + psfRadius, 0, width - 1); int top = MathHelper.Clamp<int>(y - psfRadius - 1, 0, height - 1); int bottom = MathHelper.Clamp<int>(y + psfRadius, 0, height - 1); float psfArea = (right - left) * (bottom - top); float psfSum = sat[right, bottom, 0] + sat[left, top, 0] - sat[left, bottom, 0] - sat[right, top, 0]; // average over neighborhood of the current pixel within the PSF radius // (except the current pixel itself) float averageOverPsf = (psfSum - sourceIntensity) / (psfArea - 1); //criterionImage.Image[x, y, 0] = (sourceIntensity > averageOverPsf) ? 1 : 0; diffImage.Image[x, y, 0] = sourceIntensity - averageOverPsf; //diffImage.Image[x, y, 0] = Math.Abs(sourceIntensity - averageOverPsf); //criterionImage.Image[x, y, 0] = criterion.SelectFilter(x, y, psfRadius); } } //criterionImage.ToBitmap().Save(string.Format("chessRGB_criterion_{0:000}.png", psfRadius), System.Drawing.Imaging.ImageFormat.Png); diffImage.ToBitmap(false).Save(string.Format("chessRGB_diff_nonabs_{0:000}.png", psfRadius), System.Drawing.Imaging.ImageFormat.Png); } }