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

creating tiles of 16bit multiband (4 band) tiff image leaves black canvas #466

Open
Rjaat opened this issue May 1, 2024 · 4 comments
Open

Comments

@Rjaat
Copy link

Rjaat commented May 1, 2024

I have a 4 band 16 bit tiff image and trying to create .png tiles of that image using below code:

import pyvips
image_path ="output_rgb_image.tif"
image = pyvips.Image.new_from_file(image_path, access='random')  # 'random' for non-sequential read

image.dzsave(
    "basename",  # Base name for the output files
    # layout='dz',  # Specifies the DeepZoom layout
    suffix=".png",  # Sets the format of the tiles; use '.jpg' for JPEG tiles
    overlap=320,  # The overlap between tiles; adjust as necessary
    tile_size=640  # The size of each tile in pixels
)

in the process, tile gets created but they comes with black canvas.
same approach works fine with 8bit RGB images.

anyone who faced the similar issue, or have any suggestion..... help please!!!
Thanks in advance

@jcupitt
Copy link
Member

jcupitt commented May 1, 2024

Hello @Rjaat, I'd guess your TIFF is not using 0-65535 for black to white. When it's converted to 8-bit PNG, it looks black but isn't.

You'd need to share a sample source image before anyone could say more.

Are you sure you need that huge overlap?

@Rjaat
Copy link
Author

Rjaat commented May 2, 2024

Thanks @jcupitt for your reply.

png tile information:

Width	1280
Height	1280
Data type	UInt16 - Sixteen bit unsigned integer
GDAL Driver Description	PNG

While making chunk of 4 band 16bit images the png tiles also generated in 16bit format which is not being rendered by openseadragon viewer. The same is also true when I have 3 band 16 bit image.

In another scenario where I have 8 bit RGB images everything works fine.

Yes, we need 50% overlap in our scenario

@jcupitt
Copy link
Member

jcupitt commented May 2, 2024

As I said, it seems to work for me. You need to share a sample image so I can try to reproduce your problem.

For example, I can take this sample RGBA image:

biglion

Make a 16-bit, four band TIFF like this:

vips colourspace biglion.png x.tif rgb16

dzsave like this:

vips dzsave x.tif x --suffix .png --tile-size 640 --overlap 320

And I see tiles like this:

$ vipsheader x_files/11/1_1.png 
x_files/11/1_1.png: 1280x1280 ushort, 4 bands, rgb16, pngload

1_1

Which seems correct.

@jcupitt
Copy link
Member

jcupitt commented May 2, 2024

Oh, do you want it to write 8-bit PNG tiles? You need to convert before dzsave, perhaps:

image = pyvips.Image.new_from_file(image_path, access='sequential')

image \
    .colourspace('srgb') \
    .dzsave(
        "basename",  # Base name for the output files
        suffix=".png",  # Sets the format of the tiles; use '.jpg' for JPEG tiles
        overlap=320,  # The overlap between tiles; adjust as necessary
        tile_size=640  # The size of each tile in pixels
    )

Are you sure you need random? I think sequential should work, even with very large overlaps, and will be much faster.

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

2 participants