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

How to crop a region in tiff #500

Open
Fighting-bruceCHN opened this issue Sep 2, 2024 · 5 comments
Open

How to crop a region in tiff #500

Fighting-bruceCHN opened this issue Sep 2, 2024 · 5 comments

Comments

@Fighting-bruceCHN
Copy link

Hi,

I'm using pyvips for image registration on whole slide images (WSI). I have successfully generated both the target and warped source images, both in TIFF format and of the same size (23157 x 47374).

I need to crop the same region from these two TIFF images and save the cropped areas as PNG or JPG files, so I can easily visualize the registration results on a remote server. Could you please guide me on how to accomplish this?

Thank you for your great library.

@jcupitt
Copy link
Member

jcupitt commented Sep 2, 2024

Hello @Fighting-bruceCHN,

Just crop the matching areas, for example:

a = pyvips.Image.new_from_file("file1.tif")
b = pyvips.Image.new_from_file("file2.tif")

tile1 = a.crop(10, 10, 512, 512)
tile2 = b.crop(10, 10, 512, 512)

tile1.write_to_file("tile1.jpg")
tile2.write_to_file("tile2.jpg")

If you write your tiff image in tiled format this will be much faster.

@jcupitt
Copy link
Member

jcupitt commented Sep 2, 2024

Ah do you want users to be able to scroll around the images and compare the alignment?

I would save both images as deepzoom, perhaps with:

a = pyvips.Image.new_from_file("file1.tif")
b = pyvips.Image.new_from_file("file2.tif")

tile1.dzsave("file1")
tile2.dzsave("file2")

Then make a web page with openseadragon that loads both images:

http://openseadragon.github.io/examples/multi-image/

You'll need to add some UI to control the opacity of your two layers. Now users will be able to interactively view the images and check for alignment issues.

@tubp01
Copy link

tubp01 commented Nov 5, 2024

pyvips.error.Error: no such operation dzsave
VipsOperation: class "dzsave" not found

@tubp01
Copy link

tubp01 commented Nov 5, 2024

linux下报这个错

@jcupitt
Copy link
Member

jcupitt commented Nov 5, 2024

Please open a new issue for a new question.

(your libvips has probably been built without libarchive)

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