<jupyter_start><jupyter_text>Import image<jupyter_code>img = io.imread('dm4.jpg')
plt.imshow(img)<jupyter_output><empty_output><jupyter_text>Image restorationThese steps are to restore the image to a decent quality before it is fed to the CNN for auto colorisation. Steps are as follows:- Denoising- Edge detection- Edge enhancement- Inpainting  DenoisingRemove the noise in the image using the denoising function for colored images.<jupyter_code>dst = cv.fastNlMeansDenoisingColored(img,None,10,10,6,21)

fig, axes = plt.subplots(ncols = 2, figsize = (10,5))

axes[0].imshow(img)
axes[0].axis('off')

axes[1].imshow(dst)
axes[1].axis('off')<jupyter_output><empty_output><jupyter_text>Edge detectionSometimes old images have cracks or fold lines on them. After removing noise, edge detection should help detect these fold lines that are white and that run all across the image. The edge detection algorithm used here is Canny edge detection.<jupyter_code>edges = cv.Canny(img,200,255)
plt.imshow(edges)<jupyter_output><empty_output><jupyter_text>Edge EnhancementThis step is carried out the enhance any strong edges or cracks present in the image. These enhanced edge lines are further used as guiding points or as a mask for our inpainting function. In order to enhance such folds or cracks in the picture we use opening followed by 2x dilation.<jupyter_code>kernel = np.ones((5,5),np.uint8)
opening = cv.morphologyEx(edges, cv.MORPH_OPEN, kernel)
dilation = cv.dilate(edges,kernel,iterations = 2)
plt.imshow(dilation)<jupyter_output><empty_output><jupyter_text>Inpainting The inpainting function uses a mask where missing areas are highlighted against a dark background. It then 'paints' any mixel pixels with a normalized value of all the surrounding pixels. The inpainting function is fed the mask from the previous image.<jupyter_code>dest = cv.inpaint(dst,dilation,5,cv.INPAINT_TELEA)<jupyter_output><empty_output><jupyter_text>Before vs after<jupyter_code>fig, axes = plt.subplots(ncols = 2, figsize = (10,5))

axes[0].imshow(img)
axes[0].axis('off')

axes[1].imshow(dest)
axes[1].axis('off')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09441052137153594, 'fraction_numerical': 0.016909347111319868, 'mean_word_length': 6.745454545454545, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '168154', 'license': 'MIT', 'n_tokens_mistral': 727, 'n_tokens_neox': 680, 'n_words': 216, 'path': 'src/in_progress/05_08_2020_Image restoration.ipynb', 'repo_name': 'rahulrzende/Restoration-and-colorization-of-grayscale-memories-using-CNNs', 'size': '2129'}