-
Notifications
You must be signed in to change notification settings - Fork 0
Inpainting
If the model's speckle parameters under utils.py haven't been properly defined, It is possible that white dots(image artifacts) have been scattered all over the output image. While the optimal solution would be to define the 'PARAMETERS OF SPECKLE AND NORMALIZATION FACTOR' under utils.py if a different remedy is required, inpainting can be employed.
If the artifacts have rendered the output image unusable due to white dots scattered everywhere, Inpainting can be employed to will in the white spots with the help of contextual information from surrounding pixels. In that case, a 3 step process is followed to arrive at the final inpainted image.
-
Mask generation: In this step, a mask that includes all the white spots, or places where the inpainting algorithm/filter needs to be applied is isolated. This is done by applying 'Fast Fourier Transformation' on the image or FFT, and selecting all but the first 100x100 (low) frequencies. This is then thresholded to get a binary image, which is then dumped as the 'mask' for the image.
-
Dilation of mask: Since the mask generated will be too accurate, and doesn't cover the fringes of the white dots, to improve the image quality, and to cover the fringes of the spots, we dilate the mask to widen it in-order-to to cover the fringes.
-
Inpainting: In this step, we inpaint the masked areas, using any inpainting algorithms, here a basic kernel is used to infer the masked pixel from surrounding pixels.
This file generates the mask files and dilates the mask to help cover the fringes of the artifacts introduced to the image.
- img_dir: Path to the directory with Images whose masks need to be generated. (Default Value: 'output/denoised')
- mask_data: Path to where the generated masks will be dumped. (Default Value: 'output/mask_data')
- (optional) single: Path to where the file to be masked is.
The single parameter is to be used to specify the path to the file that needs to be processed instead of a directory and can be used to generate a mask for a single file.
This file uses the mask generated together with the image to apply an inpainting filter over the artifacts introduced by the model. The resulting images will contain only traces of the artifact, and for the most part, will be free of them.
- img_dir: Path to the directory with Images whose masks need to be generated. (Default Value: 'output/denoised')
- mask_data: Path to where the masks generated by the previous step are located. (Default Value: 'output/mask_data')
- out_dir: Path to where the generated inpainted images will be dumped. (Default Value: '_output/final')
Since inpainting takes up a lot of system resources, this notebook is designed to be run in Google's free Colab. Therefore, to utilize this file fully, upload your relevant Input files to your Google Drive account, before starting this process. After you are ready to proceed,
- Upload this Notebook to Google Colab
- Once you Colab instance is initialized(ensure that you have GPU acceleration[required]), upload inpaint.py to your current colab instance.
- Link your Google Drive to the running colab instance by running the Code cells in the notebook.
- After you have configured the file paths and other configuration parameters, proceed to run the task defined in the cell titles 'Run Task''
Note: Please use the '--debug=1' flag in the 'Run Task' segment, if your instance crashes due to lack of memory or other related issues. Sometimes, the GPU allotted to your instance might not be sufficient to perform this task, in that case, even this flag won't ensure successful execution, in that case, try initializing a new instance after some time.
This batch file and the Bash script, call the 'mask_generator.py' file with the default parameters.
Note: To ensure the proper working of scripts and batch files, ensure that the project structure is maintained, as the scripts and batch files make a lot of assumptions on where the required files are located and tend to use the 'default' values. In this case, it is assumed that the Images to be inpainted are under the 'output/denoised' directory, and the masks are under the 'output/mask_data' directory.