-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
1700 lines (1512 loc) · 88.7 KB
/
main.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[
digital, %% The `digital` option enables the default options for the
%% digital version of a document. Replace with `printed`
%% to enable the default options for the printed version
%% of a document.
%% color, %% Uncomment these lines (by removing the %% at the
%% %% beginning) to use color in the printed version of your
%% %% document
oneside, %% The `oneside` option enables one-sided typesetting,
%% which is preferred if you are only going to submit a
%% digital version of your thesis. Replace with `twoside`
%% for double-sided typesetting if you are planning to
%% also print your thesis. For double-sided typesetting,
%% use at least 120 g/m² paper to prevent show-through.
nosansbold, %% The `nosansbold` option prevents the use of the
%% sans-serif type face for bold text. Replace with
%% `sansbold` to use sans-serif type face for bold text.
nocolorbold, %% The `nocolorbold` option disables the usage of the
%% blue color for bold text, instead using black. Replace
%% with `colorbold` to use blue for bold text.
lof, %% The `lof` option prints the List of Figures. Replace
%% with `nolof` to hide the List of Figures.
lot, %% The `lot` option prints the List of Tables. Replace
%% with `nolot` to hide the List of Tables.
]{fithesis4}
%% The following section sets up the locales used in the thesis.
\usepackage[resetfonts]{cmap} %% We need to load the T2A font encoding
\usepackage[T1,T2A]{fontenc} %% to use the Cyrillic fonts with Russian texts.
\usepackage[
main=english, %% By using `czech` or `slovak` as the main locale
%% instead of `english`, you can typeset the thesis
%% in either Czech or Slovak, respectively.
english, czech, slovak %% The additional keys allow
]{babel} %% foreign texts to be typeset as follows:
%%
%% \begin{otherlanguage}{german} ... \end{otherlanguage}
%% \begin{otherlanguage}{russian} ... \end{otherlanguage}
%% \begin{otherlanguage}{czech} ... \end{otherlanguage}
%% \begin{otherlanguage}{slovak} ... \end{otherlanguage}
%%
%% For non-Latin scripts, it may be necessary to load additional
%% fonts:
\usepackage{paratype}
\def\textrussian#1{{\usefont{T2A}{PTSerif-TLF}{m}{rm}#1}}
%%
%% The following section sets up the metadata of the thesis.
\thesissetup{
date = \the\year/\the\month/\the\day,
university = mu,
faculty = fi,
type = bc,
department = Department of Visual Computing,
author = Bruno Petrus,
gender = m,
advisor = {Assoc. Prof. RNDr. Martin Maška, Ph.D.},
title = {Segmentation of Membrane-Stained Cells in Image Data of Organoids},
TeXtitle = {Segmentation of Membrane-Stained Cells in Image Data of Organoids},
keywords = {segmentation, image processing, scikit-image, watershed,
thresholding, fluorescence microscopy, zero-crossing},
TeXkeywords = {segmentation, image processing, scikit-image, watershed,
thresholding, fluorescence microscopy, zero-crossing},
abstract = {%
In this thesis, we present a two-stage image analysis pipeline for segmenting membrane-stained and nuclei-stained image data of organoids captured using a fluorescence microscope. In the first stage, a coarse segmentation of individual cells in the membrane channel is obtained by analysing the Laplacian operator's response and watershed-driven tesselation. In the second stage, the coarse segmentation is projected into the nuclear channel, and individual nuclei regions are refined via local gradient thresholding. The performance of the developed pipeline is evaluated using a representative, manually annotated dataset, with a focus on detection and segmentation accuracy and execution time. The developed pipeline is implemented in Python and complemented with a detailed documentation of its usage.
},
thanks = {%
I am extremely grateful to my advisor, Assoc. Prof. RNDr. Martin Maška,
Ph.D., for his continuous guidance, helpful advice, and \mbox{feedback}. I am
also thankful to my family and close friends for their support. \mbox{Finally},
I am grateful to Dr. Zuzana Sumbalová Koledová and \mbox{Dr. Matea} Brezak for providing
me with the annotated image data \mbox{analysed} in this thesis.
},
bib = bibliography.bib,
%% Remove the following line to use the JVS 2018 faculty logo.
facultyLogo = fithesis-fi,
}
\usepackage{makeidx} %% The `makeidx` package contains
\makeindex %% helper commands for index typesetting.
%% These additional packages are used within the document:
\usepackage{paralist} %% Compact list environments
\usepackage{amsmath} %% Mathematics
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{url} %% Hyperlinks
\usepackage{markdown} %% Lightweight markup
\usepackage{listings} %% Source code highlighting
\usepackage{graphicx}
\lstset{
basicstyle = \ttfamily,
identifierstyle = \color{black},
keywordstyle = \color{blue},
keywordstyle = {[2]\color{cyan}},
keywordstyle = {[3]\color{olive}},
stringstyle = \color{teal},
commentstyle = \itshape\color{magenta},
breaklines = true,
}
\usepackage{floatrow} %% Putting captions above tables
\floatsetup[table]{capposition=top}
\usepackage[babel]{csquotes} %% Context-sensitive quotation marks
\usepackage{svg}
\usepackage{caption}
\usepackage{subcaption}
%% Specify new commands
\newcommand*{\R}{\ensuremath{\mathbb{R}}}
\newcommand*{\Z}{\ensuremath{\mathbb{Z}}}
\begin{document}
%% The \chapter* command can be used to produce unnumbered chapters:
\chapter*{Introduction}
%% Unlike \chapter, \chapter* does not update the headings and does not
%% enter the chapter to the table of contents. I we want correct
%% headings and a table of contents entry, we must add them manually:
\markright{\textsc{Introduction}}
\addcontentsline{toc}{chapter}{Introduction}
In the field of biology, the development of confocal laser scanning and
fluorescence microscopy has allowed scientists to create high-resolution multidimensional images of various plant and animal tissues \cite{stegmaier2016}. One of the areas where these methods are actively utilised is in skin cancer research \cite{gupta2020} or in the analysis of ovarian tissues from oncological patients \cite{fabbri2014}. Since cancer is the second-leading cause of death in the world \cite{mayo-clinic-cancer}, further research into this area and the creation of better tools for image processing are essential to developing cures for the disease.
One of the critical processes in researching this topic is the segmentation of cells to study their behaviour and shape; however, this often has to be done manually, taking valuable time from researchers to focus on more significant parts of their research. It is, therefore, necessary to develop robust automatic segmentation techniques that scale with the data's growing size.
This thesis focuses on developing an image analysis pipeline for segmenting membrane-stained and nuclei-stained cells in fluorescence microscopy image data of organoids without reference annotations. This pipeline is delivered in an easy-to-use form, and a quantitative analysis of the segmentation quality is performed. The developed method consists of two steps. In the first step, the program analyses the second partial derivate of the image data and uses the watershed algorithm to create a coarse segmentation of individual cells; then, in the second step, this is utilised to create a better-fitting segmentation by locally thresholding the nuclei-stained channel.
The first chapter defines the basic terms required for understanding the rest of the thesis. It also formalises the problem of edge detection, thresholding, and segmentation. The next chapter describes the available image data and the common issues that must be dealt with before analysing the data. In the third chapter, a high-level overview of all the steps taken in the segmentation process is detailed and visualised. The fourth chapter details the implementation of the non-trivial steps in the pipeline and provides the motivation behind choosing Python and the required libraries. The fifth chapter discusses how the quantitative analysis was done and its results, alongside the program's performance on the analysed dataset. Lastly, the appendix serves as a documentation for the numerous tweakable parameters.
\chapter{Basic terms}
Image processing involves mathematical techniques and algorithms
to extract useful information or somehow alter the image. The purpose of this
section is to provide a comprehensive and shallow overview of the fundamental
concepts used in the developed image processing pipeline.
\section{Digital Image}
Our eyesight is undoubtedly one of our most helpful senses, allowing us to
observe, study and comprehend the world around us. However, the way a computer
processes visual information is quite different. To enable us to study the world
using computers, numerous tools and algorithms have been developed. In this
section, I will begin by defining the concept of images in a formalized manner,
so that mathematics and computer science knowledge can be utilized to analyze
images.
Essentially we can think of an image as an n-dimensional function $f(x_1, x_2,
..., x_n)$, where $x_1, x_2, ..., x_n$ are coordinates inside a spatial domain,
while the function value at those coordinates specifies the magnitude or
intensity of the signal at that point. We can think about images as functions of
type $f:\R^n \rightarrow \R^m$ where $n$ indicates the number of spatial
dimensions and $m$ specifies the number of channels. For example, when we are
talking about two-dimensional grayscale images, $m$ is equal to 1 and $n$ is
equal to 2, while a typical coloured photograph has 3 colour channels. Another
important image type is the binary image, where the function's range is just two
values.
Once we start using computers to work with images, we no longer can work with
real-valued spatial dimensions and intensities, because we only have a finite
number of bits. The process of discretizing images in a finite grid and assigning
intensities from a finite range is called sampling and quantization. In essence,
we create a digitalized version of the original signal, which can be represented
as a one- or \mbox{multi-dimensional} array of values.
\section{Edge detection}
In digital image processing, edges typically separate different regions of
interest from one another. They are essential in digital image processing
as they can be used in many workflows --- such as image segmentation and
classification --- to extract various interesting features and regions
from the image.
There is no authoritative definition of an edge, but it can be thought of as a
set of connected pixels that lie on the boundary between two regions
\cite{gonzalez2002}. Usually, there is a gradual difference in intensities
between two regions, as is shown in Figure \ref{fig:edge_intensities}. It is
hard to define precisely where an edge begins and ends, so the first and the
second derivative of the image is usually calculated and analysed.
Looking at the second derivate of the image, we can see two distinct spikes,
which are called zero-crossings, and they will be utilised by the program for finding edges.
\begin{figure}
\begin{center}
\includegraphics[width=6cm]{resources/inkscape/gradient.png}
\end{center}
\caption{Intensity of the signal, and its first and second derivative.}
\label{fig:edge_intensities}
\end{figure}
\subsection{Gradient operator}
The first common way of working out where the edge is located is by looking at
the gradient of the image. The gradient of an image $\nabla f(x,y)$ is defined
as a vector \cite{gonzalez2002}:
$$\nabla f =
\begin{bmatrix}
\dfrac{\partial f}{\partial x}\\[2ex]
\dfrac{\partial f}{\partial y}
\end{bmatrix}.$$
This vector represents the rate of change in the image intensities, and it points in
the direction of the maximum rate of change of intensity. Often just the bare
vector is not of interest; instead, the magnitude of the gradient, denoted as
$|\nabla f|$, is calculated too. Confusingly enough, sometimes this is also called
the gradient in the literature, but here I will differentiate it by putting
absolute value around it. Formally it is defined as:
$$|\nabla f| = \sqrt{\left(\frac{\partial f}{\partial x}\right)^2 +
\left(\frac{\partial f}{\partial y}\right)^2}.$$
Now the question is how to calculate the partial derivatives of some digital image.
It is impossible to calculate the partial derivatives using the standard
definition from mathematical analysis because digital images are discrete; thus,
we must use an approximation. To calculate the $\frac{\partial f}{\partial x}$
we can use the following approximation:
$$\frac{\partial f}{\partial x}(i, j) \approx \frac{f(i+1,j)-f(i-1,j)}{2}$$
and similarly for the $\frac{\partial f}{\partial y}$ we can use:
$$\frac{\partial f}{\partial y}(i, j) \approx \frac{f(i, j+1)-f(i,j-1)}{2}.$$
Using them, we can reasonably approximate the magnitude of the gradient as:
$$|\nabla f(i, j)| \approx \frac{1}{2}\sqrt{(f(i+1, j) - f(i-1, j))^2 + (f(i, j+1) - f(i, j-1))^2}.$$
An example of the magnitude of the gradient is visible in Figure
\ref{fig:grad-thresh-grad}.
We can then extract the edges with further processing but since the program
does not rely on this method, I will skip the details; however, the program uses
the magnitude of the gradient for calculating the gradient threshold, described later
in this chapter.
\subsection{Laplacian operator}
The second common way --- and the one we will use for finding edges --- is using the second derivative, or more
precisely, using the Laplacian operator. For a 2D function $f(x, y)$ the Laplacian operator is
defined as \cite{gonzalez2002}:
$$\nabla^2 f = \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2}.$$
However, in the context of digital image processing, our signal is discrete;
therefore, a discrete approximation is needed again. A fairly standard way is to use
the following approach to calculate the partial second derivative in the $x$
axis:
$$\frac{\partial^2 f}{\partial x^2}(i, j) \approx f(i + 1, j) + f(i - 1, j) - 2f(i, j)$$
and similar in the y axis:
$$\frac{\partial^2 f}{\partial y^2}(i, j) \approx f(i, j + 1) + f(i, j - 1) - 2f(i, j).$$
Substituting into the prior definition, we get the following approximation:
$$\nabla^2 f \approx f(i+1, j) + f(i-1, j) + f(i, j+1) + f(i, j-1) - 4f(i,j).$$
To calculate the Laplacian of an image, this formula is applied to every pixel.
The outer pixels can be dealt with in many ways, but the developed program simply
ignores them.
One of the disadvantages of this approach is the sensitivity to noise. For
demonstration purposes, the effects are shown in 1D in Figure
\ref{fig:filtering-noise}. While the original
signal does not look too degraded, it is impossible to find the correct
zero-crossings. Therefore we have to help the operator by first smoothing the
image. A common approach is first to use Gaussian smoothing; this is sometimes
called a Laplacian of Gaussian operator or a Mexican hat filer. The idea is that
by averaging, we reduce some of the effects of the noise
\cite{hipr-mexican-hat}. As is shown in the figure, without the additional Gaussian
smoothing, we cannot deduce much from the second derivative, but after the smoothing
is applied, the zero-crossing becomes visible.
\begin{figure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/small_noise.png}}
\end{subfigure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/filtered_noise.png}}
\end{subfigure}
\caption{Demonstration of the effect of noise and filtering on a simple
linear increase in signal intensity. In the second row, the first derivate of the
signal is displayed, and in the third row is the second derivative. On the
left, an artificial noise has been added to the signal. On the right, a
Gaussian smoothing has been applied on top of the noisy signal.}
\label{fig:filtering-noise}
\end{figure}
After applying the Laplacian operator, we can find the zero-crossings and the edges.
A simple algorithm is to go through the whole image and checks
if a particular pixel at a given position is positive while its neighbours are
negative. If this condition is true, we set this position to white in the
resulting image and black otherwise. This creates the following image in
Subfigure \ref{fig:zc}. Here is another valuable property of the zero-crossing
algorithm. The produced edges are thin and form closed contours. This algorithm is
described in more detail in Section \ref{section:zc}.
\section{Thresholding}
Another fundamental area of image processing is thresholding. During thresholding
we try to find a suitable threshold value which separates logical parts of the image,
such as the background and foreground.
\subsection{Otsu method}
The Otsu thresholding method is a popular technique to determine a threshold
value between two classes (usually the foreground and the background). As such,
it works well if the image's histogram has a clear bimodal distribution. The
main idea of this approach is to see the problem of finding the threshold as an
optimization problem, where the inter-class variance of the two classes is to be
minimized. More information is available in \cite{otsu1979}. A demonstration of the
Otsu thresholding is shown in Figure \ref{fig:otsu-demonstration}.
\begin{figure}
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{resources/otsu-orig.png}}
\caption{}
\label{fig:otsu-orig}
%\caption{}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{resources/otsu-thresholded.png}}
\caption{}
\label{fig:otsu-thresholded}
%\caption{}
\end{subfigure}
\begin{subfigure}[t]{0.6\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/otsu-histogram.png}
\caption{}
\label{fig:otsu-histogram}
%\caption{}
\end{subfigure}
\caption{Demonstration of the Otsu thresholding method. In (\subref{fig:otsu-orig}) an image from the membrane-stained channel is shown. In (\subref{fig:otsu-thresholded}) the Otsu thresholding is applied. In (\subref{fig:otsu-histogram}) the histogram of the image data is shown with a line indicating the threshold.}
\label{fig:otsu-demonstration}
\end{figure}
%todo: Finish
\subsection{Gradient thresholding}
Another useful thresholding method is the gradient thresholding algorithm. Unlike
many other thresholding algorithms, it does not purely rely on the analysis of
the image's histogram; instead, the threshold is calculated as a weighted sum of
the image's intensities, where the weights are dictated by the magnitude of the
gradient \cite{pb130}.
The idea is that the background tends to be rather uniform compared to the
object in the foreground; hence, the magnitude of the gradient is the greatest
in the foreground, and the edge separating it from the background. That can be
utilized by using the magnitude as the weight in the summing of intensities.
This way the background's intensities play lesser role.
Formally the threshold $a$ is defined as:
$$a = \sum_{u, v} I(u, v) \frac{|\nabla I(u, v)|}{\sum_{i, j} |\nabla I(i,j)|}$$
where $I(i, j)$ stands for the image intensity at the $(i, j)$ position.
\begin{figure}
\begin{subfigure}{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{./resources/grad-thresh-orig.png}
\caption{}
\label{fig:grad-thresh-orig}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{./resources/grad-thresh-grad.png}
\caption{}
\label{fig:grad-thresh-grad}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{./resources/grad-thresh-final.png}
\caption{}
\label{fig:grad-thresh-final}
\end{subfigure}
\caption{Demonstration of the gradient thresholding. Image data from the
membrane-stained channel (\subref{fig:grad-thresh-orig}) was thresholded
(\subref{fig:grad-thresh-final}) using the gradient thresholding. In
(\subref{fig:grad-thresh-grad}) the magnitude of the gradient is shown.}
\label{fig:demo_grad_thresh}
\end{figure}
In Figure \ref{fig:demo_grad_thresh} an example image is shown. There, the
gradient thresholding algorithm was used to segment the cell from the
background. As can be seen, the magnitude of the gradient is biggest in the
cell; hence, it contributes more to the value of the threshold.
\section{Mathematical morphology}
Mathematical morphology is an area of research studying how to extract valuable
information and how to filter images. A few examples of what mathematical
morphology is used for are edge-detecting algorithms, finding convex hulls, and image
filtering. In the simplest terms, mathematical morphology looks at images as
sets of numbers and modifies them using structural elements. Those can take many
forms, but their shape varies based on the task we are trying to achieve. The
main use of mathematical morphology in this thesis is to pre- and post-process
image data generated by other image processing methods. First, some basic
operations on binary images are described. Note that this area is vast and still
being actively researched, and I will cover only parts which are helpful later
in my prototype.
In this branch of image processing, we look at the images through set theory
instead of looking at images as discrete-valued functions. In this context, an
image is a subset of 2-D integer space $\Z^2$, which can easily be generalized
to more dimensions. Each element of this subset $(x, y)$ represents a present
pixel at those coordinates in the image. In other words, if we look at an image
as an array of rectangular shape, then each foreground pixel's coordinates will
be included in the set representation.
\subsection{Preliminary}
Before we look at the two main operations --- erosion and dilation --- we have to
define two not-so-common operations on sets which are heavily used in
mathematical morphology.
During the following sections, we need to be able to talk about how to create a
reflection of the image around its origin, as shown in Figure
\ref{fig:morp_refl}. Reflection of a set $B$ is formally defined as \cite{gonzalez2002}:
$$\hat{B} = \{w | w=-b \text{ , for } b \in B\}$$
\begin{figure}
\begin{center}
\includegraphics[width=0.5\textwidth]{resources/inkscape/morphology-reflection.png}
\end{center}
\caption{Morphological reflection of image $A$, where $C=\hat{A}$} % todo: replace
\label{fig:morp_refl}
\end{figure}
While manipulating images we commonly have to move parts of the image around.
In principle, a similar operation, called translation, is defined on sets. The
formal definition of moving a set $A$ by some translation vector $z$ is
\cite{gonzalez2002}:
$$(A)_z = \{c | c = a + z\text{ , for } a \in A\}$$
The operation is illustrated in Figure \ref{fig:morph_translation} where the set
$A$ is moved downwards by a vector $z$.
\begin{figure}
\begin{center}
\includegraphics[width=0.5\textwidth]{resources/inkscape/morphology-translation.png}
\end{center}
\caption{Morphological translation}
\label{fig:morph_translation}
\end{figure}
\subsection{Dilation and Erosion}
Now it is possible to properly define two fundamental operations in the field of
mathematical morphology, upon which many other operations are built. Both of
these operations include a structural element. A structural element is again a
set, but it can be used to describe how far and in which way a particular
operation will influence the result.
\subsubsection{Dilation}
Intuitively we can think about the dilation operator as a way to dilate spots
inside an image into a bigger space. Formally it is defined as
\cite{gonzalez2002}
$$A \oplus B = \{z | (\hat{B}_z) \cap A \neq \emptyset\}$$
where $A$ and $B$ are both sets in $\Z^2$.
An example of dilation can be seen in Figure \ref{fig:morph_dilation}. In the
first row, we have a square image with a side length of $d$ and a structuring
element whose side length is a fourth of the original. If we apply the dilation
operation on these two images, we get the one on the right. You can imagine
taking the smaller square and gliding it over the bigger one. If there is an
overlap, we can add the centre of the structural element to the result.
Closer to the mathematical definition, all possible translations are applied to
the structural element and if there is an overlap, we add the centre of the
structural element to the resulting set.
For example, this operation can be used to join disconnected segments in an
image by choosing a large enough structural element. Its size will depend on the
particular example and does not necessarily have to be of regular size \cite{gonzalez2002}.
\begin{figure}
\begin{center}
\includegraphics[width=6.3cm]{resources/morph_dilation.jpg}
\end{center}
\caption{Morphological dilation (Gonzalez 2002)} % todo: Replace
\label{fig:morph_dilation}
\end{figure}
\subsubsection{Erosion}
The next essential operation is erosion. As the name suggests, we use it to
erode parts of the image which we consider unnecessary. An erosion $A \ominus B$
of two sets $A$ and $B$, both being part of $\Z^2$ space, is defined as
\cite{gonzalez2002}: $$A \ominus B = \{z | (B)_z \subseteq A\}$$
Again $A$ can be thought of as an image while $B$ can be looked at as a
structural element. In contrast to the dilation operation, we are now looking if
the whole structural element fits inside $A$ as can be seen in Figure
\ref{fig:morph_erosion}. There a smaller structural element is used to cut away
parts of the bigger square.
As opposed to the dilation, we can use erosion to divide lightly connected
segments, and to suppress noise and other unwanted disturbances in an image.\cite{gonzalez2002}
\begin{figure}
\begin{center}
\includegraphics[width=6.3cm]{resources/morph_erosion.jpg}
\end{center}
\caption{Morphological erosion (Gonzalez 2002)} % todo: Replace
\label{fig:morph_erosion}
\end{figure}
\subsection{Opening and closing}
Now that the basic two operations have been defined, we can move on to two
very useful operators, morphological opening and morphological closing.
\subsubsection{Opening}
The morphological opening is defined as erosion followed by a dilation with a
reflected structural element, formally the opening $\circ$ of a set $A$ by a structuring
element $B$ is defined as\cite{soile2004}:
$$A \circ B = (A \ominus B) \oplus \hat{B} $$
This process in visualised in Figure \ref{fig:opening}, where the square
structural element is applied on the binary image. Morphological opening
preserves larger structural components, and removes small objects from the
image. This means, it is a good candidate for removing noise, small objects or
thin structures, which may interfere with later processing. \cite{soile2004}
\begin{figure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_orig.png}
\caption{}
\label{fig:opening_orig}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_erosion.png}
\caption{}
\label{fig:opening_erosion}
\end{subfigure}
\begin{subfigure}[t]{0.2\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_erosion_se.png}
\caption{}
\label{fig:opening_erosion_se}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_dilation.png}
\caption{}
\label{fig:opening_dilation}
\end{subfigure}
\begin{subfigure}[t]{0.2\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_dilation_se.png}
\caption{}
\label{fig:opening_dilation_se}
\end{subfigure}
\caption{Morphological opening (\subref{fig:opening_dilation}) of the binary image (\subref{fig:opening_orig}) . Centres of structural elements are indicated by the circles. The gray pixels indicate which pixels
were lost (erosion) or added (dilation) after the transformation. In (\subref{fig:opening_erosion}) the erosion of the binary image with a structuring element (\subref{fig:opening_erosion_se}) is shown, and in (\subref{fig:opening_dilation}) the dilation of the previous image by the structuring element (\subref{fig:opening_dilation_se}) is shown.}
\label{fig:opening}
\end{figure}
\subsubsection{Closing}
The morphological closing is defined similarly to the opening, but the order of
operations is reversed. The closing $\bullet$ of a set $A$ by a structuring
element $B$ is defined as\cite{soile2004}:
$$A \bullet B = (A \oplus B) \ominus \hat{B} $$
\begin{figure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/closing_orig.png}
\caption{}
\label{fig:closing_orig}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/closing_dilation.png}
\caption{}
\label{fig:closing_dilation}
\end{subfigure}
\begin{subfigure}[t]{0.2\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_erosion_se.png}
\caption{}
\label{fig:closing_erosion_se}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/closing_erosion.png}
\caption{}
\label{fig:closing_erosion}
\end{subfigure}
\begin{subfigure}[t]{0.2\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/inkscape/opening_dilation_se.png}
\caption{}
\label{fig:closing_dilation_se}
\end{subfigure}
\caption{Morphological closing (\subref{fig:closing_erosion}) of the binary image (\subref{fig:closing_orig}). The circles indicate centres of structural elements. The grey pixels indicate which pixels were lost (erosion) or added (dilation) after the transformation. In (\subref{fig:closing_dilation}) the dilation with structuring element (\subref{fig:closing_erosion_se}) is applied on (\subref{fig:closing_orig}). In (\subref{fig:closing_erosion}) the erosion of (\subref{fig:closing_dilation}) with structuring element (\subref{fig:closing_dilation_se}) is shown.}
\label{fig:closing}
\end{figure}
As for the previous operator, this is visualised in Figure \ref{fig:closing},
where the square structural element is applied on the binary image.
Morphological closing, like the opening, keeps the larger structural elements
but also fills in holes, which might have been created, for example, by noise.
Also, it does not remove small objects.
While mathematical morphology is a massive topic of interest to many
researchers, here I will only use the aforementioned operations. They can be
further used to define more operations such as performing top hat transforms,
skeletonizing images, finding perimeters etc \cite{mathworks_morp_oper}.
\section{Segmentation}
Image segmentation is a fundamental step in the image processing. Unlike in the
previous sections, we are no longer interested in manipulating and changing the
image. The point of image segmentation is to split the image into regions with
some specific meaning, e.g. in our case, to split the data into regions of
individual cells \cite{gonzalez2002}.
Numerous techniques can be applied, but in this thesis, we are interested in
one particular technique --- the watershed algorithm --- and segmentation based
on the Laplacian operator in the zero-crossing algorithm.
\subsection{Watershed algorithm}
The watershed algorithm is a widespread technique for image segmentation. The
fundamental principle of the watershed algorithm is to view the image as a
topographic map, where the intensities indicate the height of the landscape, in
other words, peaks in the image represent mountains or hills, while low values
represent valleys.
The algorithm then creates water springs in these valleys, from which the water
flows at a uniform rate. As the waters from different springs rise, they might
start to mix. At these points, we build dams to separate the various flooded
areas. The water continues to flow until just the dams are visible above the
water \cite{gonzalez2002}. At this point, the image is segmented using the dams,
and every catchment basin is uniquely labelled.
\begin{figure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/watershed-basic.png}}
\caption{}
\label{fig:demo-watershed-orig}
\end{subfigure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/watershed-complex.png}}
\caption{}
\label{fig:demo-watershed-run}
\end{subfigure}
\caption{Demonstration of the watershed algorithm. In (\subref{fig:demo-watershed-orig}) a binary image with two overlapping circles is shown. Running the algorithm produces (\subref{fig:demo-watershed-run}).}
\label{fig:demo-watershed}
\end{figure}
In Figure \ref{fig:demo-watershed}, the result of running the watershed algorithm
on a simple image is shown.
\subsection{Distance transform}
One of the last required terms to define is the distance transform, which is
used in the implementation to calculate the watershed algorithm.
The distance transform is defined on binary images. After the distance transform
is applied on an image, each intensity is replaced by the closest distance to
the background. In principle any metric can be used, but the Euclidean distance
is used in our case. A simple example is shown in Figure
\ref{fig:demonstration-distance-map}.
\begin{figure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{"./resources/distance-map-cirle.png"}}
\end{subfigure}
\begin{subfigure}[t]{0.48\textwidth}
\frame{\includegraphics[width=\textwidth]{"./resources/distance-map-transform"}}
\end{subfigure}
\caption{Demonstration of the distance transform. The farther the pixel is
from the background, the higher the pixel's intensity.}
\label{fig:demonstration-distance-map}
\end{figure}
\clearpage
\chapter{Image data}
The image data --- of mouse mammary organoids --- was acquired using a confocal
laser scanning microscope. The original data was captured in 2021 by a group of
researchers at the Faculty of Medicine, Masaryk University. The captured field of view is around 500
microns by 500 microns by 80 microns, and a single voxel's size is $0.233\mu m$ by
$0.233\mu m$ by $0.586\mu m$.
In confocal laser scanning microscopy, researchers can stain specific structures in
their specimen so that the studied structures emit light when the proper wavelength
is shined upon them. This allows them to capture the expression of studied proteins
inside the specimen. In this particular case, the researchers captured the
expression of 3 different proteins, of which one is part of membranes, while the
other two are primarily located inside the cells' nuclei.
The data, totalling around 576 GB, consists of 12 different time steps, where
each step has a size of 1920x1920x388 voxels. For every protein, the researchers
captured the image using two different optical setups; thus, there are six
channels. The data is stored in numerous TIFF files, and every channel contains
grayscale data with 16 bits per voxel.
\begin{figure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/C3-t006-200-scaled.jpg}
\caption{}
\label{fig:data_example_membraine}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{resources/C2-t006-200-scaled.jpg}
\caption{}
\label{fig:data_example_nuclei}
\end{subfigure}
\caption{On the left panel a sample from the membrane-stained channel is shown, while on the right panel a corresponding slice from the nuclei-stained channel is shown.}
\label{fig:data_example}
\end{figure}
In Figure \ref{fig:data_example}, a single slice of the image data was taken from
two channels. They are from the same time point and the same place.
\section{Typical challenges to deal with}
The size of the data and the inherent phenomenons of fluorescence microscopy
provide the main challenges in analysing the data. It is very time-consuming to
analyse the whole data set; therefore, all work was done on smaller data slices.
\begin{figure}
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/bad-edges.png}}
\caption{}
\label{fig:bad_edges}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.3\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/bleading-edge.png}}
\caption{}
\label{fig:bleeding_edges}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.5\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/light-scattering.png}}
\caption{}
\label{fig:scattering}
\end{subfigure}
\caption{Typical issues with the data. In (\subref{fig:bad_edges}) many of the membranes are missing, in (\subref{fig:bleeding_edges}) there is not a clear boundary between the specimen and the background, and in (\subref{fig:scattering}) the scattering of light inside the organoid, causes large problems with the segmentation.}
\end{figure}
\subsection{Noise}
The first problem with the data set is the quality. In most places, the noise is
too strong to try to use in any analysis.
In the membrane-stained channel, two main problems can be seen. To begin, most
membranes do not form connected segments; instead, a part of the cell's membrane is
usually missing, or it is joined with the neighbouring cell's membrane, as can be
seen in Figure \ref{fig:bad_edges}. This complicates the analysis, as different
regions may require different filters to be properly preprocessed. Moreover,
this makes edge detection more difficult because it relies on the magnitude of
the gradient of the image. Moreover, sometimes the intensity change between the cell and the
background is too smooth for the program to find the divisive line as in Figure
\ref{fig:bleeding_edges}.
Another issue is that the light gets scattered inside the organoid, as shown
in Figure \ref{fig:scattering}. That means that it is possible to reliably analyse only the
outermost layers of cells of the organoid.
The nuclei-stained channel comes with its own set of problems, some of them different.
It is still true that the sharpest data comes, from the outermost layer
of the organoid, severely limiting the amount of usable data. Another issue is that the
individual cells are sometimes quite fuzzy, which makes it difficult to decide where
exactly the cell ends or if there are multiple cells instead of one.
% todo: reword
\subsection{Size}
The size of the dataset poses the second problem, as it would be computationally
expensive to try to process the whole dataset at once; however, a lot of the
data is either unusable or of no interest. In most instances, the image data is
predominantly composed of the background, and at several moments in time, no
specimen can be seen; therefore, to reduce the computational demands further,
only specific regions of interest were manually selected to create the final
dataset. Ultimately, the reduced dataset is only a few dozen megabytes large.
\section{Dataset}
For reasons specified in the previous sections, it would not be reasonable
to run the evaluation algorithm on the whole image data. Moreover, it is unclear
how prediction on the whole image data would be scored, not to mention the large
computing and storage requirements; thus, we decided to create a set of images
on which the algorithm would be evaluated. The set contains 11 images, which I
hand-picked from the raw image data. I tried to include sections from various
channels, times, and of various quality. This was done to test the
program's performance under diverse circumstances.
All of the images are included as attachments in the thesis. The general
name scheme is \texttt{txxx-roi-y-z}, where \texttt{xxx} stands for the time,
\texttt{roi-y} stands for the region of interest with index \texttt{y}, and the
\texttt{z} stands for the central frame. As the program can use
multiple frames from the membrane-stained channel, it is possible to provide
several slices in a single file. The program then runs the maximum projection
in 3D, but the slice in the middle will be picked for further processing. On the
other hand, the nuclei-stained data is always two-dimensional.
This dataset was then manually annotated as follows: Parts that were considered to be background were labelled using $0$.
Sections which were too complicated or unclear were labelled using $65535$, and
the rest of the cells were uniquely labelled with numbers starting \mbox{at $1$}. In
Figure \ref{fig:label_ground_truth} the manual segmentation of the corresponding raw image data (Fig \ref{fig:label_membrane_channel}) created by the expert is shown.
\begin{figure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/membrane-channel.png}}
\caption{}
\label{fig:label_membrane_channel}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/ground-truth.png}}
\caption{}
\label{fig:label_ground_truth}
\end{subfigure}
\caption{In (\subref{fig:label_ground_truth}) the labelling created by an expert of the (\subref{fig:label_membrane_channel}) is shown. White means a complicated area, black is the background, and the rest are the cells.}
\end{figure}
\clearpage
\chapter{The developed segmentation method}
The goal of the algorithm is to segment individual cells and uniquely label each
cell; however, as previously discussed, they are often not clearly separated
from each other. A naive Otsu thresholding leads to unsatisfactory results, as is
shown in Figure \ref{fig:otsu-nuclei-demo}. Thus, a more sophisticated algorithm
had to be developed to segment the cells' nuclei finer.
\begin{figure}
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{resources/otsu-nuclei.png}}
\caption{}
\label{fig:otsu-nuclei}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{resources/otsu-naive.png}}
\caption{}
\label{fig:otsu-naive}
\end{subfigure}
\caption{Otsu thresholding (\subref{fig:otsu-naive}) of the image (\subref{fig:otsu-nuclei}) does not lead to satisfactory segmentation.}
\label{fig:otsu-nuclei-demo}
\end{figure}
We settled on a two-step algorithm. In the first step, the membrane-stained
channel is used, while in the second step, the nuclei-stained channel is used.
Every cell in our specimen has a membrane and nuclei; hence, we should be able
to use the information provided by the first channel to improve the thresholding
in the second channel.
In the first step, a coarse segmentation step is employed on the raw image data (Figure \ref{fig:max-proj-before}) to roughly find the membranes separating the individual cells (Figure \ref{fig:watershed}). The coarse segmentation is then utilized in the second step; the algorithm overlays the previous
segmentation on top of the nuclei-stained channel and looks at every label.
Each one represents a single cell and some of its surroundings. Finally, a
local version of the gradient thresholding is performed on each region (Figure \ref{fig:grad-thresh-post}).
\begin{figure}
\begin{center}
\includegraphics[width=0.8\linewidth]{./resources/inkscape/segmentation-steps.png}
\end{center}
\caption{All steps in the segmentation algorithm.}
\label{fig:segmentation_steps}
\end{figure}
\section{Coarse cell segmentation}
The goal is to provide a coarse segmentation of the cells using the
membrane-stained channel.
\subsection{Preprocessing}
First, the input image data is pre-processed to reduce the amount of noise in it.
As shown in Figure \ref{fig:max-proj}, we need to deal with the
fact that the intensities inside every cell are quite uneven. To even out the
signal inside cells, a maximum projection (Section \ref{sec:max-proj}) is
performed. The idea behind this step is that cell membranes have higher intensities than
the cells' interiors; therefore, they should not be very influenced by this step,
while the uneven illumination inside cells would be smoothed out. That happens
because the highest intensity areas will propagate out to the surrounding area.
\begin{figure}
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/max_proj_before.png}}
\caption{}
\label{fig:max-proj-before}
\end{subfigure}
\begin{subfigure}[t]{0.45\linewidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/max_proj_after.png}}
\caption{}
\label{fig:max-proj-after}
\end{subfigure}
\caption{The uneven illumination inside individual cells (\subref{fig:max-proj-before}) is mitigated using the
maximum projection technique (\subref{fig:max-proj-after}).}
\label{fig:max-proj}
\end{figure}
After dealing with the uneven lighting, additional smoothing is applied
to reduce the effect of residual noise further. Since the voxel's dimensions are
anisotropic, an anisotropic Gaussian smoothing is applied.
\subsection{Zero-crossing algorithm}
\label{section:zc}
Applying the zero-crossing algorithm at this stage would result in many
artificial cells being found in the background due to the presence of noise. To
remove these visual artefacts, we need to create a mask to differentiate the
background from the foreground. For this task, the Otsu thresholding method was
employed due to the bimodal distribution of the image intensities. Sometimes the interface between
the organoid's contour and the background is unclear, as depicted in Figure
\ref{fig:max-proj-before}. However, it is a considerably smaller issue if part of the
the background is categorised as the foreground; hence, this issue can be fixed by
running morphological erosion with a circular structural element with a diameter similar to the average cell diameter. This final mask then approximately distinguishes between the
background and the foreground. This mask is then utilised in the next steps, which
ignore all background image elements during their calculations.
\begin{figure}
\begin{subfigure}[t]{0.45\textwidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/threshold-before.png}}
\caption{}
\label{fig:cell-mask-bef}
\end{subfigure}
\begin{subfigure}[t]{0.45\linewidth}
\centering
\frame{\includegraphics[width=\textwidth]{./resources/threshold-expanded.png}}
\caption{}
\label{fig:cell-mask-aft}
\end{subfigure}
\caption{The Otsu method might sometimes classify parts of the specimen as
background (\subref{fig:cell-mask-bef}); thus, the mask must be expanded (\subref{fig:cell-mask-aft}) using morphological erosion.}
\label{fig:cell-mask}
\end{figure}
The zero-crossing algorithm provides a reasonable outline of the cells, as is
shown in Figure \ref{fig:zc}. The user sometimes has to play around with
the strength of the Gaussian smoothing (parameter \texttt{zc\_sigma} described in later chapters) to improve the quality of the edge detection. When the strength is too low, the program tends to find many small artificial regions; conversely, strong smoothing causes the algorithm to join individual cells together.
This step is further complicated by the fact that some of the cells are missing parts of
their membranes; hence, the performance of this step is one of the limiting factors of
the whole segmentation pipeline.
\begin{figure}
\begin{subfigure}[t]{0.45\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/zero-crossing.png}}
\caption{}
\label{fig:zc}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/mask.png}}
\caption{}
\label{fig:cells}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/mask-postprocessed.png}}
\caption{}
\label{fig:cells-post-processed}
\end{subfigure}
\begin{subfigure}[t]{0.45\textwidth}
\frame{\includegraphics[width=\textwidth]{./resources/watershed.png}}
\caption{}
\label{fig:watershed}
\end{subfigure}
\caption{Steps taken from zero-crossing algorithm towards watershed. First, in (\subref{fig:zc}) the edges found by the zero-crossing algorithm are shown. Then in (\subref{fig:cells}) the mask of cells is displayed. Then the mask is post-processed (\subref{fig:cells-post-processed}) and finally the result after watershed is shown (\subref{fig:watershed}).}
\label{fig:zc-watershed}
\end{figure}
\subsection{Watershed}
The next step is to utilize the outlines to segment individual cells. First, we need
to take the previous result and fill in the inside of the cells, as can be seen
in Figure \ref{fig:cells}. How this is achieved is explained in Section
\ref{sec-markers}. After this step is done, the image is further post-processed,
starting by using erosion to remove the leftover edges found by the zero-crossing, and then a morphological opening with
a disk-like structuring element is performed to remove small artificial cells caused
by noise. Finally, dilation is applied to restore some of the unwanted losses
caused by the morphological opening, leading to the result in Figure
\ref{fig:cells-post-processed}.
Finally, the watershed algorithm is used to label the individual cells uniquely.
Since the way it is implemented, even if two or more cells are joined in the
previous step, the watershed algorithm may be able to divide them. The result
is shown in Figure \ref{fig:watershed}. A more in-depth discussion is in Section
\ref{sec-markers}.
\section{Fine nucleus segmentation}
Unlike in the membrane-stained channel, in the nuclei-stained channel the
pipeline is lot less complicated. The whole pre-processing consists of a single
Gaussian smoothing, that is done because the data is quite grainy, and it helps
the gradient thresholding to produce more reliable results.
Applying the Otsu thresholding method in the nuclei-stained channel leads to
poor results, as shown in Figure \ref{fig:otsu-naive}. The problem is that the
lighting is quite uneven. Some cells are significantly brighter than others;
thus, global thresholding is not a viable option.
However, we can use the previously obtained segmentation from membrane-stained
channel to improve the quality of the thresholding. By looking at just specific
areas denoted by the labels, the thresholding yields more suitable results. In
essence, a local version of some thresholding algorithm can be used. Applying it
this way, the resulting thresholding is shown in Figure \ref{fig:grad-thresh}.
In our testing, the Otsu thresholding method was not suitable as in many cases, the
proximity of cells shrinks the background area, causing the algorithm to
categorise some of the foreground as the background. After some experimentation,
we concluded that the gradient thresholding algorithm provides better results.
Also, others easily accessed thresholding methods in the \texttt{scikit-image}
library were experimented with, but the gradient thresholding method provided
reasonable results in many cases.