Created
May 10, 2019 16:44
-
-
Save muthuspark/25ebe61b11617f86668655326ea3a82d to your computer and use it in GitHub Desktop.
run length smoothing algorithm - on binary image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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