How to randomly change some pixels to black in any image within Pytorch? Also, how to create a U-Net for inpainting?
- You could index the pixel location directly and set the desired pixel value (
0for a black pixel). - GitHub seems to find some repositories for inpainting in PyTorch.
Any examples on how to do it on a regular JPG image?
Assuming your image is a numpy array (or you could transform it to one), this would work:
image_array = np.random.randint(0, 255, (3, 24, 24)).astype(np.uint8)
image_array[:, 17, 23] = 0
Can I use numpy within pytorch?
Yes, you can transform the tensor to a numpy array via tensor.numpy(), but would also be able to index the PyTorch tensor in the same way.
Thanks for the help! It worked.
How would I change a U-Net that segments to a U-Net that inpaints?
Best,
I don’t know the necessary changes and would take a look at some of the linked repositories.