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

when writing tiled tiff, tile size must be multiple of 16 (?) #235

Open
kaczmarj opened this issue Mar 2, 2022 · 2 comments
Open

when writing tiled tiff, tile size must be multiple of 16 (?) #235

kaczmarj opened this issue Mar 2, 2022 · 2 comments

Comments

@kaczmarj
Copy link

kaczmarj commented Mar 2, 2022

hi, thanks for this excellent software! i am using multiresolutionimageinterface to write a tiled tiff image (for the TIGER challenge). i am attempting to write some tiles, but when i apply writer.finishImage(), i get an error that no valid tiles are written. after some debugging, turns out that the writer's tile size needs to be a multiple of 16. i'm wondering if this is indeed the case?

the libtiff docs write that the tile size needs to be a multiple of 8. but using the writer, i could only get multiples of 16 to work (eg tile size of 24 does not work). (excerpt of manpages below)

TIFFTAG_TILELENGTH              1      uint32             must be a multiple of 8
TIFFTAG_TILEWIDTH               1      uint32             must be a multiple of 8

the part of the code that returns the error is below.

if (TIFFIsTiled(_tiff) == 0) {
std::cout << "No valid tiles have been written to the base image, cannot finish image." << std::endl;
return -1;
}

according to that error, the image data is organized in strips instead of tiles (from libtiff manpages).

TIFFIsTiled returns a non-zero value if the image data has a tiled organization. Zero is returned if the image data is organized in strips.

here is an example to reproduce this issue. i am using ubuntu 20.04 with asap 2.0.0 from the github releases of this project.

import multiresolutionimageinterface as mir
import numpy as np

def get_writer(output_path, tile_size, dimensions, spacing):
    writer = mir.MultiResolutionImageWriter()
    writer.openFile(str(output_path))
    writer.setTileSize(tile_size)
    writer.setCompression(mir.LZW)
    writer.setDataType(mir.UChar)
    writer.setInterpolation(mir.NearestNeighbor)
    writer.setColorType(mir.Monochrome)
    writer.writeImageInformation(dimensions[0], dimensions[1])
    pixel_size_vec = mir.vector_double()
    pixel_size_vec.push_back(spacing[0])
    pixel_size_vec.push_back(spacing[1])
    writer.setSpacing(pixel_size_vec)
    return writer

# Works
tile_size = 16
writer = get_writer("/tmp/foo.tif", tile_size=tile_size, dimensions=(4096, 4096), spacing=(0.5, 0.5))
tile = np.zeros((tile_size, tile_size), dtype="uint8")
writer.writeBaseImagePartToLocation(tile.flatten(), x=0, y=0)
writer.finishImage()

# Does not work, even though this is multiple of 8.
tile_size = 24
writer = get_writer("/tmp/foo.tif", tile_size=tile_size, dimensions=(4096, 4096), spacing=(0.5, 0.5))
tile = np.zeros((tile_size, tile_size), dtype="uint8")
writer.writeBaseImagePartToLocation(tile.flatten(), x=0, y=0)
writer.finishImage()
@alessiamarcolini
Copy link

Dear Maintainers, I have the same issue. Can you comment on this?

@464hee
Copy link

464hee commented Nov 18, 2022

Have you solved it? I have encountered similar problems

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