1

I need to create binary tiff files (normally 9 layered but only layer 0 is important)

I have the results as boolean numpy 2D arrays. But I couldn't write them to tiff format.

Code with PIL:

res = np.zeros((89262, 208796),dtype=bool)
rois = np.load(endfile)
prediction = np.load(pred)

for i in range(prediction.size):
    if(prediction[i]==1):
        y1, x1, y2, x2 = rois[i].astype(int)
        res[y1:y2,x1:x2] =True

im = PIL.Image.fromarray(res,mode='1')

File "/path/to/anaconda3/lib/python3.6/site-packages/PIL/Image.py", line 812, in frombytes s = d.decode(data)

OverflowError: size does not fit in an int

Code with pyvips

res = np.zeros((89262, 208796),dtype=bool)
rois = np.load(endfile)
prediction = np.load(pred)

for i in range(prediction.size):
    if(prediction[i]==1):
        y1, x1, y2, x2 = rois[i].astype(int)
        res[y1:y2,x1:x2] =True

im = pyvips.Image.new_from_array(res)

File "/path/to/anaconda3/lib/python3.6/site-packages/pyvips/vimage.py", line 291, in new_from_array a[x + y * width] = array[y][x]

TypeError: only size-1 arrays can be converted to Python scalars

PS: It is for the Camelyon ACDC LungHP challenge and here is the exact instructions:

  1. The submission format should be a TIFF binary mask. Only L0 level will be used to calculate the DICE.

  2. The TIFF has to be compressed using LZW format.

  3. Participants have to submit a zip file including 50 TIFF masks. Each TIFF filename should be named as num_mask.tiff, where num is the number of the test image (see below).

https://acdc-lunghp.grand-challenge.org

Uğur Dinç
  • 303
  • 3
  • 16
  • For pyvips, you need `new_from_memory`, not `new_from_array`. See https://libvips.github.io/pyvips/intro.html#numpy-and-pil – jcupitt Mar 12 '19 at 04:07
  • Thanks. Does it support lzw format ? I need that too. – Uğur Dinç Mar 12 '19 at 17:18
  • Yes, `image.tiffsave("x.tif", compression="lzw")`, see https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffsave – jcupitt Mar 12 '19 at 20:22

0 Answers0