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

add page argument to thumbnail #192

Closed
petoor opened this issue Jun 15, 2020 · 13 comments
Closed

add page argument to thumbnail #192

petoor opened this issue Jun 15, 2020 · 13 comments

Comments

@petoor
Copy link

petoor commented Jun 15, 2020

Hi John.

Following #190
I was wondering if it was possible to add a page argument to image.thumbnail ?
Right now the solution is to use new_from_file(..., page=page) and then use img.thumbnail_image, but as you stated it is not the optimal solution.

Best regards

@petoor petoor changed the title add page argument to image add page argument to thumbnail Jun 15, 2020
@petoor
Copy link
Author

petoor commented Jun 15, 2020

I understand this probably isn't a small change as it would require the thumbnail reader / writer to understand tiffload.

For instance, this image.
tiffload understands it just fine, but thumbnail gives a "tiff2vips: no SUBIFD tag"
2channels_flat.zip

@jcupitt
Copy link
Member

jcupitt commented Jun 15, 2020

Hi @petoor,

You're supposed to do something like:

thumb = pyvips.Image.thumbnail("something.tif[page=12]", 200)

The "no SUBIFD tag" error looks like a bug in libvips master, I'll have a look.

jcupitt added a commit to libvips/libvips that referenced this issue Jun 15, 2020
the recent subifd addition had broken thumbnail of multipage tiffs,
thanks @petoor

see libvips/pyvips#192
@jcupitt
Copy link
Member

jcupitt commented Jun 15, 2020

Yes, the recent addition of bioformats subifd pyramid support had broken multipage tiff thumbnailing. It should work now.

Thanks for reporting this!

@petoor
Copy link
Author

petoor commented Jun 15, 2020

I just tested your fix to libvips, and the subifd tag error is gone.

However, and you can test with the 2channels_flat image, setting the page argument in thumbnail doesnt seem to actually load the page.

def vips2numpy(vi):
    return np.ndarray(buffer=vi.write_to_memory(),
                      dtype=format_to_dtype[vi.format],
                      shape=[vi.height, vi.width, vi.bands])

a = pyvips.Image.thumbnail("2channels_flat.tif[page=0]", 500)
b = pyvips.Image.thumbnail("2channels_flat.tif[page=1]", 500)

print(vips2numpy(a).all() == vips2numpy(b).all())
True

Which should be False

@petoor
Copy link
Author

petoor commented Jun 15, 2020

Sorry, the numpy logic is wrong in that comment. The code should be

a = pyvips.Image.new_from_file("2channels_flat.tif[page=0]")
b = pyvips.Image.new_from_file("2channels_flat.tif[page=1]")

print((vips2numpy(a)==vips2numpy(b)).all())
>>>False

a = pyvips.Image.thumbnail("2channels_flat.tif[page=0]",500)
b = pyvips.Image.thumbnail("2channels_flat.tif[page=1]",500)

print((vips2numpy(a)==vips2numpy(b)).all())
>>>True

@jcupitt
Copy link
Member

jcupitt commented Jun 15, 2020

You're right, many-page TIFF thumbnailing is not working, I'll have another look.

jcupitt added a commit to libvips/libvips that referenced this issue Jun 15, 2020
The addition of subifd handling broke multipage tiff thumbnailing.

See libvips/pyvips#192
@jcupitt
Copy link
Member

jcupitt commented Jun 15, 2020

I think it's fixed. I'll add some more tests.

@petoor
Copy link
Author

petoor commented Jun 15, 2020

If it is pushed to libvips master i can test as well.

@jcupitt
Copy link
Member

jcupitt commented Jun 15, 2020

Yes, it's pushed, and I added some more tests too.

@petoor
Copy link
Author

petoor commented Jun 15, 2020

It seems to work great.
Thanks John.

@jcupitt
Copy link
Member

jcupitt commented Jun 16, 2020

Great! Thank you for testing it, I'll close.

@jcupitt jcupitt closed this as completed Jun 16, 2020
@petoor
Copy link
Author

petoor commented Jun 17, 2020

If the vips-loader is openslideload it doesn't accept the page argument, however if this is by design or not i'm not sure. Iit seems like the other loaders just ignore it if page doesn't make sense for them

@jcupitt
Copy link
Member

jcupitt commented Jun 17, 2020

You must only supply the accepted arguments for all loaders. For example:

$ vipsheader k2.jpg[page=12]
vipsheader: jpegload: no property named `page'

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

No branches or pull requests

2 participants