Comments (7)
Hey everyone,
It does make sense to support this.
The implementation would be limited to these few lines:
TODOs:
- add keyword only
padding
argument defaulting toTrue
- calculate padding needed in the two width and height directions with least overhead possible
- emit warning if region is entirely out of bounds, i.e.
read_region((-100, -100), 0, (50, 50))
- add a single call to
np.pad
just between here (Line 404), guarded only if needed: https://github.com/bayer-science-for-a-better-life/tiffslide/blob/56b5bbda36a2792a93b3eabd30c590f004835b41/tiffslide/tiffslide.py#L402-L405- add tests for the specific edge-cases
This is a pretty well defined PR. Anyone up for tackling it? 😃
Cheers, Andreas
I am working on it.
A PR will open later.
from tiffslide.
Amazing, just saw this!
Thanks for the implementation! @ap-- @One-sixth
Wilson
from tiffslide.
Hey there,
Thanks for the bug report! ❤️
I'm a bit hesitant to implement this, but openslide definitely allows you to pad in all directions 🤔 ...
import numpy as np
import openslide
def _is_padding(im):
return np.all(np.array(im) == 0)
slide = openslide.open_slide("some.svs")
slide.level_dimensions
>>> ((63743, 36055), (15935, 9013), (3983, 2253))
# oob positive
_is_padding(slide.read_region((1_000_000, 1_000_0000), 0, (10, 10)))
>>> True
# oob negative
_is_padding(slide.read_region((-1_000_000, -1_000_0000), 0, (10, 10)))
>>> True
# oob higher level than available
_is_padding(slide.read_region((0, 0), 1000, (10, 10)))
>>> True
# oob negative level
_is_padding(slide.read_region((0, 0), -1000, (10, 10)))
>>> True
# empty reads
slide.read_region((0, 0), 0, (0, 0)) # tile width and/or height can be 0
>>> <PIL.Image.Image image mode=RGBA size=0x0 at 0x7F926D19E220>
I think I'd like to default to not allow this (because I think it's a potential source of unwanted bugs). But we could offer a keyword argument and in addition some global setting to be able to allow the exact behavior above. Maybe even allowing to set the padding value.
This should also ship with more compatibility tests for openslide as mentioned in #1.
Would you like to contribute to implementing this functionality in a PR?
I could provide some feedback, or sketch out an initial draft.
Cheers,
Andreas 😃
from tiffslide.
@ap--
I had this problem recently too.
We need to keep the same padding method as openslide.
The coordinate system I use here uses negative numbers and functions that allow to exceed boundaries.
This makes it easy to slice the slide without running into annoying border issues.
In practice, we always do padding to keep the model input size.
Resize will causes abnormal image aspect ratio.
from tiffslide.
Hey everyone,
It does make sense to support this.
The implementation would be limited to these few lines:
https://github.com/bayer-science-for-a-better-life/tiffslide/blob/56b5bbda36a2792a93b3eabd30c590f004835b41/tiffslide/tiffslide.py#L358-L408
TODOs:
- add keyword only
padding
argument defaulting toTrue
- calculate padding needed in the two width and height directions with least overhead possible
- emit warning if region is entirely out of bounds, i.e.
read_region((-100, -100), 0, (50, 50))
- add a single call to
np.pad
just between here (Line 404), guarded only if needed: https://github.com/bayer-science-for-a-better-life/tiffslide/blob/56b5bbda36a2792a93b3eabd30c590f004835b41/tiffslide/tiffslide.py#L402-L405 - add tests for the specific edge-cases
This is a pretty well defined PR. Anyone up for tackling it? 😃
Cheers,
Andreas
from tiffslide.
@ap--
How do you think about filling with any color? Let the parameter padding = (0, 0, 0) .
from tiffslide.
Let's start with padding with 0 only.
We'll think about user provided padding values in a separate issue.
Thank you so much for contributing!
from tiffslide.
Related Issues (20)
- [Bug] Padding is expected. But it is not padding. HOT 1
- CI: cache downloads
- Support for axes=='YX' and uint16 svs files. HOT 5
- Issue with `get_best_level_for_downsample` for NDPI HOT 2
- Compatibility issue with read_region HOT 5
- test_from_kerchunk fails in CI but passes locally? HOT 2
- tiffslide with CLAM HOT 5
- Offer direct-to-gpu decode HOT 1
- round downsamples ?!?
- tiffslide fails to detect svs format and MPP if ImageDescription contains non ascii characters HOT 11
- Refactor leica metadata parsing
- Support for Hamamatsu VMS
- Cannot parse metadata of tiled-tiff images. HOT 4
- Tiffslide much slower than openslide reading patches from SVS with JPEG2000 compression HOT 31
- Dependencies: restrict combinations of versions of dependencies
- tiffslide not reading MPP of CAMELYON16 but openslide does HOT 3
- integration with xarray? HOT 11
- Support icc profile HOT 1
- quickhash implementation
- garbled tiles from CAMELYON16 dataset using tiffslide but not openslide HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiffslide.