From ab0455b07e931dd6b885675f575f8a32dc69da4b Mon Sep 17 00:00:00 2001 From: Matt Kubilus Date: Sun, 8 Oct 2023 13:56:26 -0400 Subject: [PATCH 1/2] Fix 'duplicate' best chunk tile matches --- autoortho/getortho.py | 7 ++++++- autoortho/test_getortho.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/autoortho/getortho.py b/autoortho/getortho.py index 8ed8bd08..247a852e 100644 --- a/autoortho/getortho.py +++ b/autoortho/getortho.py @@ -799,10 +799,14 @@ def get_best_chunk(self, col, row, mm, zoom): col_offset = col % scalefactor row_offset = row % scalefactor + log.debug(f"Col_Offset: {col_offset}, Row_Offset: {row_offset}, Scale_Factor: {scalefactor}") + # Pixel width w_p = 256 >> diff h_p = 256 >> diff + log.debug(f"Pixel Size: {w_p}x{h_p}") + # Load image to crop img_p = AoImage.load_from_memory(c.data) if not img_p: @@ -812,11 +816,12 @@ def get_best_chunk(self, col, row, mm, zoom): # Crop crop_img = AoImage.new('RGBA', (w_p, h_p), (0,255,0)) - img_p.crop(crop_img, (col_offset, row_offset)) + img_p.crop(crop_img, (col_offset * w_p, row_offset * h_p)) chunk_img = crop_img.scale(scalefactor) return chunk_img + log.debug(f"No best chunk found for {col}x{row}x{zoom}!") return False diff --git a/autoortho/test_getortho.py b/autoortho/test_getortho.py index 7076d05f..8fcac5d8 100644 --- a/autoortho/test_getortho.py +++ b/autoortho/test_getortho.py @@ -338,3 +338,19 @@ def test_get_best_chunk(tmpdir): ret = tile3.get_best_chunk(18408, 26857, 0, 16) assert not ret + +@pytest.mark.parametrize("mm", [4,3,2,1]) +def test_get_best_chunks_all(mm, tmpdir): + tile = getortho.Tile(17408, 25856, 'BI', 16, cache_dir=tmpdir) + + # Verify we get a match + tile.get_img(mm) + + for x in range(16): + for y in range(16): + ret = tile.get_best_chunk(17408+x, 25856+y, 0, 16) + assert(ret) + ret.write_jpg(os.path.join(tmpdir, f"best_{mm}_{x}_{y}.jpg")) + + #assert True == False + From 7ba80e3c6231bd27a7a7fd583244fca1b3d38eb7 Mon Sep 17 00:00:00 2001 From: Matt Kubilus Date: Sun, 8 Oct 2023 14:06:01 -0400 Subject: [PATCH 2/2] Cleanup a bit --- autoortho/getortho.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/autoortho/getortho.py b/autoortho/getortho.py index 247a852e..76072b42 100644 --- a/autoortho/getortho.py +++ b/autoortho/getortho.py @@ -825,29 +825,6 @@ def get_best_chunk(self, col, row, mm, zoom): return False - def _get_best_chunk(self, x, y, mm): - for i in range(mm+1, 5): - if i in self.imgs: - # We have an image already - img = self.imgs[i] - - # Difference between requested mm and found image mm level - mmdiff = i - mm - - mm4_x = x >> mmdiff - mm4_y = y >> mmdiff - scalefactor = 1 << mmdiff - - mm_w = 256 >> mmdiff - mm_h = 256 >> mmdiff - - log.debug(f"GET_IMG: {self} Crop: {mm4_x}x{mm4_y} w:{mm_w} h:{mm_h}") - crop_img = AoImage.new('RGBA', (mm_w, mm_h), (0,255,0)) - img.crop(crop_img, (mm4_x, mm4_y)) - chunk_img = crop_img.scale(scalefactor) - return chunk_img - return False - #@profile @locked def get_mipmap(self, mipmap=0):