-
Notifications
You must be signed in to change notification settings - Fork 23
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
[request] Array Interpolation via Stencils #34
Comments
@fosskers That's a great question! Your assumption is correct, it would be fairly easy to implement upsampling (the ballooning up or adding new elements) right now using So the naive and slower way would be to first upsample an array, compute it, and only after that apply interpolation to it. This works only for scaling factors such as 2x, 3x, 4x, etc., but does not for fractional scaling, such as x1.7, for instance. Also it requires an intermediate in-memory representation, which, I am pretty sure, could be avoided. The combination that you bring up of Interpolation via Stencils, I think, is an outstanding idea. I will ponder around on it and try to see what I can come up with. |
Hey @fosskers, hope you are doing well. Just wanted to let you know that in the newest release of massiv-0.2.1 I added I am still pondering on how to do the upsampling in a similarly efficient manner and don't have a solution yet, but do have some good ideas about it. |
Cool! So striding can help us shrink an image by tossing out intermediate pixels. Do we have any access to the ignored pixels during the shrinking process that would allow us to implement some sort of interpolation (i.e. the average colour of all the pixels in the |
That's precisely where downSizeX3 :: (Load r' Ix2 Double, Manifest r' Ix2 Double, Mutable r Ix2 Double) =>
Array r' Ix2 Double -> Array r Ix2 Double
downSizeX3 = computeWithStride (Stride 3) . mapStencil Edge average3x3Filter
average3x3Filter :: Stencil Ix2 Double Double
average3x3Filter = makeStencil (3 :. 3) (1 :. 1) $ \ get ->
( get (-1 :. -1) + get (-1 :. 0) + get (-1 :. 1) +
get ( 0 :. -1) + get ( 0 :. 0) + get ( 0 :. 1) +
get ( 1 :. -1) + get ( 1 :. 0) + get ( 1 :. 1) ) / 9 |
Oh, duh, functional programming. Do one thing and then do the other thing, hahaha. In that case, I can add downsampling to |
In case if you want to scale by two: average2x2Filter :: Stencil Ix2 Double Double
average2x2Filter = makeStencil (2 :. 2) (0 :. 0) $ \ get ->
( get ( 0 :. 0) + get ( 0 :. 1) +
get ( 1 :. 0) + get ( 1 :. 1) ) / 4 After that just use |
I assume that it's currently possible "expand" an image, say from 256x256 -> 512x512 via some manual
traverse
calls and simple interpolation.Both for
mapalgebra
and for implementing a Haskell version of the hqx algorithm, it would be very handy if images could be upsampled/downsampled (I can never remember the difference) using stencils.For instance, hxq wants to know the neighbourhood around each pixel. Based on the "shape" of the surrounding colours, it replaces the current pixel with 4 (a 2x2 grid) new pixels, effectively ballooning the image up by double. Currently, stencil operations assume "read some neighbourhood, write 1 pixel". Is this an unchangeable assumption?
Cheers,
Colin
The text was updated successfully, but these errors were encountered: