Image Partition into Blocks

What is the equivalent Julia function of the Wolfram Mathematica ImagePartition function ( ImagePartition—Wolfram Language Documentation )

You could implement one yourself in about one line with comprehensions and views.

Take a look at GitHub - JuliaArrays/TiledIteration.jl: Julia package to facilitate writing mulithreaded, multidimensional, cache-efficient code, which handles N-dimensional arrays (including images).

1 Like

A basic version:

using Images
using TestImages

img = testimage("cameraman")

"""
Partitions an image into an array of subimages
of pixel width w and pixel height h.
"""
function imblocks(img,
                  ( w,  h)::Tuple{Integer,Integer},
                  (dw, dh)::Tuple{Integer,Integer} = (0, 0))
    x = (size(img, 2) - dw) ÷ w
    y = (size(img, 1) - dh) ÷ h
    [view(img, (1:h) .+ (i*h+dh), (1:w) .+ (j*w+dw)) for i=0:y-1, j=0:x-1]
end
"""
Partitions an image into an array of sxs-pixel subimages.
"""
imblocks(img, s::Integer) = imblocks(img, (s, s))

imblocks(img, (128,64))

Padding left as an exercise.