Image pooling

question

#1

Is there a package that implements image pooling?

In more detail: I have a big image and need to downsize it. Say my image is of size 1000x1000 and I want to bring it down to 100x100. What I want to do is tile it with 10x10 blocks and replace each block by its median or mean, maximum… This operation is called pooling I think.
More generally I would like to be able to replace each 10x10 block by say a 4x4 block with respect to some function "f : 10x10 -> 4x4"
Is there a package that implements these kinds of operations?


#2

You can low-pass filter the image using https://github.com/JuliaImages/Images.jl/blob/master/README.md
And then subsample it manually.


#3

Related to the question, you may try Images.resize as discussed in this thread:

Code optimization is still under development though.


#4

That has bad performance (also not exactly equivalent, but that does probably not matter in practice). For example applying naively the 10x10 median filter and then subsampling does 100 times more work then necessary.


#5

The package https://github.com/JuliaArrays/TiledIteration.jl probably provides the functionality you want, at least low level support for it, e.g.,

julia> using TiledIteration

julia> A = rand(1000,1000);   # our big array

julia> asmall = map(TileIterator(indices(A), (100,100))) do tileinds
                    median(A[tileinds...])
                end;


julia> Asmall = reshape(asmall,10,10);

julia> Asmall[1,1] == median(A[1:100,1:100])
true

julia> Asmall[end,end] == median(A[901:end,901:end])
true

julia> size(Asmall)
(10, 10)

I have not verified that this actually does exactly what you want, maybe the final array must be permuted somehow.


#6

Looks promising, I will check it out, thanks!


#7

Try restrict, which (should have) good performance while also antialiasing. You can call resize for the final (less-than-a-factor-of-2) resizing.