Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muthuspark/25ebe61b11617f86668655326ea3a82d to your computer and use it in GitHub Desktop.
Save muthuspark/25ebe61b11617f86668655326ea3a82d to your computer and use it in GitHub Desktop.
run length smoothing algorithm - on binary image
X = [0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1]
def run_length_smoothing(X, run_length_width):
block = []
for index, intensity in enumerate(X):
if intensity == 1 and len(block) <= run_length_width:
for j in block:
X[j] = 1
block = []
elif intensity == 1 and len(block) > run_length_width:
block = []
elif intensity == 0:
block.append(index)
return X
print(run_length_smoothing(X,3))
#show image
binary_c = np.copy(binary)
for ri in range(binary_c.shape[0]):
binary_c[ri,:] = run_length_smoothing(binary_c[ri,:], 10)
plt.figure(figsize=(20,20))
plt.imshow(binary_c, cmap="gray")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment