5

I would like to recognize if a cell is infected by malaria or not (https://www.kaggle.com/iarunava/cell-images-for-detecting-malaria). But the pictures have different size, so I want to resize every image to the same size to be able to use my first layer (that has a static size)

How can I resize an image in Julia? Or can I just use flux to be able to compute image of different dimension?

logankilpatrick
  • 13,148
  • 7
  • 44
  • 125
Zul Huky
  • 331
  • 4
  • 24
  • 1
    I tried to do this challenge as well and I got good results with knet (but not with flux so far). I posted to code to read this data set in the julia forum in case it is helpful: https://discourse.julialang.org/t/shuffeld-minibatches-of-a-large-datasets/ . I preferred to pad the data to a common size. – Alex338207 Mar 13 '19 at 08:50

1 Answers1

5

You can do this with the packages Images and ImageMagick (you need to install both), and then:

using Images
download("https://juliaimages.org/latest/assets/logo.png","test.png");
img = Images.load("test.png");
size(img) # outputs (128, 128)
img2 = imresize(img,(50,50));
Images.save("test2.png",img2);

The file test2.png has the size 50x50. More info about imsize is available at:

https://juliaimages.org/latest/function_reference.html#Spatial-transformations-and-resizing-1

You would do this operation before hand (i.e. outside of Flux.jl) because otherwise the interpolation would need to be done at every time you compute the gradient.

The package Interpolations would also allow you to resize the images. You would then interpolate the red, green, blue channels individually.

For the particular images of the kaggle challenge, padding the data with black pixels to a common size would also be an option.

Alex338207
  • 1,825
  • 12
  • 16