←Select platform

GetRegistrationMarksCenterMass Method

Summary
Finds the center of mass for each of the registration marks specified by markPoints. This method is available in the Document/Medical Toolkits.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public static LeadPoint[] GetRegistrationMarksCenterMass( 
   RasterImage image, 
   LeadPoint[] markPoints 
) 
+ (nullable NSArray<NSValue *> * /*LeadPoint*/)getRegistrationMarksCenterMass:(LTRasterImage *)image 
                                                                   markPoints:(nullable NSArray<NSValue *> *)markPoints /*LeadPoint*/ 
                                                                        error:(NSError **)error 
public static LeadPoint[] getRegistrationMarksCenterMass( 
   RasterImage image, 
   LeadPoint[] markPoints 
); 
public: 
static array<LeadPoint>^ GetRegistrationMarksCenterMass(  
   RasterImage^ image, 
   array<LeadPoint>^ markPoints 
)  
def GetRegistrationMarksCenterMass(self,image,] markPoints): 

Parameters

image
RasterImage object that references the transformed image.

markPoints
Array of LeadPoint structures containing mark locations.

Return Value

Array of LeadPoint structures to be filled with points which represent the center of mass for each of the supplied registration marks. The first center of mass point corresponds to the first registration mark in the markPoints array and so on_

Remarks
  • This method is used to determine the center of mass for each supplied registration mark, to be used in detecting image rotation, scaling and translation.
  • The results (that is, the points representing each center of mass) returned by this method are multiplied by 100 in order to obtain more precision (00.00). To get the actual results, divide by 100.
  • This methods uses values that are divided internally by 100.
  • This method can be used in the following manner:
    • Use SearchRegistrationMarksCommand to find the registration marks.
    • Pass data from MarkDetectedPoints to this method to determine the points representing the center of mass for each registration mark.
    • Pass these points to GetTransformationParameters to detect the image rotation, scaling and translation.
  • If you simply want to automatically straighten the image, use the DeskewCommand.
  • This method supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.
  • This method does not support signed data images.

For more information, refer to Detecting Registration Marks.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
 
 
public void GetTransformationParametersExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "RGSRef.cmp")); 
 
   // Prepare the command 
   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(); 
   rmData[2].Rectangle = new LeadRect(7, 1073, 298 - 7, 1246 - 1073); 
   rmData[2].MarkDetectedPoints = new LeadPoint[1]; 
   rmData[2].Width = 31; 
   rmData[2].Height = 29; 
   rmData[2].Type = RegistrationMarkCommandType.TShape; 
   rmData[2].MinimumScale = 90; 
   rmData[2].MaximumScale = 110; 
   rmData[2].SearchMarkCount = 1; 
   SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(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 transformation parameters to correct the image 
   ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(parameters.XTranslation, parameters.YTranslation, parameters.Angle, parameters.XScale, parameters.YScale, 
         ApplyTransformationParametersCommandFlags.Normal); 
   applyCommand.Run(image); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.*; 
 
 
public void getTransformationParametersExample() { 
 
      final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
      // Load an image 
      RasterCodecs codecs = new RasterCodecs(); 
      codecs.setThrowExceptionsOnInvalidImages(true); 
      RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "rgsref.cmp")); 
 
      // Prepare the command 
      SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3]; 
 
      // Mark1 
      rmData[0] = new SearchRegistrationMarksCommandData(); 
      rmData[0].setRectangle(new LeadRect(680, 20, 941 - 680, 218 - 20)); 
      rmData[0].setMarkDetectedPoints(new LeadPoint[1]); 
      rmData[0].setWidth(31); 
      rmData[0].setHeight(29); 
      rmData[0].setType(RegistrationMarkCommandType.T_SHAPE); 
      rmData[0].setMinimumScale(90); 
      rmData[0].setMaximumScale(110); 
      rmData[0].setSearchMarkCount(1); 
 
      // Mark2 
      rmData[1] = new SearchRegistrationMarksCommandData(); 
      rmData[1].setRectangle(new LeadRect(665, 790, 899 - 665, 961 - 790)); 
      rmData[1].setMarkDetectedPoints(new LeadPoint[1]); 
      rmData[1].setWidth(31); 
      rmData[1].setHeight(29); 
      rmData[1].setType(RegistrationMarkCommandType.T_SHAPE); 
      rmData[1].setMinimumScale(90); 
      rmData[1].setMaximumScale(110); 
      rmData[1].setSearchMarkCount(1); 
 
      // Mark3 
      rmData[2] = new SearchRegistrationMarksCommandData(); 
      rmData[2].setRectangle(new LeadRect(7, 1073, 298 - 7, 1246 - 1073)); 
      rmData[2].setMarkDetectedPoints(new LeadPoint[1]); 
      rmData[2].setWidth(31); 
      rmData[2].setHeight(29); 
      rmData[2].setType(RegistrationMarkCommandType.T_SHAPE); 
      rmData[2].setMinimumScale(90); 
      rmData[2].setMaximumScale(110); 
      rmData[2].setSearchMarkCount(1); 
      SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(rmData); 
      command1.run(image); 
 
      if ((rmData[2].getMarkDetectedCount() != 1) || (rmData[1].getMarkDetectedCount() != 1) 
                  || (rmData[0].getMarkDetectedCount() != 1)) 
            return; 
 
      LeadPoint[] original = { 
                  new LeadPoint(81400, 11300), 
                  new LeadPoint(78600, 87400), 
                  new LeadPoint(14300, 115400) 
      }; 
 
      LeadPoint[] detected = { 
                  rmData[0].getMarkDetectedPoints()[0], 
                  rmData[1].getMarkDetectedPoints()[0], 
                  rmData[2].getMarkDetectedPoints()[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 transformation parameters to correct the image 
      ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand( 
                  parameters.getXTranslation(), parameters.getYTranslation(), parameters.getAngle(), 
                  parameters.getXScale(), 
                  parameters.getYScale(), 
                  ApplyTransformationParametersCommandFlags.NORMAL.getValue()); 
      applyCommand.run(image); 
 
      codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 0); 
 
      assertTrue(new File(combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")).exists()); 
      System.out.println("Image successfully ran and saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.Core Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.