Change color to white/grey

Hello all, I have a set of images that I am trying to get rid of the blue and change it to a more translucent white/grey matching that of the background more or less. I want to do this before putting into my module where it will turn all of the lines into dark black marks but I want that do essentially be white without inverting the image. Any ideas? Thanks

Very interesting problem.

I created a quick and dirty python script:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.ndimage.morphology import binary_dilation

def pandas_fill(arr):
    df = pd.DataFrame(arr)
    df.fillna(method='ffill', axis=0, inplace=True)
    out = df.as_matrix()
    return out

im = plt.imread('image.jpg')
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))

The last line will output the image:

In this case the threshold for the line colors are hard coded and the small animals (?) become enlarged when they cross your lines.

If you want to detect/ track the small animals, it is probably easier to detect them with the lines included instead of deleting the lines first.


Hey Eric,
thanks for the quick response. I am curious as to why you believe keeping the lines included might track the flies better? I tried leaving the lines in, and found that any discontinuity in a line can be picked up as a fly/object that I am tracking even when I raise the minimum and lower the maximum thresholds for filtering. In the meantime I will try my luck with your code, much appreciated.

-Michael B.

Also how do I import this python script as a module?