Skip to content

Commit

Permalink
Merge b45e483 into 6e3af4f
Browse files Browse the repository at this point in the history
  • Loading branch information
ColCarroll committed Feb 8, 2018
2 parents 6e3af4f + b45e483 commit df2c5b1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions imcmc/imcmc.py
Expand Up @@ -105,17 +105,18 @@ def sample_grayscale(image, samples=5000, tune=100, nchains=4, threshold=0.2):
of indices that were sampled, with the variable name 'image'.
"""
# preprocess
image_copy = image.copy()
if threshold != -1:
image[image < threshold] = 0
image[image >= threshold] = 1
image_copy[image < threshold] = 0
image_copy[image >= threshold] = 1

# need an active pixel to start on
active_pixels = np.array(list(zip(*np.where(image == image.max()))))
active_pixels = np.array(list(zip(*np.where(image_copy == image_copy.max()))))
idx = np.random.randint(0, len(active_pixels), nchains)
start = active_pixels[idx]

with pm.Model():
pm.DensityDist('image', ImageLikelihood(image), shape=2)
pm.DensityDist('image', ImageLikelihood(image_copy), shape=2)
trace = pm.sample(samples,
tune=tune,
chains=nchains, step=pm.Metropolis(),
Expand Down

0 comments on commit df2c5b1

Please sign in to comment.