Split a large image into many small images to get training data for a CNN


I Googled, but I think I miss the right terms to find what I am looking for:

I want to train a CNN to dedect landforms.
I have a .shp file with the landforms for training and want to:

a: rasterize it
b: split up the large image into many small, overlapping images .

Can someone give me a hint which package I can use to do something like that?

For the shp file you can use GitHub - JuliaGeo/Shapefile.jl: Parsing .shp files in Julia.

To chop images, you should be able to use Images.jl.

using Images
using TestImages

img = testimage("mandrill")

w, h = size(img)

ims = [@view img[iw:iw + 100, ih:ih + 100] 
    for iw in 1:100:w - 100, 
        ih in 1:100:h - 100]

for (i, im) in enumerate(ims)
     save("/tmp/im-$(lpad(i, 3, "0")).png", im)

Obviously you’ll need to add code to specify overlaps, work out how many tiles you can get, allow for remainders, etc.


Thank you so much!!

this helped a lot!!