<jupyter_start><jupyter_text>Notebook use to check the result of the classifier, how well can you detect the nucleus .You can click `shift` + `enter` to run one cell, you can also click run in top menu.To run all the cells, you can click `kernel` and `Restart and run all` in the top menu.<jupyter_code># Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
%reload_ext autoreload
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = 8,8
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
import numpy as np
import javabridge
import bioformats
from itkwidgets import view
from sklearn.externals import joblib
# Ignore warnings in notebook
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>The following path should direct to the folder "utils", on Window env it should have slash " / " and not backslash " \ " .<jupyter_code># Create a temporary python PATH to the module that we are using for the analysis
import sys
sys.path.insert(0, "/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/ChromosomeDetectionChloe/utils")
from chromosome_dsb import *<jupyter_output><empty_output><jupyter_text>Loading a typical image using bioformats<jupyter_code>javabridge.start_vm(class_path=bioformats.JARS)<jupyter_output><empty_output><jupyter_text>In the path variable you should enter the path to your image of interest:<jupyter_code>path = '/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/data_chloe/cku-exo1_002/2017-04-12_RAD51-HTP3_cku80-exo1_002_visit_13_D3D_ALX.dv'<jupyter_output><empty_output><jupyter_text>in the following cell in "channel" enter the the channel (starting from 0) where you will find the nucleus<jupyter_code>img = load_data.load_bioformats(path, channel = 3, no_meta_direct = True)
img.shape
#view(visualization.convert_view(img))<jupyter_output><empty_output><jupyter_text>Sliding Window  First need to load the classifier (clf) and scaler.<jupyter_code>clf = joblib.load("/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/clf_scaler/clf")
scaler = joblib.load("/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/clf_scaler/scaler")
import time
tp1 = time.time()
result = search.rolling_window(img, clf, scaler)
tp2 = time.time()
print("It took {}sec to find the chromosomes in 1 Zstack".format(int(tp2-tp1)))<jupyter_output><empty_output><jupyter_text>Optionally you can create a Heat map with the probability at every pixel that there is a nucleus<jupyter_code>#heat_map = visualization.heatmap(result)
#view(visualization.convert_view(heat_map))<jupyter_output><empty_output><jupyter_text>Max projection and check how the result looks like<jupyter_code>proj = np.amax(img, axis=0)<jupyter_output><empty_output><jupyter_text>When boxes are overlapping, only keep the highest probability one.Here you can adjust `probaThresh` and `overlaThresh`, if you find better parameters, you can change them in the function `batch.batch` in the `chromosome_dsb` folder.<jupyter_code>box = search.non_max_suppression(result, probaThresh=0.8, overlapThresh=0.3)
import matplotlib.patches as patches
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
ax.imshow(proj, vmax = 100000)
for rec in box: 
    rect = patches.Rectangle((rec[0],rec[1]),70,70,linewidth=3,edgecolor='y',facecolor='none')
    # Add the patch to the Axes
    ax.add_patch(rect)
plt.axis('off')
#plt.savefig('/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/data_chloe/fig.png', bbox_inches="tight", pad_inches=0)<jupyter_output><empty_output><jupyter_text>Save the result<jupyter_code>#path = "/Users/Espenel/Desktop/Mini-Grant-Image-analysis/2018/Chloe/13/"
#load_data.save_file(path, "bbox_3D", box, model=False)
#load_data.save_file(path, "bbox_3D", binary, model=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11024414799899321, 'fraction_numerical': 0.02391140196325195, 'mean_word_length': 6.884920634920635, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '2966', 'license': 'MIT', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1367, 'n_words': 329, 'path': 'notebook/Sliding_Window_Chloe.ipynb', 'repo_name': 'Chloe-Girard/Foci_counting', 'size': '3973'}