Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- from scipy.ndimage.morphology import binary_dilation
- #from https://stackoverflow.com/questions/41190852/most-efficient-way-to-forward-fill-nan-values-in-numpy-array
- def pandas_fill(arr):
- df = pd.DataFrame(arr)
- df.fillna(method='ffill', axis=0, inplace=True)
- out = df.as_matrix()
- return out
- import os
- directory = 'C:\\Users\\Dj_Mi\\Desktop\\Python\\Test Pictures\\1.12 TGI Exp-6.2-5d F0 SH ST50 AM'
- for filename in os.listdir(directory):
- if filename.endswith(".jpg"):
- f = open(filename)
- im = plt.imread(filename)
- mask = np.any(np.concatenate((im[:, :, 0:1] < 50, im[:, :, 1:2] < 45), axis=2), axis=2)
- mask = binary_dilation(mask, iterations=10)
- im2 = im.copy().astype(np.float)
- im2[mask, :] = np.nan
- for i in range(3):
- im2[:, :, i] = pandas_fill(im2[:, :, i])
- im2 = im2.astype(np.integer)
- f, ax = plt.subplots(1, figsize=(100, 10))
- ax.imshow(im2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement