Poissonfish / GRID

GRID: Deal with Field Segmentations Elegantly
https://poissonfish.github.io/GRID/index.html
GNU General Public License v3.0
32 stars 11 forks source link

Issue with Very Large GeoTIFFs #6

Closed djpetti closed 3 years ago

djpetti commented 3 years ago

Describe the bug I'm working with some really big GeoTIFFs in GRID (>500 MB). I can successfully load the file and define the AOI, but when I try to go to the next step, it crashes:

Traceback (most recent call last):
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gridGUI.py", line 125, in <lambda>
    lambda: self.showKMeaner())
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gridGUI.py", line 141, in showKMeaner
    self.updateMainPn(panel=Panels.KMEANER, isNew=isNew)
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gridGUI.py", line 189, in updateMainPn
    self.pnMain.addWidget(panel.value[1](self.grid))
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gui/kmeaner.py", line 107, in __init__
    self.initUI()
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gui/kmeaner.py", line 225, in initUI
    self.change_k()  # initialize kmeans
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gui/kmeaner.py", line 315, in change_k
    self.auto_cut()
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gui/kmeaner.py", line 328, in auto_cut
    self.binarizeImgGUI()
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gui/kmeaner.py", line 288, in binarizeImgGUI
    self.grid.binarizeImg(
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/grid.py", line 169, in binarizeImg
    self.cropImg()
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/grid.py", line 154, in cropImg
    self.imgs.crop(pts)
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/gimage.py", line 161, in crop
    imgCrop, M = cropImg(self.imgs['raw'], pts)
  File "/home/daniel/grid_venv/lib/python3.8/site-packages/grid/lib.py", line 161, in cropImg
    dst = cv2.warpPerspective(img, H, (shape[0], shape[1]))
cv2.error: OpenCV(4.5.3) /tmp/pip-req-build-f51eratu/opencv/modules/imgproc/src/imgwarp.cpp:1724: error: (-215:Assertion failed) dst.cols < SHRT_MAX && dst.rows < SHRT_MAX && src.cols < SHRT_MAX && src.rows < SHRT_MAX in function 'remap'
Aborted (core dumped)

I think this is an inherent limitation in OpenCV, where it can't warp images in which the row/column count doesn't fit in an int16. However, I was wondering if there was some way around it, maybe, for instance, using rasterio to warp? If not, do you have any recommendations for how to process these files? GRID seems like a great tool, but unfortunately, it's not very useful to us if it can't handle our data.

To Reproduce Steps to reproduce the behavior:

  1. Load a very large TIFF file, one with more than 32767 rows or columns.
  2. Select the AOI
  3. Click "next"

Expected behavior It should go to the next step.

Desktop (please complete the following information):

Poissonfish commented 3 years ago

Thanks for your report and suggestions. You are right about the inherent limitation in OpenCV, and the workaround I proposed was that GRID will now resize the image to less than 32767 rows/columns before proceeding to the next step, using cv.resize().

Please upgrade GRID to 1.2.16 and see if your issue is gone. Thank you.

James

djpetti commented 3 years ago

Thanks, this seems to have fixed the problem.