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

# +
# %%time
# for development, changes in other modules have to be reloaded to reflect changes
# %load_ext autoreload
# %autoreload 1

import pandas as pd 
import numpy as np 
from matplotlib import pyplot as plt 
import seaborn as sbn 
import os, sys
import SimpleITK as sitk

# %aimport config 
sys.path.append(config.lib_dir)
# %aimport utils
# %aimport segment 
# %aimport match 
# %aimport register 
# %aimport evaluate 
# %aimport qc 
sys.path.append(config.script_dir)
from slide_registration import *
# -

# # Overview
#
# The goal of this notebook is to compare the efficacy of the full slide's registrations for a given experiment.
#

# These must be adjusted to your specific experiment
dedusted_path = './dedusted_imgs/'   
unreg_path    = '/mnt/z/Marilyne/Axioscan/6-Dhivya/split/No_Scene/'
slide_name    = 'D1'
scene_name    = 'None'

# +
img_file_names = [x for x in os.listdir(dedusted_path) if x[-4:] == '.tif']
parsed_names = pd.DataFrame([parse_file_name(x) for x in img_file_names])

# filter to slide/scene

# grab only the dapi channel 
parsed_names = parsed_names[lambda x: x.color_channel == 'c1']

parsed_names.head()
# -

imgs_dedust= utils.load_imgs_mt(parsed_names.original.values, dedusted_path)

imgs_unreg = utils.load_imgs_mt(parsed_names.original.values, unreg_path)

# # Testing de-dusting alg

img_names = list(imgs_unreg.keys())
img_names.sort()
for _im in img_names: 
    f, axes = plt.subplots(1,3, figsize=(15,5))
    
    original = imgs_unreg[_im][::10, ::10]
    dedusted = imgs_dedust[_im][::10, ::10]
    
    utils.myshow(original, ax=axes.flat[0], title='original image')
    utils.myshow(dedusted, ax=axes.flat[1], title='dedusted image')
    difference = sitk.Cast(original, sitk.sitkFloat32) - sitk.Cast(dedusted, sitk.sitkFloat32)
    utils.myshow(difference, ax=axes.flat[2], title='difference')

    plt.show()



StarcoderdataJupyterScriptsDedupFiltered