Commit 39bc71f427194047a71e30c0f59a149b43e1b742

Authored by Thiago Franco de Moraes
1 parent 8b6aa2c4

FIX: edition when the brush is bigger than the slice

Showing 1 changed file with 9 additions and 4 deletions   Show diff stats
invesalius/data/slice_.py
... ... @@ -419,18 +419,23 @@ class Slice(object):
419 419 xf = image.shape[1]
420 420  
421 421 # Verifying if the points is over the image array.
422   - if (not 0 < xi < image.shape[1] and not 0 < xf < image.shape[1]) or \
423   - (not 0 < yi < image.shape[0] and not 0 < yf < image.shape[0]):
  422 + if (not 0 <= xi <= image.shape[1] and not 0 <= xf <= image.shape[1]) or \
  423 + (not 0 <= yi <= image.shape[0] and not 0 <= yf <= image.shape[0]):
424 424 return
425 425  
  426 +
426 427 roi_m = mask[yi:yf,xi:xf]
427 428 roi_i = image[yi:yf, xi:xf]
428 429  
429 430 if operation == const.BRUSH_THRESH:
430 431 # It's a trick to make points between threshold gets value 254
431 432 # (1 * 253 + 1) and out ones gets value 1 (0 * 253 + 1).
432   - roi_m[index] = (((roi_i[index] >= thresh_min)
433   - & (roi_i[index] <= thresh_max)) * 253) + 1
  433 + try:
  434 + roi_m[index] = (((roi_i[index] >= thresh_min)
  435 + & (roi_i[index] <= thresh_max)) * 253) + 1
  436 + except IndexError:
  437 + # Resolving the problem when roi_i has 0 elements.
  438 + pass
434 439 elif operation == const.BRUSH_DRAW:
435 440 roi_m[index] = 254
436 441 elif operation == const.BRUSH_ERASE:
... ...