# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [Root]
#     language: python
#     name: Python [Root]
# ---

# + deletable=true editable=true
# Plot inside the notebook
# %matplotlib inline
# this is used for debugging purposes only. allows to reload classes when changed
# %load_ext autoreload
# %autoreload 2

# + deletable=true editable=true
# Ignore warnings in notebook
import warnings
warnings.filterwarnings('ignore')
# -

# cd ..

# + deletable=true editable=true
# load all the necessary modules for the analysis
from script import *
from skimage import io
import numpy as np

# + deletable=true editable=true
import matplotlib.pyplot as plt

# + deletable=true editable=true
# General parameters of the plot
plt.rcParams['figure.figsize'] = 8,8
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'viridis'
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['ps.fonttype'] = 42

# + deletable=true editable=true
img = io.imread('data/Pos4_Green.tif')
img_red = io.imread('data/Pos4_Red.tif')

# + deletable=true editable=true
#stack = np.stack((img, img_red))

# + deletable=true editable=true
#img_rgb = display.to_rgb(stack, auto = True, bf=False)

# + deletable=true editable=true
#z, _ , _, _ = img_rgb.shape

# + [markdown] deletable=true editable=true
# # Create and plot an overlay image of Red and Green Channels

# + deletable=true editable=true
stack = np.stack((img, img_red))
img_rgb = display.to_rgb(stack, auto = True, bf=False)

# + deletable=true editable=true
frame=10

# + deletable=true editable=true
plt.imshow(img_rgb[frame])
plt.axis("off")
#plt.savefig("frame_{}.png".format(x),bbox_inches='tight' , dpi = 50)

# + [markdown] deletable=true editable=true
# # Cell division event

# + deletable=true editable=true
fig, axes = plt.subplots(2,4, figsize=(16,8))

for i in range(2):
    for j in range(4):
        if i ==0:
            axes[i,j].imshow(img[j,650:950,650:950], cmap = 'gray',interpolation='nearest')
            axes[i,j].axis("off")
            axes[i,j].set_title('plane_{}'.format(j+1))
        else:
            axes[i,j].imshow(img[j+4,650:950,650:950], cmap = 'gray',interpolation='nearest')
            axes[i,j].set_title('plane_{}'.format(j+5))
            axes[i,j].axis("off")
            
#plt.savefig("bii_track/division.png",bbox_inches='tight' , dpi = 300)

# + deletable=true editable=true
nt, y, x = img.shape

# + [markdown] deletable=true editable=true
# ## Flat field correction

# + deletable=true editable=true
img_correct = img_cleaning.flat_field(img)

# + [markdown] deletable=true editable=true
# ## Filtering the noise using non local mean, assuming it's Gaussian

# + [markdown] deletable=true editable=true
# Adjusting nt, you can chose the numbe of frame to analyse

# + deletable=true editable=true
result_denoised = img_cleaning.parallel_denoise(img_correct, nt = nt)

# + [markdown] deletable=true editable=true
# ## Segmentation of cell and parasite

# + deletable=true editable=true
result, fill_segmentation, prop_red, Red_binary_open = segmentation.parallel_segmentation(img, img_red, result_denoised, nt = nt)

# + deletable=true editable=true
from skimage.color import label2rgb

plt.contour(Red_binary_open[frame], colors="white")
plt.imshow(label2rgb(fill_segmentation[frame], bg_label=0))
plt.axis("off")

# + deletable=true editable=true
plt.imshow(img[-1], cmap="gray",interpolation='nearest')
for coor in result:           
            plt.scatter(coor[:,1], coor[:,0], s=100, marker = "x",c='r')
        
plt.axis("off")
#plt.savefig("bii_track/lastframe_track.png",bbox_inches='tight' , dpi = 300)

# + [markdown] deletable=true editable=true
# ## Tracking the cells

# + deletable=true editable=true
list_track = tracking.track_multi(img, result)

# + [markdown] deletable=true editable=true
# ## Visualizing the result

# + deletable=true editable=true
plot_track.browse_track_multi(img, list_track, fill_segmentation)

# + deletable=true editable=true
df = pandas_track.create_pandas_track(list_track)

# + deletable=true editable=true
df.head()

# + deletable=true editable=true
import os
import imageio
import matplotlib.pyplot as plt

def create_GIF():
    
    path = "GIF"
    imageformat=".png"
    imfilelist=[os.path.join(path,f) for f in os.listdir(path) if f.endswith(imageformat)]
    
    images = []
    for filename in imfilelist:
        images.append(imageio.imread(filename))
    kargs = { 'duration': 0.4}
    imageio.mimsave('GIF/movie.gif', images, **kargs)
# -



StarcoderdataJupyterScriptsDedupFiltered