<jupyter_start><jupyter_text>After a CSV is saved with the information of nuclei and a "Matched" and an "Erase" column, we are ready to open each tile, bring its labels, check for nuclei that have to be erased from the image, do so and save the image into a new tile in the same folder<jupyter_code>import warnings
import numpy as np
import pandas as pd
import IPython.display
import matplotlib.pyplot as plt
import threading
import os.path
from skimage import io
import sys
import sqlite3
from matplotlib.patches import Circle
from notebooklibs import relabel

warnings.filterwarnings('ignore')
#if you have dta as DB write location here
relabel.df_nuclei,relabel.df_voronoi,relabel.df_image,relabel.df_experiment=\
    relabel.loadDBIntoDataFrame("/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/DefaultDB_2.db")
#csv_nuclei="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/1441-exp-febnuclei.csv"
#csv_voronoi="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/1441-exp-febvoronoi.csv"
#csv_image="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/1441-exp-febImage.csv"
#csv_experiment="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/1441-exp-febExperiment.csv"
csv_nuclei_mod="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/relabeled/MyExpt_2_mod2.2.csv"

relabel.df_nuclei_mod=pd.read_csv(csv_nuclei_mod,index_col=0)
#relabel.df_image=pd.read_csv(csv_image)
### This asumes the tiles are named with teh DZI tiling style meaning a tile named 2_3.png has a 
#right neighbor 3_3.png and a bottom neighbor called 3_2.png I need to know the neighbors so if 
#there is no way to know them this notebook cant be ran

#number of tiles along width, or columns
nbcols=33  #it is actually from 0 to 32

#number of tiles along height, or rows
nbrows=22   #it is actually from 0 to 21

#original tile size
origts=1024
origover=100
mygrace=2.2

#to check if an image has number in our experiment db
#relabel.df_image.loc[relabel.df_image[filenamecolumn]=="13_5.png"]
overlap=100
#location of tiles with labels
mainlocation="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/CellProfiler_regions"
experimentname="MyExpt_2"

IPython.display.display(relabel.df_nuclei_mod.iloc[0:5,:])
print (relabel.df_image[relabel.filenamecolumn]=="16_11.png")
print (relabel.df_image.loc[relabel.df_image[relabel.filenamecolumn]=="16_11.png"]["ImageNumber"].values[0])
nucleix=relabel.df_nuclei_mod.loc[(relabel.df_nuclei_mod["ImageNumber"]==158) & (relabel.df_nuclei_mod["Erase"]==True)]
IPython.display.display(nucleix)
print (len(nucleix))
vor_loc=None
nuc_loc="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/CellProfiler_regions/"
savelocation=None
relabel.eraseSelectedLabels(16,11,nuc_loc,vor_loc,savelocation,filetypeorig=".png",filetypelabel=".tiff",nuc_sfx="_regs",save=False,draw=True)
%matplotlib notebook
width=33566#31677    
height=22508#18976

#number of tiles along width, or columns
nbcols=33  #nbcols=30   #it is actually from 0 to 31

#number of tiles along height, or rows
nbrows=22   #nbrows=22 #it is actually from 0 to 21

#original tile size
origts=1024
origover=100

suffix="nuclei"

#nuc_loc="/home/leslie/Documents/Uppsala/cellprofiler/output/labels/"
#vor_loc="/home/leslie/Documents/Uppsala/cellprofiler/output/voronoi/"
#savelocation="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/"

vor_loc=None
nuc_loc="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/CellProfiler_regions/"
savelocation="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/relabeled/"

#eraseSelectedLabels(16,11,nuc_loc,vor_loc,savelocation,save=True,draw=False)
for j in range(nbrows):
    for i in range(nbcols):  
        success=relabel.eraseSelectedLabels(i,j,nuc_loc,vor_loc,savelocation,filetypelabel=".tiff",nuc_sfx="_regs",draw=False,save=True)
        if success==False:
            print (i,j,"gave false results")
    print ("new j", j)<jupyter_output><empty_output><jupyter_text>Make borders and unpad images<jupyter_code>width=33566#31677    
height=22508#18976

#number of tiles along width, or columns
nbcols=33  #nbcols=30   #it is actually from 0 to 31

#number of tiles along height, or rows
nbrows=22   #nbrows=22 #it is actually from 0 to 21

#original tile size
origts=1024
origover=100
suffix="_regs"
mainlocation="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/CellProfiler_regions/"
savelocation="/home/leslie/Documents/Uppsala/cellprofiler/170315_161220_hippo_4_1/cellsegmentations/relabeled/borders/"

relabel.unpadfolder(origts,origover,mainlocation,savelocation,suffix,filetypeorig=".tiff",filetypelabel=".png",debug=False)
findthis="voronoi" #"labels"
suffix="voronoi"
#suffix=""
filetype=".png"
mainlocation="/home/leslie/Documents/Uppsala/cellprofiler/output/"+findthis+"/"
savelocation="/home/leslie/Documents/Uppsala/cellprofiler/output/exp-feb/unpadded/"
#mainlocation="/home/leslie/Documents/Uppsala/understandvips/raw2p5_files/11/"
regionsize=15
path=mainlocation+name
tilesize=1024
overlap=100<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11056137012369172, 'fraction_numerical': 0.0538534728829686, 'mean_word_length': 6.9878419452887535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '142939', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2132, 'n_tokens_neox': 1921, 'n_words': 349, 'path': 'examples/TileEffect2.ipynb', 'repo_name': 'arundasan91/TissUUmaps', 'size': '5255'}