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

s2p ValueError: Number of columns or rows must be non-negative - with small tile_size (~<2000) #122

Open
Vierod opened this issue Apr 11, 2022 · 3 comments

Comments

@Vierod
Copy link

Vierod commented Apr 11, 2022

Get the following error when attempting to process a relatively large area of Pleiades triples (2x 3):

s2p ValueError: Number of columns or rows must be non-negative

Roots back to rasterio/windows.py validate_length_values.

EDIT - Full output:

Exception in pointing_correction
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/s2p/parallel.py", line 43, in tilewise_wrapper
    out = fun(*args)
  File "/usr/local/lib/python3.7/dist-packages/s2p/__init__.py", line 67, in pointing_correction
    cfg['sift_match_thresh'], cfg['max_pointing_error']
  File "/usr/local/lib/python3.7/dist-packages/s2p/pointing_accuracy.py", line 125, in compute_correction
    method, sift_thresh, epipolar_threshold)
  File "/usr/local/lib/python3.7/dist-packages/s2p/sift.py", line 272, in matches_on_rpc_roi
    p2 = image_keypoints(im2, x2, y2, w2, h2, thresh_dog=thresh_dog)
  File "/usr/local/lib/python3.7/dist-packages/s2p/sift.py", line 112, in image_keypoints
    in_buffer = ds.read(window=rio.windows.Window(x, y, w, h))
  File "<attrs generated init rasterio.windows.Window>", line 8, in __init__
    __attr_validator_width(self, __attr_width, self.width)
  File "/usr/local/lib/python3.7/dist-packages/rasterio/windows.py", line 512, in validate_length_value
    raise ValueError("Number of columns or rows must be non-negative")
ValueError: Number of columns or rows must be non-negative

Happens specifically if I use a lower tile window size, raising the tile size to 2000 fixes it so I'm guessing it might be something to do with empty blocks but unsure. Running fine now but thought I'd raise this, can provide more detail if useful.

Thanks,
Alex

@gfacciol
Copy link
Member

Thanks Alex,
From the stack trace it seems that the sift that is applied on the "corresponding_roi" (line 272), is actually trying to read a tile outside of the image domain that's why rasterio is returning the error

s2p/s2p/sift.py

Lines 261 to 276 in ca589ef

"""
x2, y2, w2, h2 = rpc_utils.corresponding_roi(rpc1, rpc2, x, y, w, h)
# estimate an approximate affine fundamental matrix from the rpcs
rpc_matches = rpc_utils.matches_from_rpc(rpc1, rpc2, x, y, w, h, 5)
F = estimation.affine_fundamental_matrix(rpc_matches)
# if less than 10 matches, lower thresh_dog. An alternative would be ASIFT
thresh_dog = 0.0133
for _ in range(2):
p1 = image_keypoints(im1, x, y, w, h, thresh_dog=thresh_dog)
p2 = image_keypoints(im2, x2, y2, w2, h2, thresh_dog=thresh_dog)
matches = keypoints_match(p1, p2, method, sift_thresh, F,
epipolar_threshold=epipolar_threshold,
model='fundamental')
if matches is not None and matches.ndim == 2 and matches.shape[0] > 10:

We should fix that.

@Vierod
Copy link
Author

Vierod commented Apr 13, 2022

Is there anything I can do to help? I can't share the actual imagery but I could share something of the same dimensions and the RPC info if required. Specifically it's two sets of three images that overlap, one of the sets is just a small corner of the scene, the other three images are much larger covering most of the scene (maybe like 90%+).

@carlodef
Copy link
Member

carlodef commented Apr 18, 2022

Hi @Vierod, this error usually happens when the input ROI is not entirely contained in the reference input image. Could you please share your input config.json and the dimensions of the images?

When the tile size is large enough, all tiles intersect the reference image. But with a smaller tile size, you may have a tile that is completely outside of the reference image, and this is what triggers the error.

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

No branches or pull requests

3 participants