Skimage Sample From Non-integer Locations In Image?
We can sample from integer positions in an image because images are constructed as 2d arrays, and we just take whatever data is sitting in the array location.
With non-integer positions, like say between two pixels, this is not so straightforward. However, it's such a common problem that (for ex.) GPUs have this functionality baked into the hardware so long as you're satisfied with linear interpolation. I can't find any functionality for this in skimage, but it seems so fundamental to image processing that I feel like I must be missing something.
I would expect something like:
sample(img, (64.5, 120.37), interpolation='linear')
Answer
Scipy has interp2d that can be used successfully for image interpolation.
Let's start with a sample image (random grayscale to keep it simple, colormap comes from matplotlib which I'm using for plotting):
np.random.seed(42)
np.random.randint(255, (10, 10))
Now we can initialize our interpolator
from scipy.interpolate import interp2d
x = np.arange(10)
y = np.arange(10)
f = interp2d(x, y, img, kind="cubic")
and evaluate it on a new grid
xdense = np.linspace(0, 9, 100)
ydense = np.linspace(0, 9, 100)
newimg = f(xdense, ydense)
And you can also use it to sample arbitrary points
f(0.192321, 5.99927371)
Gives
array([99.04826046])
With skimage
you could maybe obtain something similar rescaling and resampling, but this method looks a lot more convenient to me.
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module