Generate a projection map that describes the mapping between the image plane and a the plane z=0 of a world coordinate system.
gen_image_to_world_plane_map generates a projection map Map, which describes the mapping between the image plane and the plane z=0 (plane of measurements) in a world coordinate system. This map can be used to rectify an image with the operator map_image. The rectified image shows neither radial nor perspective distortions; it corresponds to an image acquired by a distortion-free camera that looks perpendicularly onto the plane of measurements. The world coordinate system is chosen by passing its 3D pose relative to the camera coordinate system in WorldPose. In CamParam you must pass the interior camera parameters (see write_cam_par for the sequence of the parameters and the underlying camera model).
In many cases CamParam and WorldPose are the result of calibrating the camera with the operator camera_calibration. See below for an example.
The size of the images to be mapped can be specified by the parameters WidthIn and HeightIn. The pixel position of the upper left corner of the output image is determined by the origin of the world coordinate system. The size of the output image can be choosen by the parameters WidthMapped, HeightMapped, and Scale. WidthMapped and HeightMapped must be given in pixels.
With the parameter Scale you can specify the size of a pixel in the transformed image. There are two typical scenarios: First, you can scale the image such that pixel coordinates in the transformed image directly correspond to metric units, e.g., that one pixel corresponds to one micron. This is useful if you want to perform measurements in the transformed image which will then directly result in metric results. The second scenario is to scale the image such that its content appears in a size similar to the original image. This is useful, e.g., if you want to perform shape-based matching in the transformed image.
Scale must be specified as the ratio desired pixel size/original unit. A pixel size of 1µm means that a pixel in the transformed image corresponds to the area 1µm x 1µm in the plane of measurements. The original unit is determined by the coordinates of the calibration object. If the original unit is meters (which is the case if you use the standard calibration plate), you can use the parameter values 'm', 'cm', 'mm', 'microns', or 'µm' to directly set the unit of pixel coordinates in the transformed image.
The parameter Interpolation specifies whether bilinear interpolation ('bilinear') should be applied between the pixels in the input image or whether the gray value of the nearest neighboring pixel ('none') should be used.
The mapping function is stored in the output image Map. Map has the same size as the resulting images after the mapping. If no interpolation is chosen, Map consists of one image containing one channel, in which for each pixel of the resulting image the linearized coordinate of the pixel of the input image is stored that is the nearest neighbor to the transformed coordinates. If bilinear interpolation is chosen, Map consists of one image containing five channels. In the first channel for each pixel in the resulting image the linearized coordinates of the pixel in the input image is stored that is in the upper left position relative to the transformed coordinates. The four other channels contain the weights of the four neighboring pixels of the transformed coordinates which are used for the bilinear interpolation, in the following order:
+---+---+ | 2 | 3 | +---+---+ | 4 | 5 | +---+---+The second channel, for example, contains the weights of the pixels that lie to the upper left relative to the transformed coordinates. If several images have to be mapped using the same camera parameters, gen_image_to_world_plane_map in combination with map_image is much more efficient than the operator image_to_world_plane because the mapping function needs to be computed only once.
|
Map (output_object) |
(multichannel-)image -> object : int4 / uint2 |
| Image containing the mapping data. | |
|
CamParam (input_control) |
number-array -> real / integer |
| Interior camera parameters. | |
| Number of elements: (CamParam == 8) || (CamParam == 11) | |
|
WorldPose (input_control) |
pose-array -> real / integer |
| 3D pose of the world coordinate system in camera coordinates. | |
| Number of elements: 7 | |
|
WidthIn (input_control) |
extent.x -> integer |
| Width of the images to be transformed. | |
|
HeightIn (input_control) |
extent.y -> integer |
| Height of the images to be transformed. | |
|
WidthMapped (input_control) |
extent.x -> integer |
| Width of the resulting mapped images in pixels. | |
|
HeightMapped (input_control) |
extent.y -> integer |
| Height of the resulting mapped images in pixels. | |
|
Scale (input_control) |
number -> string / integer / real |
| Scale or unit. | |
| Default value: 'm' | |
| Suggested values: 'm', 'cm', 'mm', 'microns', 'µm', 1.0, 0.01, 0.001, '1.0e-6', 0.0254, 0.3048, 0.9144 | |
|
Interpolation (input_control) |
string -> string |
| Type of interpolation. | |
| Default value: 'bilinear' | |
| List of values: 'none', 'bilinear' | |
* perform camera calibration (with standard calibration plate)
camera_calibration(NX, NY, NZ, NRow, NCol, StartCamParam, NStartPose, 'all',
FinalCamParam, NFinalPose, Errors)
* world coordinate system is defined by calibration plate in first image
FinalPose1 := NFinalPose[0:6]
* compensate thickness of plate
set_origin_pose(FinalPose1, 0, 0, 0.000073, WorldPose)
* goal: rectify images
* first determine parameters such that the entire image content is visible
* -> transform image boundary into world plane, determine smallest
* rectangle around it
get_image_pointer1(Image, Pointer, Type, Width, Height)
gen_rectangle1 (ImageRect, 0, 0, Height-1, Width-1)
gen_contour_region_xld (ImageRect, ImageBorder, 'border')
contour_to_world_plane_xld(ImageBorder, ImageBorderWCS, FinalCamParam,
WorldPose, 1)
smallest_rectangle1_xld (ImageBorderWCS, MinY, MinX, MaxY, MaxX)
* -> move the pose to the upper left corner of the surrounding rectangle
set_origin_pose(WorldPose, MinX, MinY, 0, PoseForEntireImage)
* -> determine the scaling factor such that the center pixel has the same
* size in the original and in the rectified image
* method: transform corner points of the pixel into the world
* coordinate system, compute their distances, and use their
* mean as the scaling factor
image_points_to_world_plane(FinalCamParam, PoseForEntireImage,
[Height/2, Height/2, Height/2+1],
[Width/2, Width/2+1, Width/2],
1, WorldPixelX, WorldPixelY)
distance_pp(WorldPixelY[0], WorldPixelX[0], WorldPixelY[1], WorldPixelX[1],
WorldLength1)
distance_pp(WorldPixelY[0], WorldPixelX[0], WorldPixelY[2], WorldPixelX[2],
WorldLength2)
ScaleForSimilarPixelSize := (WorldLength1+WorldLength2)/2
* -> determine output image size such that entire input image fits into it
ExtentX := MaxX-MinX
ExtentY := MaxY-MinY
WidthRectifiedImage := ExtentX/ScaleForSimilarPixelSize
HeightRectifiedImage := ExtentY/ScaleForSimilarPixelSize
* create mapping with the determined parameters
gen_image_to_world_plane_map(Map, FinalCamParam, PoseForEntireImage,
Width, Height,
WidthRectifiedImage, HeightRectifiedImage,
ScaleForSimilarPixelSize, 'bilinear')
* transform grabbed images with the created map
while(1)
grab_image_async(Image, FGHandle, -1)
map_image(Image, Map, RectifiedImage)
endwhile
gen_image_to_world_plane_map returns 2 (H_MSG_TRUE) if all parameter values are correct. If necessary, an exception handling is raised.
gen_image_to_world_plane_map is reentrant and processed without parallelization.
create_pose, hom_mat3d_to_pose, camera_calibration, hand_eye_calibration, set_origin_pose
map_image, contour_to_world_plane_xld, image_points_to_world_plane
Calibration