private void _invertImageUnderOverlayRectButton_Click(object sender, EventArgs e) { RasterImage image = _imageViewer.Image; // Add the overlay rect as a region to the image // The overlay rect is in image coordinates already but it is at top-left // view perspective, the image might not be. If you load a BMP file or click // the fast rotate buttons, you will notice this. // We can do one of two things: // 1. Use RasterRegionXForm to tell the AddRectangleToRegion method the // rect passed is in TopLeft: /* * RasterRegionXForm xForm = RasterRegionXForm.Default; * xForm.ViewPerspective = RasterViewPerspective.TopLeft; * image.AddRectangleToRegion(xForm, _overlayRect, RasterRegionCombineMode.Set); */ // RasterRegionXForm is a matrix that allows you to perform many more actions, // such as transform the rectangle from any coordinates to another. // 2. Use RasterImage.RectangleToImage to convert the rect from TopLeft // to the view perspective of the image: LeadRect dataRect = image.RectangleToImage(RasterViewPerspective.TopLeft, _overlayRect); image.AddRectangleToRegion(null, dataRect, RasterRegionCombineMode.Set); InvertCommand cmd = new InvertCommand(); cmd.Run(image); // Remove the region image.MakeRegionEmpty(); }
private void ApplyFilter() { try { RasterImage runImage = _originalBitmap.Clone(); if (_cbInvert.Checked) { runImage.UseLookupTable = false; InvertCommand invComd = new InvertCommand(); invComd.Run(runImage); } BackGroundRemovalCommand backgroundRemovalCommand = new BackGroundRemovalCommand(Convert.ToInt32(_numRemovalFactor.Value)); backgroundRemovalCommand.Run(runImage); MinMaxValuesCommand minMaxCmd = new MinMaxValuesCommand(); minMaxCmd.Run(runImage); int min = minMaxCmd.MinimumValue; int max = minMaxCmd.MaximumValue; if (_cbEnableEnhancements.Checked) { AverageCommand avrcmd = new AverageCommand(); avrcmd.Dimension = 5; avrcmd.Run(runImage); MultiscaleEnhancementCommand MSECommand = new MultiscaleEnhancementCommand(); MSECommand.Contrast = Convert.ToInt32(_numContrast.Value * 100); MSECommand.EdgeCoefficient = Convert.ToInt32(_numEdgeCoef.Value * 100); MSECommand.EdgeLevels = Convert.ToInt32(_numEdgeLevel.Value); MSECommand.LatitudeCoefficient = 140; MSECommand.LatitudeLevels = 5; MSECommand.Flags = MultiscaleEnhancementCommandFlags.EdgeEnhancement | MultiscaleEnhancementCommandFlags.LatitudeReduction; MSECommand.Type = MultiscaleEnhancementCommandType.Gaussian; MSECommand.Run(runImage); } else { AverageCommand avrcmd = new AverageCommand(); avrcmd.Dimension = 3; avrcmd.Run(runImage); } ApplyLinearVoiLookupTableCommand voiCmd = new ApplyLinearVoiLookupTableCommand(); voiCmd.Center = (min + max) / 2; voiCmd.Width = max - min; voiCmd.Flags = VoiLookupTableCommandFlags.UpdateMinMax; voiCmd.Run(runImage); GetLinearVoiLookupTableCommand voiLutCommand = new GetLinearVoiLookupTableCommand(GetLinearVoiLookupTableCommandFlags.None); voiLutCommand.Run(runImage); _form.WindowLevelWidth = (int)voiLutCommand.Width; _form.WindowLevelCenter = (int)voiLutCommand.Center; _viewer.Image = runImage; } catch (System.Exception /*ex*/) { } }
public static void Invert(RasterImage image, params string[] parameters) { InvertCommand cmd = new InvertCommand(); cmd.Run(image); }
/// <summary> /// Batch 2 Functions /// </summary> private void DoBatch2() { // save the current caption string tmpCaption = Text; // disable the form Enabled = false; // change cursor Cursor = Cursors.SizeNS; // Do AntiAlias Text = "AntiAliasing Image..."; AntiAliasingCommand antiAliasingCommand = new AntiAliasingCommand(); antiAliasingCommand.Threshold = 25; antiAliasingCommand.Dimension = 7; antiAliasingCommand.Filter = AntiAliasingCommandType.Type1; antiAliasingCommand.Run(_viewer.Image); Text = "Image Is AntiAliased"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeWE; // Do Reverse Text = "Reversing Image..."; FlipCommand flipCommand = new FlipCommand(); flipCommand.Horizontal = true; flipCommand.Run(_viewer.Image); Text = "Image Is Reversed"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeNS; // Do Grayscale Text = "Grayscaling Image..."; GrayscaleCommand grayScaleCommand = new GrayscaleCommand(); grayScaleCommand.BitsPerPixel = 8; grayScaleCommand.Run(_viewer.Image); Text = "Image Is Grayscaled"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeWE; // Do Invert Text = "Inverting Image..."; InvertCommand invertCommand = new InvertCommand(); invertCommand.Run(_viewer.Image); Text = "Image Is Inverted, Batch Is Complete"; _viewer.Refresh(); Thread.Sleep(2000); // change the cursor to arrow Cursor = Cursors.Arrow; // enable the form Enabled = true; // return the old caption Text = tmpCaption; }