1 Departamento de Raios Cósmicos e Cronologia, IFGW, University of Campinas
2 Institut für Geologie, TU Bergakademie Freiberg
Copyright (C) 2017 Alexandre Fioravante de Siqueira
This file is part of 'Segmentation of nearly isotropic overlapped
tracks in photomicrographs using successive erosions as watershed
markers - Supplementary Material'.
'Segmentation of nearly isotropic overlapped tracks in photomicrographs
using successive erosions as watershed markers - Supplementary Material'
is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
'Segmentation of nearly isotropic overlapped tracks in photomicrographs
using successive erosions as watershed markers - Supplementary Material'
is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 'Segmentation of nearly isotropic overlapped tracks in
photomicrographs using successive erosions as watershed markers -
Supplementary Material'. If not, see <http://www.gnu.org/licenses/>.
Thank you for downloading these files. Before using this material, please download this file: https://dl.dropboxusercontent.com/u/70640911/afdesiqueira2017_figures.zip. After downloading, please unzip the file and place the contents in the folder containing all Supplementary Code.
The structure of this folder is given at the file STRUCTURE. If you have any issues executing this notebook, please check if all subfolders and files are present.
In [1]:
from itertools import product
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
from scipy.stats import norm
from scipy.ndimage.morphology import binary_fill_holes
from skimage.filters import threshold_isodata
from skimage.io import imread
from skimage.measure import regionprops
from sys import platform
import matplotlib.mlab as mlab
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import statistics as stats
import warnings
desiqueira2017.py; please ensure that you are executing this how-to in the same folder as these functions, or the following command will return an error.
In [2]:
import desiqueira2017 as ds
In [3]:
import supmat_support as sup
In [4]:
default_fontsize = 15
plt.rcParams['font.family'] = 'monospace'
plt.rcParams['font.size'] = 15
plt.rcParams['axes.labelsize'] = plt.rcParams['font.size']
plt.rcParams['axes.titlesize'] = 1.5*plt.rcParams['font.size']
plt.rcParams['legend.fontsize'] = 1.5*plt.rcParams['font.size']
plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
%matplotlib inline
warnings.filterwarnings('ignore')
imread(). Then, we use the function wusem_results(), which presents the ISODATA threshold and WUSEM segmentation results. We obtain also the threshold value and the number of counted tracks.
In [5]:
image = imread('figures/orig_figures/dataset_01/Kr-78_4,5min/K90_incid/K90_incid4,5min_6.bmp', as_grey=True)
num_objects = sup.wusem_results(image, initial_radius=10, delta_radius=2, save_images=False)
print('Threshold: ', threshold_isodata(image))
print('Number of tracks: ', num_objects)
In [6]:
# some helping variables.
samples = ['0', '20', '30', '40', '50', '60', '70', '80', '90']
folders = ['K0_incid', 'K20_incid', 'K30_incid', 'K40_incid', 'K50_incid',
'K60_incid', 'K70_incid', 'K80_incid', 'K90_incid']
# reading input data.
man_count_45 = pd.read_excel('counting/manual_count/manual_dataset01_Kr-78_4,5min_incid.xls')
wusem_count_45 = pd.read_csv('counting/wusem_count/auto_dataset01_Kr-78_4,5min_incid.txt')
man_count_85 = pd.read_excel('counting/manual_count/manual_dataset01_Kr-78_8,5min_incid.xls')
wusem_count_85 = pd.read_csv('counting/wusem_count/auto_dataset01_Kr-78_8,5min_incid.txt')
# separating folders.
manual_45, wusem_45, manual_85, wusem_85 = [{} for _ in range(4)]
for idx, folder in enumerate(folders):
manual_45[samples[idx]] = man_count_45[man_count_45['folder'] == folder]
wusem_45[samples[idx]] = wusem_count_45[wusem_count_45['folder'] == folder]
manual_85[samples[idx]] = man_count_85[man_count_85['folder'] == folder]
wusem_85[samples[idx]] = wusem_count_85[wusem_count_85['folder'] == folder]
initial_radius and delta_radius, and plot the results.
In [7]:
# helping plot variables.
x_ticks = ['5', '10', '15', '20', '25', '30', '35', '40']
y_ticks = ['2', '4', '6', '8', '10', '12', '14', '16', '18', '20']
# separating a test image.
autotest_45 = wusem_count_45[(wusem_count_45['folder'] == 'K90_incid') &
(wusem_count_45['image'] == 1)]
autotest_85 = wusem_count_85[(wusem_count_85['folder'] == 'K90_incid') &
(wusem_count_85['image'] == 1)]
# initial_radius starts in 5, ends in 40 and has delta_radius 5.
# delta_radius starts in 2, ends in 20 and has delta_radius 2.
# first, we create matrices to accomodate the countings.
XX, YY = np.mgrid[5:41:5, 2:21:2]
ZZtest_auto45, ZZtest_auto85 = [np.zeros(XX.shape) for _ in range(2)]
for i, j in product(range(5, 41, 5), range(2, 21, 2)):
aux = int(autotest_45.auto_count[(wusem_count_45.initial_radius == i) &
(wusem_count_45.delta_radius == j)])
ZZtest_auto45[(XX == i) & (YY == j)] = aux
aux = int(autotest_85.auto_count[(wusem_count_85.initial_radius == i) &
(wusem_count_85.delta_radius == j)])
ZZtest_auto85[(XX == i) & (YY == j)] = aux
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(20, 10))
image = axes[0].contour(ZZtest_auto45.T, colors='w')
axes[0].clabel(image, fmt='%i', fontsize=default_fontsize)
image = axes[0].contourf(ZZtest_auto45.T, cmap='magma')
axes[0].set_title('Automatic counting: 4,5 min')
image = axes[1].contour(ZZtest_auto85.T, colors='w')
axes[1].clabel(image, fmt='%i', fontsize=default_fontsize)
image = axes[1].contourf(ZZtest_auto85.T, cmap='magma')
axes[1].set_title('Automatic counting: 8,5 min')
for ax in axes.ravel():
ax.set_xlabel('initial_radius')
ax.set_ylabel('delta_radius')
ax.set_xticklabels(x_ticks)
ax.set_yticklabels(y_ticks)
fig.colorbar(image, ax=axes.ravel().tolist(), orientation='vertical')
Out[7]:
In [8]:
# calculating the means for manual counting, and obtaining the candidates for initial_radius and delta_radius.
mean_tol = 2 # defining tolerance
meanman_45, meanman_85 = [{} for _ in range(2)]
cand_wusem_45, cand_wusem_85 = [{} for _ in range(2)]
for key, val in manual_45.items():
# candidates for 4,5 min.
meanman_45[key] = val.manual_count.mean()
cand_wusem_45[key] = ds.comp_wusem_counting(meanman_45[key],
wusem_45[key],
tolerance=mean_tol)
for key, val in manual_85.items():
# candidates for 8,5 min.
meanman_85[key] = val.manual_count.mean()
cand_wusem_85[key] = ds.comp_wusem_counting(meanman_85[key],
wusem_85[key],
tolerance=mean_tol)
initial_radius, delta_radius candidates in order, and for how many samples it was inside the tolerance interval: the first candidate is the best for that sample.
In [9]:
print('* Means for manual counting (4.5 min):\n', meanman_45)
for cand in ds.sorting_candidates(ds.joining_candidates(cand_wusem_45)):
print('Candidate: ', cand[0], ', Samples: ', cand[1])
print('\n')
print('* Means for manual counting (8.5 min):\n', meanman_85)
for cand in ds.sorting_candidates(ds.joining_candidates(cand_wusem_85)):
print('Candidate: ', cand[0], ', Samples: ', cand[1])
print('\n')
In [10]:
# supporting variables.
man_color = '#386cb0'
wusem_color = '#fdc086'
plot_where = {'0': 10, '20': 20, '30': 30, '40': 40, '50': 50,
'60': 60, '70': 70, '80': 80, '90': 90}
x_ticks = [10, 20, 30, 40, 50, 60, 70, 80, 90]
x_labels = ['K0', 'K20', 'K30', 'K40', 'K50', 'K60', 'K70', 'K80', 'K90']
# the actual plots.
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 15))
for key, val in meanman_45.items():
axes[0].errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
axes[0].annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
axes[0].set_title('4,5 min samples')
for key, val in meanman_85.items():
axes[1].errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
axes[1].annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
axes[1].set_title('8,5 min samples')
for i, j in product(range(5, 41, 5), range(2, 21, 2)):
for key, val in wusem_45.items():
aux_wb = val.auto_count[(val.initial_radius == i) & (val.delta_radius == j)].mean()
if 0 < (meanman_45[key] - aux_wb) < mean_tol:
axes[0].scatter(plot_where[key], aux_wb, color=wusem_color)
else:
axes[0].scatter(plot_where[key], aux_wb, color='k', alpha=0.1)
for key, val in wusem_85.items():
aux_wb = val.auto_count[(val.initial_radius == i) & (val.delta_radius == j)].mean()
if 0 < (meanman_85[key] - aux_wb) < mean_tol:
axes[1].scatter(plot_where[key], aux_wb, color=wusem_color)
else:
axes[1].scatter(plot_where[key], aux_wb, color='k', alpha=0.1)
for ax in axes.ravel():
ax.set_xticks(x_ticks)
ax.set_xticklabels(x_labels)
ax.set_xlim([5, 100])
ax.set_ylim([-1, 40])
In [11]:
bestarg_45 = (10, 20)
bestarg_85 = (10, 14)
In [12]:
# 4.5 minutes:
wusem_best_45 = {}
for key, val in wusem_45.items():
wusem_best_45[key] = val[(val['initial_radius'] == bestarg_45[0]) &
(val['delta_radius'] == bestarg_45[1])]
ratio = ds.ratio_manauto(manual_45, wusem_best_45)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [13]:
# 8.5 minutes:
wusem_best_85 = {}
for key, val in wusem_85.items():
wusem_best_85[key] = val[(val['initial_radius'] == bestarg_85[0]) &
(val['delta_radius'] == bestarg_85[1])]
ratio = ds.ratio_manauto(manual_85, wusem_best_85)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [14]:
# 4.5 min.
# supporting variables
plot_where = {'0': 0, '20': 1, '30': 2, '40': 3, '50': 4,
'60': 5, '70': 6, '80': 7, '90': 8}
plot_colors = {'0': '#440154', '20': '#472d7b', '30': '#3b528b',
'40': '#2c728e', '50': '#21918c', '60': '#28ae80',
'70': '#5ec962', '80': '#addc30', '90': '#fde725'}
# the actual plots.
for key, val in manual_45.items():
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))
sup.plot_auxiliar_dataset1(var_manual=val.manual_count,
var_auto=wusem_best_45[key].auto_count,
auto_color=plot_colors[key],
ax=ax[0])
sup.plot_linreg_dataset1(var_manual=val.manual_count,
var_auto=wusem_best_45[key].auto_count,
color=plot_colors[key],
ax=ax[1])
ax[1].axis([0, 45, 0, 45])
In [15]:
# 8.5 min.
# supporting variables
plot_where = {'0': 0, '20': 1, '30': 2, '40': 3, '50': 4,
'60': 5, '70': 6, '80': 7, '90': 8}
plot_colors = {'0': '#440154', '20': '#472d7b', '30': '#3b528b',
'40': '#2c728e', '50': '#21918c', '60': '#28ae80',
'70': '#5ec962', '80': '#addc30', '90': '#fde725'}
# the actual plots.
for key, val in manual_85.items():
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))
sup.plot_auxiliar_dataset1(var_manual=val.manual_count,
var_auto=wusem_best_85[key].auto_count,
auto_color=plot_colors[key],
ax=ax[0])
sup.plot_linreg_dataset1(var_manual=val.manual_count,
var_auto=wusem_best_85[key].auto_count,
color=plot_colors[key],
ax=ax[1])
ax[1].axis([0, 45, 0, 45])
In [16]:
# comparing manual/auto mean and std
print('* Manual, dataset 01, 4.5 min')
for key, val in manual_45.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* Auto, dataset 01, 4.5 min')
for key, val in wusem_best_45.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
print('* Manual, dataset 01, 8.5 min')
for key, val in manual_85.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* Auto, dataset 01, 8.5 min')
for key, val in wusem_best_85.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [17]:
man_count = pd.read_excel('counting/manual_count/manual_dataset01_Kr-78_4,5min_incid.xls')
wusem_count = pd.read_csv('counting/wusem_count/auto_dataset01_Kr-78_4,5min_incid.txt')
manual, wusem, wusem_best = [{} for _ in range(3)]
for idx, folder in enumerate(folders):
manual[samples[idx]] = man_count[man_count['folder'] == folder]
wusem[samples[idx]] = wusem_count[wusem_count['folder'] == folder]
for key, val in wusem.items():
# best candidate.
wusem_best[key] = val[(val['initial_radius'] == bestarg_45[0]) &
(val['delta_radius'] == bestarg_45[1])]
round_regions() with the best arguments.
In [18]:
image = imread('figures/orig_figures/dataset_01/Kr-78_4,5min/K90_incid/K90_incid4,5min_3.bmp',
as_grey=True)
labels, objects, info_reg = ds.round_regions(image,
initial_radius=bestarg_45[0],
delta_radius=bestarg_45[1],
toler_ecc=0.3)
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(15, 10))
ax[0].imshow(image, cmap='gray')
ax[1].imshow(labels, cmap='nipy_spectral')
ax[2].imshow(objects, cmap='magma')
plt.show()
properties = regionprops(labels, intensity_image=image)
In [19]:
# sample_set = ['Kr-78_4,5min', 'Kr-78_8,5min']
# ds.all_round_regions(sample_set, initial_radius=5, delta_radius=4, eccentricity=0.3)
In [20]:
incid_energy = {'0': 865, '20': 701, '30': 613, '40': 520, '50': 422,
'60': 320, '70': 213, '80': 105, '90': 18}
In [ ]:
In [21]:
wuseminfo_45 = pd.read_csv('counting/wusem_count/roundinfo_dataset01_Kr-78_4,5min.txt')
wuseminfo_85 = pd.read_csv('counting/wusem_count/roundinfo_dataset01_Kr-78_8,5min.txt')
wusem_45, wusem_85 = [{} for _ in range(2)]
for idx, folder in enumerate(folders):
wusem_45[samples[idx]] = wuseminfo_45[wuseminfo_45['folder'] == folder]
wusem_85[samples[idx]] = wuseminfo_85[wuseminfo_85['folder'] == folder]
In [ ]:
In [ ]:
In [22]:
rows, cols = 3, 3
which_to_plot = {'[0, 0]': '0', '[0, 1]': '20', '[0, 2]': '30',
'[1, 0]': '40', '[1, 1]': '50', '[1, 2]': '60',
'[2, 0]': '70', '[2, 1]': '80', '[2, 2]': '90'}
In [23]:
data_45, data_85 = [{} for _ in range(2)]
plot_colors = ['#1b9e77', '#d95f02']
border = []
for color in plot_colors:
border.append(mpatches.Patch(color=color))
for idx, folder in enumerate(folders):
data_45[samples[idx]] = wuseminfo_45[wuseminfo_45['folder'] == folder]
data_85[samples[idx]] = wuseminfo_85[wuseminfo_85['folder'] == folder]
data_wusem45 = [data_45]
data_wusem85 = [data_85]
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(20, 20))
for idx, data in enumerate(data_wusem45):
for key, val in data.items():
axes[0, 0].scatter(incid_energy[key],
ds.px_to_um2(val['minor_axis'].mean(),
val['major_axis'].mean()),
marker='o', color=plot_colors[idx])
axes[0, 0].errorbar(incid_energy[key],
ds.px_to_um2(val['minor_axis'].mean(),
val['major_axis'].mean()),
yerr=ds.px_to_um2(val['minor_axis'].std(),
val['major_axis'].std()),
marker='o', color=plot_colors[idx])
axes[0, 0].set_ylabel('Mean diameter product ($\mu m^2$)')
axes[0, 1].scatter(incid_energy[key], val['mean_gray'].mean(),
marker='X', color=plot_colors[idx])
axes[0, 1].errorbar(incid_energy[key], val['mean_gray'].mean(),
yerr=val['mean_gray'].std(), marker='o',
color=plot_colors[idx])
axes[0, 1].set_ylabel('Mean gray levels')
for idx, data in enumerate(data_wusem85):
for key, val in data.items():
axes[1, 0].scatter(incid_energy[key],
ds.px_to_um2(val['minor_axis'].mean(),
val['major_axis'].mean()),
marker='o', color=plot_colors[idx])
axes[1, 0].errorbar(incid_energy[key],
ds.px_to_um2(val['minor_axis'].mean(),
val['major_axis'].mean()),
yerr=ds.px_to_um2(val['minor_axis'].std(),
val['major_axis'].std()),
marker='o', color=plot_colors[idx])
axes[1, 0].set_ylabel('Mean diameter product ($\mu m^2$)')
axes[1, 1].scatter(incid_energy[key], val['mean_gray'].mean(),
marker='X', color=plot_colors[idx])
axes[1, 1].errorbar(incid_energy[key], val['mean_gray'].mean(),
yerr=val['mean_gray'].std(), marker='o',
color=plot_colors[idx])
axes[1, 1].set_ylabel('Mean gray levels')
for ax in axes.ravel():
ax.set_xlim([-100, 1000])
ax.set_xlabel('Kr$^{78}$ energy (MeV)')
ax.invert_xaxis()
In [ ]:
In [24]:
image = imread('figures/orig_figures/dataset_02/FT-Lab_19.07.384.MAG1.jpg', as_grey=True)
num_objects = sup.wusem_results(image,
initial_radius=10,
delta_radius=2,
save_images=False)
print('Number of tracks: ', num_objects)
In [25]:
mancount_dap = pd.read_excel('counting/manual_count/manual_dataset02.xls')
manual = {'MAG1': mancount_dap.query('image <= 9'),
'MAG2': mancount_dap.query('image > 9')}
wusem_count_dap = pd.read_csv('counting/wusem_count/auto_dataset02.txt')
wusem = {'MAG1': wusem_count_dap.query('image <= 9'),
'MAG2': wusem_count_dap.query('image > 9')}
In [26]:
# separating a test image.
wusem_daptest = wusem['MAG1'][wusem['MAG1']['image'] == 5]
In [27]:
# initial_radius starts in 5, ends in 40 and has delta_radius 5.
# delta_radius starts in 2, ends in 20 and has delta_radius 2.
# let's create matrices to accomodate the countings.
XX, YY = np.mgrid[5:41:5, 2:21:2]
ZZ_k0 = np.zeros(XX.shape)
for i, j in product(range(5, 41, 5), range(2, 21, 2)):
aux = int(wusem_daptest.auto_count[(wusem_count_dap.initial_radius == i) & (wusem_count_dap.delta_radius == j)])
ZZ_k0[(XX == i) & (YY == j)] = aux
In [28]:
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12, 10))
image = ax.contour(ZZ_k0.T, colors='w')
ax.clabel(image, fmt='%i', fontsize=12)
image = ax.contourf(ZZ_k0.T, cmap='magma')
ax.set_xlabel('initial_radius')
ax.set_ylabel('delta_radius')
ax.set_xticklabels(('5', '10', '15', '20', '25', '30', '35', '40'))
ax.set_yticklabels(('2', '4', '6', '8', '10', '12', '14', '16', '18', '20'))
# fig.colorbar(image, ax=ax.tolist(), orientation='horizontal')
fig.colorbar(image, orientation='horizontal')
Out[28]:
In [29]:
# calculating the means for manual counting, and obtaining the candidates for initial_radius and delta_radius.
mean_tol = 5 # defining tolerance
meanman_dap, wusem_dap = [{} for _ in range(2)]
for key, val in manual.items():
meanman_dap[key] = val.manual_count.mean()
wusem_dap[key] = ds.comp_wusem_counting(meanman_dap[key],
wusem[key],
tolerance=mean_tol)
In [30]:
print('Means for manual counting: ', meanman_dap, '\nBest candidates: ', wusem_dap)
In [31]:
man_color = '#386cb0'
auto_color = '#fdc086'
plot_where = {'MAG1': 10, 'MAG2': 20}
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(15, 10))
for key, val in meanman_dap.items():
ax.errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
ax.annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
for i, j in product(range(5, 41, 5), range(2, 21, 2)):
for key, val in wusem.items():
aux = val.auto_count[(val.initial_radius == i) & (val.delta_radius == j)].mean()
if 0 < (meanman_dap[key] - aux) < mean_tol:
ax.scatter(plot_where[key], aux, color=auto_color)
else:
ax.scatter(plot_where[key], aux, color='k', alpha=0.1)
ticks = [10, 20]
ax.set_xticklabels(('Magnification 1', 'Magnification 2'))
ax.set_xticks(ticks)
ax.set_xlim([5, 25])
Out[31]:
In [32]:
wusem_best_mag1 = wusem['MAG1'][(wusem['MAG1']['initial_radius'] == 5) & (wusem['MAG1']['delta_radius'] == 12)]
wusem_best_mag2 = wusem['MAG2'][(wusem['MAG2']['initial_radius'] == 10) & (wusem['MAG2']['delta_radius'] == 14)]
wusem_best = {'MAG1': wusem_best_mag1, 'MAG2': wusem_best_mag2}
ratio = ds.ratio_manauto(manual, wusem_best, sample='dataset02')
for rt in ratio:
print(rt)
In [33]:
plot_where = {'MAG1': 10, 'MAG2': 20}
plot_colors = {'MAG1': '#472d7b', 'MAG2': '#addc30'}
for key, val in manual.items():
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))
sup.plot_auxiliar_dataset2(var_manual=manual[key].manual_count,
var_auto=wusem_best[key].auto_count,
auto_color=plot_colors[key],
ax=ax[0])
sup.plot_linreg_dataset2(var_manual=manual[key].manual_count,
var_auto=wusem_best[key].auto_count,
color=plot_colors[key],
ax=ax[1])
In [34]:
print('Manual, dataset 02')
for key, val in manual.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('Auto, dataset 02')
for key, val in wusem_best.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [35]:
samples = ['0', '20', '30', '40', '50', '60', '70', '80', '90']
folders = ['K0_incid', 'K20_incid', 'K30_incid', 'K40_incid', 'K50_incid',
'K60_incid', 'K70_incid', 'K80_incid', 'K90_incid']
In [36]:
# dataset 01
manual_45, manual_85 = [{} for _ in range(2)]
man_count_45 = pd.read_excel('counting/manual_count/manual_dataset01_Kr-78_4,5min_incid.xls')
man_count_85 = pd.read_excel('counting/manual_count/manual_dataset01_Kr-78_8,5min_incid.xls')
# separating folders.
for idx, folder in enumerate(folders):
manual_45[samples[idx]] = man_count_45[man_count_45['folder'] == folder]
manual_85[samples[idx]] = man_count_85[man_count_85['folder'] == folder]
# dataset 02
mancount_dap = pd.read_excel('counting/manual_count/manual_dataset02.xls')
manual = {'MAG1': mancount_dap.query('image <= 9'),
'MAG2': mancount_dap.query('image > 9')}
In [37]:
# reading input data.
water_count_45 = pd.read_csv('counting/water_count/water_dataset01_Kr-78_4,5min_incid.txt')
water_count_85 = pd.read_csv('counting/water_count/water_dataset01_Kr-78_8,5min_incid.txt')
# separating folders.
water_45, water_85 = [{} for _ in range(2)]
for idx, folder in enumerate(folders):
water_45[samples[idx]] = water_count_45[water_count_45['folder'] == folder]
water_85[samples[idx]] = water_count_85[water_count_85['folder'] == folder]
In [ ]:
In [53]:
# comparing manual/auto mean and std
print('* Manual, dataset 01, 4.5 min')
for key, val in manual_45.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* Classic watershed, dataset 01, 4.5 min')
for key, val in water_45.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
print('* Manual, dataset 01, 8.5 min')
for key, val in manual_85.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* Classic watershed, dataset 01, 8.5 min')
for key, val in water_85.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [38]:
ratio = ds.ratio_manauto(manual_45, water_45)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [39]:
ratio = ds.ratio_manauto(manual_85, water_85)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [40]:
water_count_dap = pd.read_csv('counting/water_count/water_dataset02.txt')
water = {'MAG1': water_count_dap.query('image <= 392'),
'MAG2': water_count_dap.query('image > 392')}
In [41]:
ratio = ds.ratio_manauto(manual, water, sample='dataset02')
for rt in ratio:
print(rt)
In [58]:
print('Manual, dataset 02')
for key, val in manual.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('Classic watershed, dataset 02')
for key, val in water.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [42]:
# reading input data.
hwater_count_45 = pd.read_csv('counting/hwater_count/hwater_dataset01_Kr-78_4,5min_incid.txt')
hwater_count_85 = pd.read_csv('counting/hwater_count/hwater_dataset01_Kr-78_8,5min_incid.txt')
# separating folders.
hwater_45, hwater_85 = [{} for _ in range(2)]
for idx, folder in enumerate(folders):
hwater_45[samples[idx]] = hwater_count_45[hwater_count_45['folder'] == folder]
hwater_85[samples[idx]] = hwater_count_85[hwater_count_85['folder'] == folder]
# calculating the means for manual counting, and obtaining the candidates
# for seed.
mean_tol = 2 # defining tolerance
meanman_45, meanman_85 = [{} for _ in range(2)]
cand_hwater_45, cand_hwater_85 = [{} for _ in range(2)]
for key, val in manual_45.items():
# candidates for 4,5 min.
meanman_45[key] = val.manual_count.mean()
cand_hwater_45[key] = sup.comp_hwater_counting(meanman_45[key],
hwater_45[key],
tolerance=mean_tol)
for key, val in manual_85.items():
# candidates for 8,5 min.
meanman_85[key] = val.manual_count.mean()
cand_hwater_85[key] = sup.comp_hwater_counting(meanman_85[key],
hwater_85[key],
tolerance=mean_tol)
In [43]:
print('* Means for manual counting (4.5 min):\n', meanman_45)
for cand in ds.sorting_candidates(ds.joining_candidates(cand_hwater_45)):
print('Candidate: ', cand[0], ', Samples: ', cand[1])
print('\n')
print('* Means for manual counting (8.5 min):\n', meanman_85)
for cand in ds.sorting_candidates(ds.joining_candidates(cand_hwater_85)):
print('Candidate: ', cand[0], ', Samples: ', cand[1])
print('\n')
In [44]:
# supporting variables.
man_color = '#386cb0'
hwater_color = '#99d8c9'
plot_where = {'0': 10, '20': 20, '30': 30, '40': 40, '50': 50,
'60': 60, '70': 70, '80': 80, '90': 90}
x_ticks = [10, 20, 30, 40, 50, 60, 70, 80, 90]
x_labels = ['K0', 'K20', 'K30', 'K40', 'K50', 'K60', 'K70', 'K80', 'K90']
# the actual plots.
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 15))
for key, val in meanman_45.items():
axes[0].errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
axes[0].annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
axes[0].set_title('4,5 min samples')
for key, val in meanman_85.items():
axes[1].errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
axes[1].annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
axes[1].set_title('8,5 min samples')
for idx in range(1, 61):
for key, val in hwater_45.items():
aux_hwater = val.auto_count[val.seed == idx].mean()
if 0 < (meanman_45[key] - aux_hwater) < mean_tol:
axes[0].scatter(plot_where[key], aux_hwater, color=hwater_color)
else:
axes[0].scatter(plot_where[key], aux_hwater, color='k', alpha=0.1)
for key, val in hwater_85.items():
aux_hwater = val.auto_count[val.seed == idx].mean()
if 0 < (meanman_85[key] - aux_hwater) < mean_tol:
axes[1].scatter(plot_where[key], aux_hwater, color=hwater_color)
else:
axes[1].scatter(plot_where[key], aux_hwater, color='k', alpha=0.1)
for ax in axes.ravel():
ax.set_xticks(x_ticks)
ax.set_xticklabels(x_labels)
ax.set_xlim([5, 100])
ax.set_ylim([-1, 40])
In [45]:
bestseed = 5
In [46]:
# 4.5 minutes:
hwaterbest_45 = {}
for key, val in hwater_45.items():
hwaterbest_45[key] = val[val['seed'] == bestseed]
ratio = ds.ratio_manauto(manual_45, hwaterbest_45)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [55]:
# comparing manual/auto mean and std
print('* Manual, dataset 01, 4.5 min')
for key, val in manual_45.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* H-watershed, dataset 01, 4.5 min')
for key, val in hwaterbest_45.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
print('* Manual, dataset 01, 8.5 min')
for key, val in manual_85.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('* H-watershed, dataset 01, 8.5 min')
for key, val in hwaterbest_85.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [47]:
# 8.5 minutes:
hwaterbest_85 = {}
for key, val in hwater_85.items():
hwaterbest_85[key] = val[val['seed'] == bestseed]
ratio = ds.ratio_manauto(manual_85, hwaterbest_85)
# the values of mu and sigma for each sample:
for rt in ratio:
print(rt)
In [48]:
hwater_count_dap = pd.read_csv('counting/hwater_count/hwater_dataset02.txt')
hwater = {'MAG1': hwater_count_dap.query('image <= 392'),
'MAG2': hwater_count_dap.query('image > 392')}
In [49]:
# calculating the means for manual counting, and obtaining the candidates for initial_radius and delta_radius.
mean_tol = 5 # defining tolerance
meanman_dap, hwater_dap = [{} for _ in range(2)]
for key, val in manual.items():
meanman_dap[key] = val.manual_count.mean()
hwater_dap[key] = sup.comp_hwater_counting(meanman_dap[key],
hwater[key],
tolerance=mean_tol)
In [50]:
print('Means for manual counting: ', meanman_dap, '\nBest candidates: ', hwater_dap)
In [51]:
man_color = '#386cb0'
hwater_color = '#99d8c9'
plot_where = {'MAG1': 10, 'MAG2': 20}
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(15, 10))
for key, val in meanman_dap.items():
ax.errorbar(plot_where[key], val, yerr=np.array([[mean_tol, 0]]).T, marker='o', color=man_color)
ax.annotate(np.round(val, decimals=1), xy=(plot_where[key]+1.2, val), color=man_color)
for idx in range(1, 61):
for key, val in hwater.items():
aux_hwater = val.auto_count[val.seed == idx].mean()
if 0 < (meanman_dap[key] - aux_hwater) < mean_tol:
ax.scatter(plot_where[key], aux_hwater, color=hwater_color)
else:
ax.scatter(plot_where[key], aux_hwater, color='k', alpha=0.1)
ticks = [10, 20]
ax.set_xticklabels(('Magnification 1', 'Magnification 2'))
ax.set_xticks(ticks)
ax.set_xlim([5, 25])
Out[51]:
In [52]:
hwater_best_mag1 = hwater['MAG1'][hwater['MAG1']['seed'] == 19]
hwater_best_mag2 = hwater['MAG2'][hwater['MAG2']['seed'] == 23]
hwater_best = {'MAG1': hwater_best_mag1, 'MAG2': hwater_best_mag2}
ratio = ds.ratio_manauto(manual, hwater_best, sample='dataset02')
for rt in ratio:
print(rt)
In [57]:
print('Manual, dataset 02')
for key, val in manual.items():
print(key, ':', ds.parameters_samples(val.manual_count))
print('\n')
print('H-watershed, dataset 02')
for key, val in hwater_best.items():
print(key, ':', ds.parameters_samples(val.auto_count))
print('\n')
In [ ]: