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:
The submission format should be a TIFF binary mask. Only L0 level will be used to calculate the DICE.
The TIFF has to be compressed using LZW format.
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).