The code regenerates a black and white image of any image input using Metropolis Hastings algorithm.
- Place the desired input image (
image.png
) in the directory specified in the code:C:\Users\username\Desktop\image.png
. Replaceusername
with your actual username. - Open the
MHA.py
script and run it using Python.
The script will perform the following steps:
- Read the input image.
- Convert the color image to a black and white image.
- Create a matrix representing the normalized probability distribution over the image's pixel positions.
- Use the Metropolis Hastings algorithm to sample from this distribution.
- Generate a histogram-based visualization of the sampled positions.
The resulting plot will display the generated black and white image, representing the normalized probability distribution from the input image.
The script converts a color image to black and white by first converting the color channels to grayscale. Then, it creates a matrix T
representing the normalized probability distribution over the image's pixel positions. The Metropolis Hastings algorithm is employed to sample from this distribution, generating a sequence of pixel positions.
Contributions are welcome! If you find any issues or ways to improve this script, feel free to create a pull request.