Crappify resizing Black and White image

Hi Team,

I am trying to crappify black and white images, however, with the current set of crappification code, it gets converted to RGB format and then gives issue while calculating SSIM (color channel mismatch). I tried changing the conversion to black and white by giving “L” and “1” and changing BILINEAR to NEAREST as a parameter in the following piece of code, but it gave me an error which you may find the later screenshot attached.

img = img.resize(targ_sz, resample=PIL.Image.BILINEAR).convert(‘RGB’)

Crappifying code: (gets executed successfully)

Modified Crappifying code for B&W image with the error message:

Kindly suggest how to fix it.


from PIL import Image, ImageDraw, ImageFont

class crappifier(object):

def __init__(self, path_lr, path_hr):
    self.path_lr = path_lr
    self.path_hr = path_hr              

def __call__(self, fn, i):       
    dest = self.path_lr/fn.relative_to(self.path_hr)    
    dest.parent.mkdir(parents=True, exist_ok=True)
    img =
    targ_sz = resize_to(img, 96, use_min=True)
    img = img.resize(targ_sz, resample=PIL.Image.NEAREST).convert('L')
    w,h = img.size
    q = random.randint(10,70)
    ImageDraw.Draw(img).text((random.randint(0,w//2),random.randint(0,h//2)), str(q), fill=(255,255,255)), quality=q)

il = ImageList.from_folder(path_hr)
parallel(crappifier(path_lr, path_hr), il.items)


Traceback (most recent call last):
File “/usr/lib/python3.6/concurrent/futures/”, line 175, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
File “”, line 16, in call
ImageDraw.Draw(img).text((random.randint(0,w//2),random.randint(0,h//2)), str(q), fill=(255,255,255))
File “/usr/local/lib/python3.6/dist-packages/PIL/”, line 337, in text
ink = getink(fill)
File “/usr/local/lib/python3.6/dist-packages/PIL/”, line 300, in getink
ink, fill = self._getink(fill)
File “/usr/local/lib/python3.6/dist-packages/PIL/”, line 113, in _getink
ink = self.draw.draw_ink(ink)
TypeError: function takes exactly 1 argument (3 given)

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
in ()
1 il = ImageList.from_folder(path_hr)
----> 2 parallel(crappifier(path_lr, path_hr), il.items)

2 frames
/usr/local/lib/python3.6/dist-packages/fastai/ in parallel(func, arr, max_workers, leave)
361 results = []
362 for f in progress_bar(concurrent.futures.as_completed(futures), total=len(arr), leave=leave):
–> 363 results.append(f.result())
364 if any([o is not None for o in results]): return results

/usr/lib/python3.6/concurrent/futures/ in result(self, timeout)
423 raise CancelledError()
424 elif self._state == FINISHED:
–> 425 return self.__get_result()
427 self._condition.wait(timeout)

/usr/lib/python3.6/concurrent/futures/ in __get_result(self)
382 def __get_result(self):
383 if self._exception:
–> 384 raise self._exception
385 else:
386 return self._result

TypeError: function takes exactly 1 argument (3 given)