NAME

mrcal-reproject-image - Remaps a captured image into another camera model

SYNOPSIS

### To "undistort" images to reproject to a pinhole projection
$ mrcal-reproject-image --to-pinhole
    camera0.cameramodel
    image*.jpg
Wrote image0-pinhole.jpg
Wrote image1-pinhole.jpg
...

### To reproject images from one lens model to another
$ mrcal-reproject-image
    camera0.cameramodel camera1.cameramodel
    image*.jpg
Wrote image0-reprojected.jpg
Wrote image1-reprojected.jpg
Wrote image2-reprojected.jpg
...

### To reproject two sets of images to a common pihole projection
$ mrcal-reproject-image --to-pinhole
    camera0.cameramodel camera1.cameramodel
    'image*-cam0.jpg' 'image*-cam1.jpg'
Wrote image0-reprojected.jpg
Wrote image1-reprojected.jpg
Wrote image2-reprojected.jpg
...

### To "manually" stereo-rectify a pair of images
$ mrcal-stereo          \
    --az-fov-deg 80     \
    --el-fov-deg 50     \
    --outdir /tmp       \
    left.cameramodel    \
    right.cameramodel
Wrote '/tmp/rectified0.cameramodel'
Wrote '/tmp/rectified1.cameramodel'

$ mrcal-reproject-image         \
    --outdir /tmp               \
    /tmp/left.cameramodel       \
    /tmp/rectified0.cameramodel \
    left.jpg
Wrote /tmp/left-reprojected.jpg

$ mrcal-reproject-image          \
    --outdir /tmp                \
    /tmp/right.cameramodel       \
    /tmp/rectified1.cameramodel  \
    right.jpg
Wrote /tmp/right-reprojected.jpg

$ mrcal-stereo                       \
    --already-rectified              \
    --outdir /tmp                    \
    /tmp/rectified[01].cameramodel   \
    /tmp/left-reprojected.jpg        \
    /tmp/right-reprojected.jpg

# This is the same as using mrcal-stereo to do all the work:
$ mrcal-stereo          \
    --az-fov-deg 80     \
    --el-fov-deg 50     \
    --outdir /tmp       \
    left.cameramodel    \
    right.cameramodel   \
    left.jpg            \
    right.jpg

DESCRIPTION

This tool takes image(s) of a scene captured by one camera model, and produces image(s) of the same scene, as it would appear if captured by a different model, taking into account both the different lens parameters and geometries. This is similar to mrcal-reproject-points, but acts on a full image, rather than a discrete set of points.

There are several modes of operation, depending on how many camera models are given, and whether --to-pinhole is given, and whether --plane-n,--plane-d are given.

To "undistort" (remap to a pinhole projection) a set of images captured using a particular camera model, invoke this tool like this:

mrcal-reproject-image
  --to-pinhole
  model0.cameramodel image*.jpg

Each of the given images will be reprojected, and written to disk as "image....-reprojected.jpg". The pinhole model used for the reprojection will be written to standard output.

To remap images of a scene captured by model0 to images of the same scene captured by model1, do this:

mrcal-reproject-image
  model0.cameramodel model1.cameramodel image*.jpg

Each of the given images will be reprojected, and written to disk as "image....-reprojected.jpg". Nothing will be written to standard output. By default, full relative extrinsics between the two models are used in the reprojection. The unprojection distance (given with --distance) is infinity by default, so only the relative rotation is used by default. To ignore the extrinsics entirely, pass --intrinsics-only.

A common use case is to validate the relative intrinsics and extrinsics in two models. If you have a pair of models and a pair of observed images, you can compute the reprojection, and compare the reprojection-to-model1 to images that were actually captured by model1. If the intrinsics and extrinsics were correct, then the two images would line up exactly for relevant objects (far-away observations with the default --distance, ground plane with --plane-n, etc).

Computing this reprojection map is often very slow. But if the use case is comparing two sets of captured images, the next, much faster invocation method can be used.

To remap images of a scene captured by model0 and images of the same scene captured by model1 to a common pinhole projection, do this:

mrcal-reproject-image
  --to-pinhole
  model0.cameramodel model1.cameramodel 'image*-cam0.jpg' 'image*-cam1.jpg'

A pinhole model is constructed that has the same extrinsics as model1, and both sets of images are reprojected to this model. This is similar to the previous mode, but since we're projecting to a pinhole model, this computes much faster. The generated pinhole model is written to standard output.

Finally instead of reprojecting to match up images of objects at infinity, it is possible to reproject to match up images of arbitrary planes. This can be done by a command like this:

mrcal-reproject-image
  --to-pinhole
  --plane-n 1.1 2.2 3.3
  --plane-d 4.4
  model0.cameramodel model1.cameramodel 'image*-cam0.jpg' 'image*-cam1.jpg'

If the models were already pinhole-projected, this does the same thing as

mrcal-reproject-image
  --plane-n 1.1 2.2 3.3
  --plane-d 4.4
  model0.cameramodel model1.cameramodel 'image*-cam0.jpg'

This maps observations of a given plane in camera0 coordinates to where this plane would be observed in camera1 coordinates. This requires both models to be passed-in. And ALL the intrinsics, extrinsics and the plane representation are used. If all of these are correct, the observations of this plane would line up exactly in the remapped-camera0 image and the camera1 image. The plane is represented in camera0 coordinates by a normal vector given by --plane-n, and the distance to the normal given by plane-d. The plane is all points p such that inner(p,planen) = planed. planen does not need to be normalized. This mode does not require --to-pinhole, but it makes the computations run much faster, as before.

If --to-pinhole, then we generate a pinhole model, that is written to standard output. By default, the focal length of this pinhole model is the same as that of the input model. The "zoom" level of this pinhole model can be adjusted by passing --scale-focal SCALE, or more precisely by passing --fit. --fit takes an argument that is one of

- "corners": make sure all of the corners of the original image remain in-bounds of the pinhole projection

- "centers-horizontal": make sure the extreme left-center and right-center points in the original image remain in-bounds of the pinhole projection

- "centers-vertical": make sure the extreme top-center and bottom-center points in the original image remain in-bounds of the pinhole projection

- A list of pixel coordinates x0,y0,x1,y1,x2,y2,.... The focal-length will be chosen to fit all of the given points

By default, the resolution of the generated pinhole model is the same as the resolution of the input model. This can be adjusted by passing --scale-image. For instance, passing "--scale-image 0.5" will generate a pinhole model and images that are half the size of the input images, in both the width and height.

The output image(s) are written into the same directory as the input image(s), with annotations in the filename. This tool will refuse to overwrite any existing files unless --force is given.

It is often desired to apply transformations to lots of images in bulk. To make this go faster, this tool supports the -j JOBS option. This works just like in Make: the work will be parallelized among JOBS simultaneous processes. Unlike make, the JOBS value must be specified.

OPTIONS

POSITIONAL ARGUMENTS

model-from            Camera model for the FROM image(s). If "-' is given,
                      we read standard input
model-to-and-image-globs
                      Optionally, the camera model for the TO image.
                      Followed, by the from/to image globs. See the mrcal-
                      reproject-image documentation for the details.

OPTIONAL ARGUMENTS

-h, --help            show this help message and exit
--to-pinhole          If given, we reproject the images to a pinhole model
                      that's generated off the MODEL-FROM and --fit,
                      --scale-focal, --scale-image. The generated pinhole
                      model is written to the standard output
--intrinsics-only     If two camera models are given, then by default the
                      full relative transformation is used in the
                      reprojection. If we want to use the intrinsics ONLY,
                      pass this option
--distance DISTANCE   The fundamental operation of this tool is to unproject
                      points from one camera, and to reproject them into the
                      other. The distance used for the unprojection is set
                      by this argument. If omitted, infinity is used; this
                      is equivalent to only using the rotation component of
                      the relative transformation between the cameras. This
                      option only makes sense without --intrinsics-only and
                      without --plane-n/--plane-d
--fit FIT             If we generate a target pinhole model (if --to-pinhole
                      is given) then we can choose the focal length of the
                      target model. This is a "zoom" operation. By default
                      just use whatever value model-from has. Or we scale it
                      by the value given in --scale-focal. Or we use --fit
                      to scale the focal length intelligently. The --fit
                      argument could be one of ("corners", "centers-
                      horizontal", "centers-vertical"), or the argument
                      could be given as a list of points
                      x0,y0,x1,y1,x2,y2,.... The focal length scale would
                      then be chosen to zoom in as far as possible, while
                      fitting all of these points
--scale-focal SCALE_FOCAL
                      If we generate a target pinhole model (if --to-pinhole
                      is given) then we can choose the focal length of the
                      target model. This is a "zoom" operation. By default
                      just use whatever value model-from has. Or we scale it
                      by the value given in --scale-focal. Or we use --fit
                      to scale the focal length intelligently.
--scale-image SCALE_IMAGE
                      If we generate a target pinhole model (if --to-pinhole
                      is given) then we can choose the dimensions of the
                      output image. By default we use the dimensions of
                      model-from. If --scale-image is given, we use this
                      value to scale the imager dimensions of model-from.
                      This parameter changes the RESOLUTION of the output,
                      unlike --scale-focal, which ZOOMS the output
--plane-n PLANE_N PLANE_N PLANE_N
                      We're reprojecting a plane. The normal vector to this
                      plane is given here, in from-camera coordinates. The
                      normal does not need to be normalized; any scaling is
                      compensated in planed. The plane is all points p such
                      that inner(p,planen) = planed
--plane-d PLANE_D     We're reprojecting a plane. The distance-along-the-
                      normal to the plane, in from-camera coordinates is
                      given here. The plane is all points p such that
                      inner(p,planen) = planed
--outdir OUTDIR       Directory to write the output images into. If omitted,
                      we write the output images to the same directory as
                      the input images
--valid-intrinsics-region
                      If given, we annotate the images with the FROM model's
                      valid-intrinsics region
--mask-valid-intrinsics-region
                      If given, we draw everything outside the FROM model's
                      valid-intrinsics region as black. So the unreliable
                      regions aren't even drawn
--force, -f           By default existing files are not overwritten. Pass
                      --force to overwrite them without complaint
--jobs JOBS, -j JOBS  parallelize the processing JOBS-ways. This is like
                      Make, except you're required to explicitly specify a
                      job count.

REPOSITORY

https://www.github.com/dkogan/mrcal

AUTHOR

Dima Kogan, <dima@secretsauce.net>

LICENSE AND COPYRIGHT

Copyright (c) 2017-2021 California Institute of Technology ("Caltech"). U.S. Government sponsorship acknowledged. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0