Leadtools.ImageProcessing.Core Namespace > ApplyTransformationParametersCommand Class > ApplyTransformationParametersCommand Constructor : ApplyTransformationParametersCommand Constructor() |
public ApplyTransformationParametersCommand()
'Declaration Public Function New()
'Usage Dim instance As New ApplyTransformationParametersCommand()
public ApplyTransformationParametersCommand()
function ApplyTransformationParametersCommand()
public: ApplyTransformationParametersCommand();
Public Sub ApplyTransformationParametersConstructorExample() Dim codecs As New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg")) ' Prepare the command Dim tempImage As RasterImage tempImage = leadImage Try tempImage = leadImage.Clone() If (tempImage.HasRegion) Then tempImage.MakeRegionEmpty() End If If (leadImage.HasRegion) Then leadImage.MakeRegionEmpty() End If Dim rmData() As SearchRegistrationMarksCommandData ReDim rmData(2) Dim points() As LeadPoint ReDim points(0) ' Mark1 rmData(0) = New SearchRegistrationMarksCommandData rmData(0).Rectangle = New LeadRect(680, 20, 941 - 680, 218 - 20) rmData(0).MarkDetectedPoints = points rmData(0).Width = 31 rmData(0).Height = 29 rmData(0).Type = RegistrationMarkCommandType.TShape rmData(0).MinimumScale = 90 rmData(0).MaximumScale = 110 rmData(0).SearchMarkCount = 1 ' Mark2 rmData(1) = New SearchRegistrationMarksCommandData rmData(1).Rectangle = New LeadRect(665, 790, 899 - 665, 961 - 790) rmData(1).MarkDetectedPoints = points rmData(1).Width = 31 rmData(1).Height = 29 rmData(1).Type = RegistrationMarkCommandType.TShape rmData(1).MinimumScale = 90 rmData(1).MaximumScale = 110 rmData(1).SearchMarkCount = 1 ' Mark3 rmData(2) = New SearchRegistrationMarksCommandData(31, 29, 90, 110, New LeadRect(7, 1073, 298 - 7, 1246 - 1073), 1, points, RegistrationMarkCommandType.TShape) Dim command1 As SearchRegistrationMarksCommand command1 = New SearchRegistrationMarksCommand command1.SearchMarks = rmData command1.Run(leadImage) If ((rmData(2).MarkDetectedCount <> 1) OrElse (rmData(1).MarkDetectedCount <> 1) OrElse (rmData(0).MarkDetectedCount <> 1)) Then Return End If Dim original() As LeadPoint ReDim original(2) original(0) = New LeadPoint(81400, 11300) original(1) = New LeadPoint(78600, 87400) original(2) = New LeadPoint(14300, 115400) Dim detected() As LeadPoint ReDim detected(2) detected(0) = rmData(0).MarkDetectedPoints(0) detected(1) = rmData(1).MarkDetectedPoints(0) detected(2) = rmData(2).MarkDetectedPoints(0) ' Find center of mass for detected registration marks in the transformed image Dim transformed() As LeadPoint transformed = CoreUtilities.GetRegistrationMarksCenterMass(leadImage, detected) ' Find transformation parameters Dim parameters As TransformationParameters parameters = CoreUtilities.GetTransformationParameters(leadImage, original, transformed) ' Apply transformatin parameters to correct the image Dim applyCommand As ApplyTransformationParametersCommand applyCommand = New ApplyTransformationParametersCommand applyCommand.XTranslation = parameters.XTranslation applyCommand.YTranslation = parameters.YTranslation applyCommand.Angle = parameters.Angle applyCommand.XScale = parameters.XScale applyCommand.YScale = parameters.YScale applyCommand.Flags = ApplyTransformationParametersCommandFlags.Normal applyCommand.Run(tempImage) Catch e As Exception MessageBox.Show(e.Message) End Try End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void ApplyTransformationParametersConstructorExample() { // Load an image RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg")); // Prepare the command RasterImage tempImage = image; try { tempImage = image.Clone(); if (tempImage.HasRegion) tempImage.MakeRegionEmpty(); if (image.HasRegion) image.MakeRegionEmpty(); SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3]; // Mark1 rmData[0] = new SearchRegistrationMarksCommandData(); rmData[0].Rectangle = new LeadRect (680, 20, 941 - 680, 218 - 20); rmData[0].MarkDetectedPoints = new LeadPoint[1]; rmData[0].Width = 31; rmData[0].Height = 29; rmData[0].Type = RegistrationMarkCommandType.TShape; rmData[0].MinimumScale = 90; rmData[0].MaximumScale = 110; rmData[0].SearchMarkCount =1; // Mark2 rmData[1] = new SearchRegistrationMarksCommandData(); rmData[1].Rectangle = new LeadRect(665,790,899-665,961-790); rmData[1].MarkDetectedPoints = new LeadPoint[1]; rmData[1].Width = 31; rmData[1].Height = 29; rmData[1].Type = RegistrationMarkCommandType.TShape; rmData[1].MinimumScale = 90; rmData[1].MaximumScale = 110; rmData[1].SearchMarkCount =1; // Mark3 rmData[2] = new SearchRegistrationMarksCommandData(31, 29, 90, 110, new LeadRect(7,1073,298-7,1246-1073), 1, new LeadPoint[1], RegistrationMarkCommandType.TShape); SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(); command1.SearchMarks = rmData; command1.Run(image); if((rmData[2].MarkDetectedCount != 1) || (rmData[1].MarkDetectedCount != 1) || (rmData[0].MarkDetectedCount != 1)) return; LeadPoint[] original = { new LeadPoint(81400, 11300), new LeadPoint(78600, 87400), new LeadPoint(14300, 115400) }; LeadPoint[] detected = { rmData[0].MarkDetectedPoints[0], rmData[1].MarkDetectedPoints[0], rmData[2].MarkDetectedPoints[0] }; // Find center of mass for detected registration marks in the transformed image LeadPoint[] transformed = CoreUtilities.GetRegistrationMarksCenterMass(image, detected); // Find transformation parameters TransformationParameters parameters = CoreUtilities.GetTransformationParameters(image, original, transformed); // Apply transformatin parameters to correct the image ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(); applyCommand.XTranslation = parameters.XTranslation; applyCommand.YTranslation = parameters.YTranslation; applyCommand.Angle = parameters.Angle; applyCommand.XScale = parameters.XScale; applyCommand.YScale = parameters.YScale; applyCommand.Flags = ApplyTransformationParametersCommandFlags.Normal; applyCommand.Run(tempImage); } catch(Exception exception) { MessageBox.Show(exception.Message); } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
// [TestMethod] // public async Task ApplyTransformationParametersConstructorExample() // { // // Load an image // RasterCodecs codecs = new RasterCodecs(); // codecs.ThrowExceptionsOnInvalidImages = true; // // Load the image // string srcFileName = @"Assets\Image1.cmp"; // StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); // RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); // // Prepare the command // RasterImage tempImage = image; // try // { // tempImage = image.Clone(); // if (tempImage.HasRegion) // tempImage.MakeRegionEmpty(); // if (image.HasRegion) // image.MakeRegionEmpty(); // SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3]; // // Mark1 // rmData[0] = new SearchRegistrationMarksCommandData(); // rmData[0].Rectangle = new LeadRect (680, 20, 941 - 680, 218 - 20); // rmData[0].MarkDetectedPoints = new LeadPoint[1]; // rmData[0].Width = 31; // rmData[0].Height = 29; // rmData[0].Type = RegistrationMarkCommandType.TShape; // rmData[0].MinimumScale = 90; // rmData[0].MaximumScale = 110; // rmData[0].SearchMarkCount =1; // // Mark2 // rmData[1] = new SearchRegistrationMarksCommandData(); // rmData[1].Rectangle = LeadRectHelper.Create(665,790,899-665,961-790); // rmData[1].MarkDetectedPoints = new LeadPoint[1]; // rmData[1].Width = 31; // rmData[1].Height = 29; // rmData[1].Type = RegistrationMarkCommandType.TShape; // rmData[1].MinimumScale = 90; // rmData[1].MaximumScale = 110; // rmData[1].SearchMarkCount =1; // // Mark3 // rmData[2] = new SearchRegistrationMarksCommandData(31, 29, 90, 110, LeadRectHelper.Create(7,1073,298-7,1246-1073), 1, new LeadPoint[1], RegistrationMarkCommandType.TShape); // SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(); // command1.SearchMarks = rmData; // command1.Run(image); // if((rmData[2].MarkDetectedCount != 1) || (rmData[1].MarkDetectedCount != 1) || (rmData[0].MarkDetectedCount != 1)) // return; // LeadPoint[] original = // { // LeadPointHelper.Create(81400, 11300), // LeadPointHelper.Create(78600, 87400), // LeadPointHelper.Create(14300, 115400) // }; // LeadPoint[] detected = // { // rmData[0].MarkDetectedPoints[0], // rmData[1].MarkDetectedPoints[0], // rmData[2].MarkDetectedPoints[0] // }; // // Find center of mass for detected registration marks in the transformed image // LeadPoint[] transformed = CoreUtilities.GetRegistrationMarksCenterMass(image, detected); // // Find transformation parameters // TransformationParameters parameters = CoreUtilities.GetTransformationParameters(image, original, transformed); // // Apply transformatin parameters to correct the image // ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(); // applyCommand.XTranslation = parameters.XTranslation; // applyCommand.YTranslation = parameters.YTranslation; // applyCommand.Angle = parameters.Angle; // applyCommand.XScale = parameters.XScale; // applyCommand.YScale = parameters.YScale; // applyCommand.Flags = ApplyTransformationParametersCommandFlags.Normal; // applyCommand.Run(tempImage); // } // catch(Exception exception) // { // Debug.WriteLine(exception.Message); // } // } //
public void ApplyTransformationParametersConstructorExample(RasterImage image, Stream outStream) { // Prepare the command RasterImage tempImage = image; tempImage = image.Clone(); if (tempImage.HasRegion) tempImage.MakeRegionEmpty(); if (image.HasRegion) image.MakeRegionEmpty(); // Apply transformatin parameters to correct the image ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(); applyCommand.XTranslation = 10; applyCommand.YTranslation = 10; applyCommand.Angle = 500; applyCommand.XScale = 1; applyCommand.YScale = 2; applyCommand.Flags = ApplyTransformationParametersCommandFlags.Normal; applyCommand.Run(tempImage); // Save result image RasterCodecs codecs = new RasterCodecs(); codecs.Save(image, outStream, RasterImageFormat.DicomGray, image.BitsPerPixel); image.Dispose(); }
Public Sub ApplyTransformationParametersConstructorExample(ByVal image As RasterImage, ByVal outStream As Stream)
' Prepare the command
Dim tempImage As RasterImage = image
tempImage = image.Clone()
If tempImage.HasRegion Then
tempImage.MakeRegionEmpty()
End If
If image.HasRegion Then
image.MakeRegionEmpty()
End If
' Apply transformatin parameters to correct the image
Dim applyCommand As ApplyTransformationParametersCommand = New ApplyTransformationParametersCommand()
applyCommand.XTranslation = 10
applyCommand.YTranslation = 10
applyCommand.Angle = 500
applyCommand.XScale = 1
applyCommand.YScale = 2
applyCommand.Flags = ApplyTransformationParametersCommandFlags.Normal
applyCommand.Run(tempImage)
' Save result image
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, outStream, RasterImageFormat.DicomGray, image.BitsPerPixel)
image.Dispose()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2