Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling the CSM model resolution #421

Open
oleg-alexandrov opened this issue Aug 19, 2022 · 12 comments
Open

Scaling the CSM model resolution #421

oleg-alexandrov opened this issue Aug 19, 2022 · 12 comments

Comments

@oleg-alexandrov
Copy link
Collaborator

I got a suggestion from some folks who are using LRO NAC and who found CSM so much faster than the ISIS camera model. One thing that CSM is lacking is being able to reduce the resolution of the cameras, in a way consistent with the ISIS "reduce" command. Being able to do things at lower-resolution can be quite useful. Note sure what it would take to use a scale factor with CSM. Scale the dimensions, and apply a scale factor each time the input or output are pixels?

@jessemapel
Copy link
Contributor

There's a few obvious approaches here:

  1. Add an optional scale keyword to the ISD
  2. Modify the ISD parameters to "double" the pixel sizes

Either of this would require the image to also be down-sampled. What tools are users using to do this? Applications like reduce are outside of the CSM spec as it doesn't deal with any pixel values.

@steo85it
Copy link

steo85it commented May 29, 2024

Hi! I might be one of those "folks who are using LRO NAC" and indeed I would still be interested in trying this. Are you saying that using reduce and then modifying the json "manually" to adapt the pixel sizes (by changing the image_lines and image_samples values) would not work? That's the approach I meant to test...

@oleg-alexandrov
Copy link
Collaborator Author

It should work. Most of the model, including the bookkeeping for quaternions, positions, velocities, and times, will not change.

When it comes to what to modify, the key parameter in the model state (not in the original ISD which I don't know that well), is m_intTimes, which is the delta time per line width. Likely one need not change m_intTimeStartTimes (first line time), and m_intTimeLines (which I don't know what it does).

Also need to change m_nLines and m_nSamples, obviously.

The definition of model state is in: https://stereopipeline.readthedocs.io/en/latest/examples/csm.html#csm-model-state

ASP's cam_tool can be used for sanity checks as it can shoot rays from an original camera to the ground and back with a second camera.

@oleg-alexandrov
Copy link
Collaborator Author

Also need to change the optical center (m_detectorLineOrigin, m_detectorSampleOrigin).

The CSM model also has some weirdness in places when it comes to half a pixel offset. I am not sure they will have an effect. One can mapproject with original image/camera and modified image/camera and watch for subtle shifts.

@oleg-alexandrov
Copy link
Collaborator Author

Need to change focal length too, I believe, by same amount. (m_focalLength).

@steo85it
Copy link

Oh great, I didn't think about those at all. Thanks for the hints, I'll check this out.

@steo85it
Copy link

steo85it commented Jun 3, 2024

Your suggested "tweaks" seem to work (almost) perfectly, thanks @oleg-alexandrov!
Here below is the summary of a small test I did on LROC NAC image M129050120LE.

Original .cub vs .csm (cam_test result)

Image dimensions: 2532 52224
Number of samples used: 13598

cam1 to cam2 camera direction diff norm
Min:    5.66395e-10
Median: 1.97569e-07
Max:    7.79053e-06

cam1 to cam2 camera center diff (meters)
Min:    4.55051e-08
Median: 3.2549e-05
Max:    0.334139

cam1 to cam2 pixel diff
Min:    2.11018e-05
Median: 0.00969859
Max:    0.390455

cam2 to cam1 pixel diff
Min:    1.35774e-05
Median: 0.00977334
Max:    0.390295

Reduced .cub vs "tweaked" .csm (cam_test result)

Image dimensions: 253 5222
Number of samples used: 159

cam1 to cam2 camera direction diff norm
Min:    3.07541e-06
Median: 1.73445e-05
Max:    0.000145736

cam1 to cam2 camera center diff (meters)
Min:    0.00308957
Median: 2.00129
Max:    4.00384

cam1 to cam2 pixel diff
Min:    0.0132675
Median: 0.306688
Max:    0.817671

cam2 to cam1 pixel diff
Min:    0.0134031
Median: 0.306656
Max:    0.827721

There is still something off (most obviously in --> cam1 to cam2 camera center diff), but ASP.mapproject manages to process the reduced csm camera, and the resulting deformation is relatively small (when compared to the starting point w/o tweaks).

Still, I wonder what is missing to fine-tune the result (if at all possible).
I placed the original and tweaked model_state, along with the mapprojected images at this link.
Thanks for any further suggestions!

@oleg-alexandrov
Copy link
Collaborator Author

oleg-alexandrov commented Jun 4, 2024 via email

@steo85it
Copy link

steo85it commented Jun 4, 2024

I tried to play around with that (and with most other values, a bit blindly ^^), and it seems to impact the cam to cam pixel diffs (multiplying by 100 seemed to work best, reducing the differences by 50%).
Happy to see that a factor = scale_factor**2 would make sense, thanks.

Still, I can't find a parameter that has an impact on the camera center diffs (well, timing does, but usually in a negative way...). Will keep checking.

@oleg-alexandrov
Copy link
Collaborator Author

oleg-alexandrov commented Jun 4, 2024 via email

@steo85it
Copy link

steo85it commented Jun 4, 2024

While what I wrote above is true about the results of ASP.cam_test (comparing the reduced ISIS camera to the tweaked CSM camera), applying the factor (scale_factor**2) to m_opticalDistCoeffs (on top of all other modifications) removed the residual distortion. The new mapprojected image overlaps very well with the original csm camera (mapprojected using the same downsampling factor in the ASP.mapproject call)!

I wonder if the smal offset that I see between csm and isis mapprojected cameras can then be due to the mapprojection rather than to the downsampling of the csm camera?

In any case this looks great, and it's easy to automatize ... thanks for all the suggestions!

@oleg-alexandrov
Copy link
Collaborator Author

oleg-alexandrov commented Jun 4, 2024

Glad there is an improvement.

I wonder if the smal offset that I see between csm and isis mapprojected cameras can then be due to the mapprojection rather than to the downsampling of the csm camera?

Not sure.

Your experiments show that a utility to scale a CM camera would be tricky. Particularly, code will be needed for every supported lens distortion model. For LRO NAC it was actually easy, as there was a single value squared. Other models have polynomials, and each coefficient would need appropriate adjustments, and for some model (radtan) no adjustment would be needed even if there are polynomials because it already applies some internal scaling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants