torch / image

An Image toolbox for Torch.
Other
208 stars 141 forks source link

Fix out-of-boundary bug when lineWidth is big #210

Closed angli-ai closed 7 years ago

angli-ai commented 7 years ago

drawRect throws error when lineWidth>1 and a pixel coordinate of the rectangle is out of the image boundary. e.g., the following code could not succeed

image = require 'image'
bg = torch.ByteTensor(3, 100, 100):fill(3)
img = image.drawRect(bg, 0, 80, 50, 99, {color={255, 0, 255}, lineWidth=5})
image.save('test.png', img)

which throws error:

/scratch0/torch/install/share/lua/5.1/image/init.lua:2172: bad argument #2 to 'drawRect' (out of range at /tmp/luarocks_torch-scm-1-3526/torch7/lib/TH/generic/THTensor.c:759)
stack traceback:
    [C]: at 0x7f9ca8b008e0
    [C]: in function 'drawRect'
    /scratch0/torch/install/share/lua/5.1/image/init.lua:2172: in function 'drawRect'
    /scratch0/image/test.lua:3: in main chunk

After this fix, the same code could generate rectangles on top of the image with ignored pixels on the line and out of the image boundary. test

soumith commented 7 years ago

thanks for correctly figuring out the boundary conditions.