LeadTools创建“图像去噪”应用程序的具体步骤

2024-10-15 01:00:49

1、打开Visual Studio .NET。点击 文件->新建->项目…。打开新建项目对话框后,在模板中选择“Visual C#”或“Visual Basic”,随后选择“Windows窗体应用程序”。在名称栏中输入项目名称“RemoveNoise”,并使用“浏览”按钮选择您工程的存储路径,点击“确定”。

2、在“解决方案资源管理器”中,右击“引用”,选择“添加引用”。根据当前工程的 Framework 版本和生成目标平台,选择添加相应的LeadTools控件,例如工程中的版本为 Framework 4.0、生成目标平台是 x86,则浏览选择Leadtools For .NET文件夹” <LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32”,选择以下的DLL“:Leadtools.dllLeadtools.Codecs.dllLeadtools.Codecs.Cmp.dllLeadtools.Codecs.Bmp.dllLeadtools.Codecs.Tif.dllLeadtools.ImageProcessing.Color.dll Leadtools.ImageProcessing.Core.dll Leadtools.ImageProcessing.Effects.dll Leadtools.WinForms.dll

3、从工具箱(视图->工具箱),添加7个RadioButton控件(将RadioButton的Text属性依照下表修改),两个Panel控件(Name分别修改为panelBefore和panelAfter)。如下图:

LeadTools创建“图像去噪”应用程序的具体步骤

4、切换至Form1的代码视图(右击Form1,选择查看代码),将下面几行代码添加到文件开始处:1: using Leadtools; 2: using Leadtools.Codecs; 3: using Leadtools.Codecs.Tif; 4: using Leadtools.ImageProcessing; 5: using Leadtools.ImageProcessing.Core; 6: using Leadtools.ImageProcessing.Effects; 7: using Leadtools.ImageProcessing.Color; 8: using Leadtools.WinForms;

5、将以下变量添加至Form1类: 1: private RasterImageViewer beforePic; 2: private RasterImageViewer afterPic; 3: private RasterCodecs codecs; 4: private RasterImage temp;

6、添加Form1 Load事件句柄,在其中添加以下代码: 1: beforePic = new RasterImageViewer(); 2: beforePic.BackColor = Color.DarkCyan; 3: beforePic.Dock = DockStyle.Fill; 4: beforePic.InteractiveMode = RasterViewerInteractiveMode.Pan; 5: beforePic.HorizontalAlignMode = RasterPaintAlignMode.Center; 6: beforePic.VerticalAlignMode = RasterPaintAlignMode.Center; 7: beforePic.AutoResetScaleFactor = false; 8: panelBefore.Controls.Add(beforePic); 9: beforePic.BringToFront();10:11: afterPic = new RasterImageViewer();12: afterPic.BackColor = beforePic.BackColor;13: afterPic.Dock = beforePic.Dock;14: afterPic.InteractiveMode = beforePic.InteractiveMode;15: afterPic.HorizontalAlignMode = beforePic.HorizontalAlignMode;16: afterPic.VerticalAlignMode = beforePic.VerticalAlignMode;17: afterPic.AutoResetScaleFactor = beforePic.AutoResetScaleFactor;18: panelAfter.Controls.Add(afterPic);19: afterPic.BringToFront();20:21: codecs = new RasterCodecs();22: codecs.ThrowExceptionsOnInvalidImages = true;

7、双击radioButton1,在radioButton1 CheckedChanged事件句柄中添加以下代码:(本段代码为DespeckleCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\clean.tif")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: DespeckleCommand command = new DespeckleCommand(); 6: 7: command.Run(temp); 8: afterPic.Image = temp;

8、双击radioButton2,在radioButton2 CheckedChanged事件句柄中添加以下代码:(本段代码为MedianCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: MedianCommand command = new MedianCommand(); 6: 7: command.Dimension = 9; 8: command.Run(temp); 9: afterPic.Image = temp;

9、双击radioButton3,在radioButton3 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为AverageCo罪焐芡拂mmand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: AverageCommand command = new AverageCommand(); 6: 7: command.Dimension = 3; 8: command.Run(temp); 9: afterPic.Image = temp;10: codecs.Save(temp, Path.Combine(Application.StartupPath, @"..\..\Pic\AverageCommandResult.jpg"), RasterImageFormat.Jpeg, 24);

10、双击radioButton4,在radioButton4 CheckedChanged事件句柄中添加以下代码:(本段代码为AutoBinaryCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: AutoBinaryCommand command = new AutoBinaryCommand(); 6: 7: command.Run(temp); 8: afterPic.Image = temp; 9: codecs.Save(temp, Path.Combine(Application.StartupPath, @"..\..\Pic\AutoBinaryCommand.jpg"), RasterImageFormat.Jpeg, 24);

11、双击radioButton5,在radioButton5 CheckedChanged事件句柄中添加以下代码:(本段代码为SmoothEdgesCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: SmoothEdgesCommand command = new SmoothEdgesCommand(); 6: command.Amount = 50; 7: command.Threshold = 0; 8: 9: command.Run(temp);10: afterPic.Image = temp;

12、双击radioButton6,在radioButton6 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为DiscreteFourierTransformCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: FourierTransformInformation FTArray = new FourierTransformInformation(temp); 6: LeadRect rcRange = new LeadRect(0, 0, temp.Width - 1, temp.Height - 1); 7: DiscreteFourierTransformCommand command = new DiscreteFourierTransformCommand(); 8: 9: command.FourierTransformInformation = FTArray;10: command.Range = rcRange;11: command.Flags = DiscreteFourierTransformCommandFlags.DiscreteFourierTransform |12: DiscreteFourierTransformCommandFlags.Gray |13: DiscreteFourierTransformCommandFlags.Range |14: DiscreteFourierTransformCommandFlags.InsideX |15: DiscreteFourierTransformCommandFlags.InsideY;16:17:18: FourierTransformDisplayCommand disCommand = new FourierTransformDisplayCommand();19: disCommand.Flags = FourierTransformDisplayCommandFlags.Log | FourierTransformDisplayCommandFlags.Magnitude;20: disCommand.FourierTransformInformation = command.FourierTransformInformation;21:22: disCommand.Run(temp);23:24: afterPic.Image = temp;

13、双击radioButton7,在radioButton7 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为FastFouri髫潋啜缅erTransformCommand类的使用) 1: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Master.jpg")); 2: 3: temp = beforePic.Image.Clone(); 4: 5: SizeCommand sizecommand = new SizeCommand(256, 256, Leadtools.RasterSizeFlags.Bicubic); 6: 7: sizecommand.Run(temp); 8: FourierTransformInformation FTArray = new FourierTransformInformation(temp); 9:10: FastFourierTransformCommand command = new FastFourierTransformCommand(FTArray, FastFourierTransformCommandFlags.FastFourierTransform | FastFourierTransformCommandFlags.Gray);11: command.Run(temp);12: LeadRect rcRect = new LeadRect(0, 0, temp.Width / 2, temp.Height / 2);13: FrequencyFilterCommand FreqCommand = new FrequencyFilterCommand(FTArray, rcRect, FrequencyFilterCommandFlags.InsideX | FrequencyFilterCommandFlags.OutsideY);14:15: FastFourierTransformCommand InvCommand = new FastFourierTransformCommand(FTArray, FastFourierTransformCommandFlags.InverseFastFourierTransform | FastFourierTransformCommandFlags.Gray | FastFourierTransformCommandFlags.Scale | FastFourierTransformCommandFlags.Both);16: InvCommand.Run(temp);17:18: afterPic.Image = temp;

14、编译运行程序。本文DEMO使用了DespeckleCommand、MedianCommand、AverageCommand、AutoBinaryCommand、SmoothEdgesCommand类对图像进行去噪处理,使用了离散傅里叶变换和快速傅里叶变换对图像进行了处理。结果如下图:

LeadTools创建“图像去噪”应用程序的具体步骤LeadTools创建“图像去噪”应用程序的具体步骤
猜你喜欢