samdobson / image_slicer

Split images into tiles. Join the tiles back together.
http://samdobson.github.io/image_slicer
MIT License
151 stars 73 forks source link

slice function: None type not handled for rectangular images #31

Open AkhilJPatil opened 4 years ago

AkhilJPatil commented 4 years ago

Hello Sam,

I have been using the image_slicer.slice() for some time now. Recently the input image dimensions changed and thus the new shape of input images have become rectangular now. Current dimensions of new input images = 8235 10065 pixel (earlier the input images were square shaped with dimension in multiple of 183) Expected output tile dimension = 183 183 So the number of tiles expected = 55 rows * 45 columns

I gave n=2475 (55 45) but the function sliced 2500 tiles of dimension 164201 pixel, which is not the desired result in this case.

Can this (slicing the input images to a given number of tiles as rows and columns) be achieved using the slice function() ? please suggest if its possible.

Best, Akhil

AkhilJPatil commented 4 years ago

Hello again,

I did some digging of the lib code and came across the slice() function definition. def slice(filename, number_tiles=None, col=None, row=None, save=True): which gave the answer to my query. I was not able to find anything related to this provision in the documents. May be the docs could be updated.

However, in the else block, the calculation of variable extra was throwing an error: unsupported operand type(s) for -: 'int' and 'NoneType' for obvious reason. extras = (columns * rows) - number_tiles where number_tiles is None

I could get it working using a ternary operator as below extras = (columns * rows) - 0 if number_tiles is None else number_tiles I would keep this issue open with updated title instead of closing it and creating a new one.

Best, Akhil

cromlyngames commented 4 years ago

I just hit the same error (line 161 main.py) You can delete the '-number_tiles ' bit, that code is only called if number_tiles is not defined with a value.