This repository has been archived by the owner on Jul 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmorphdemo.py
3628 lines (3591 loc) · 107 KB
/
morphdemo.py
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
"""
Module morphdemo -- Demonstrations
-------------------------------------------------------------------
morphdemo is a set of Demonstrations for pymorph package
-------------------------------------------------------------------
airport() -- Detecting runways in satellite airport imagery.
area() -- Remove objects with small areas in binary images.
asp() -- Detect the missing aspirin tablets in a card of aspirin
tablets.
beef() -- Detect the lean meat region in a beef steak image.
blob() -- Demonstrate blob measurements and display.
brain() -- Extract the lateral ventricle from an MRI image of the
brain.
calc() -- Extract the keys of a calculator.
cells() -- Extract blood cells and separate them.
chickparts() -- Classify chicken parts in breast, legs+tights and wings
concrete() -- Aggregate and anhydrous phase extraction from a concrete
section observed by a SEM image.
cookies() -- Detect broken rounded biscuits.
cornea() -- Cornea cells marking.
fabric() -- Detection of vertical weave in fabrics.
fila() -- Detect Filarial Worms.
flatzone() -- Flat-zone image simplification by connected filtering.
flow() -- Detect water in a static image of an oil-water flow
experiment.
gear() -- Detect the teeth of a gear
holecenter() -- Hole center misalignment in PCB.
labeltext() -- Segmenting letters, words and paragraphs.
leaf() -- Segment a leaf from the background
lith() -- Detect defects in a microelectronic circuit.
pcb() -- Decompose a printed circuit board in its main parts.
pieces() -- Classify two dimensional pieces.
potatoes() -- Grade potato quality by shape and skin spots.
robotop() -- Detect marks on a robot.
ruler() -- Detect defects in a ruler.
soil() -- Detect fractures in soil.
"""
from pymorph import *
import numpy
print '''\
*********************** WARNING ******************************
The demo is not as well maintained as the rest of the package.
*********************** WARNING ******************************
The demo has not been updated to the newer interfaces.
'''
def readgray(imgname):
import pylab
return pylab.imread('pymorph/data/' + imgname)
def show(f, f1=None, f2=None, f3=None, f4=None, f5=None, f6=None):
import pylab
pylab.ion()
pylab.imshow(overlay(f,f1,f2,f3,f4,f5,f6))
pylab.draw()
# =========================================================================
#
# airport - Detecting runways in satellite airport imagery.
#
# =========================================================================
def airport():
print
print '''Detecting runways in satellite airport imagery.'''
print
#
print '========================================================================='
print '''
The satellite image of the airport is read.
'''
print '========================================================================='
#0
print '''
f = readgray('galeao.jpg')
show(f)'''
f = readgray('galeao.jpg')
show(f)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The disk of radius 5 (diameter 11) is chosen to detect features
smaller than this size. For visualization, the top-hat image is
brightened by 150 gray-levels.
'''
print '========================================================================='
#0
print '''
th=openth(f,sedisk(5))
show(addm(th, 150))'''
th=openth(f,sedisk(5))
show(addm(th, 150))
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
A thresholding is applied to detect the features enhanced by the
top-hat. This is a standard top-hat sequence.
'''
print '========================================================================='
#0
print '''
bin=threshad(th,30)
show(f,bin)'''
bin=threshad(th,30)
show(f,bin)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The thinning (red) and pruning (green) detect closed structures
which characterized the runways structure. The area open (blue)
selects only very long features, with more than 1000 pixels.
'''
print '========================================================================='
#0
print '''
m1=thin(bin)
m2=thin(m1,endpoints())
m=areaopen(m2,1000,sebox())
show(f,m1,m2,m)'''
m1=thin(bin)
m2=thin(m1,endpoints())
m=areaopen(m2,1000,sebox())
show(f,m1,m2,m)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The previous result is a sample of the runway pixels. It is used as
a marker for gray-scale morphological reconstruction. The runways
are enhanced in the reconstructed image.
'''
print '========================================================================='
#0
print '''
g=infrec(gray(m), th)
show(g)'''
g=infrec(gray(m), th)
show(g)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
A thresholding is applied to the reconstructed image, detecting the
airport runways.
'''
print '========================================================================='
#0
print '''
final=threshad(g, 20)
show(f, final)'''
final=threshad(g, 20)
show(f, final)
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# area - Remove objects with small areas in binary images.
#
# =========================================================================
def area():
print
print '''Remove objects with small areas in binary images.'''
print
#
print '========================================================================='
print '''
The binary image to be processed is read.
'''
print '========================================================================='
#0
print '''
a = readgray('circuit_bw.tif')
show(a)'''
a = readgray('circuit_bw.tif')
show(a)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The procedure areaopen removes the objects with area less than the
specified parameter (i.e., 200).
'''
print '========================================================================='
#0
print '''
b = areaopen(a,200)
show(b)'''
b = areaopen(a,200)
show(b)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
For displaying purposes the filtered image is superposed over the
original image.
'''
print '========================================================================='
#0
print '''
show(a,b)'''
show(a,b)
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# asp - Detect the missing aspirin tablets in a card of aspirin tablets.
#
# =========================================================================
def asp():
print
print '''Detect the missing aspirin tablets in a card of aspirin tablets.'''
print
#
print '========================================================================='
print '''
The aspirin tablet binary image is read.
'''
print '========================================================================='
#0
print '''
a = readgray('astablet.tif')
show(a)'''
a = readgray('astablet.tif')
show(a)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The image can be model as a topographical surface where white
regions corresponds to high altitude and dark regions to lower
altitute. The regional maxima of the image is normally very noisy as
can be seen below.
'''
print '========================================================================='
#0
print '''
b = surf(a)
show(b)
c = regmax(a,sebox())
show(b,c)'''
b = surf(a)
show(b)
c = regmax(a,sebox())
show(b,c)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Opening the original image by a disk a little smaller than the
tablets removes all the noisy regional maxima. The only regional
maxima in the opened image are the aspirin tablets as they are the
only regionally brighter regions of shape larger than the disk of
radius 20 pixels.
'''
print '========================================================================='
#0
print '''
d = open(a, sedisk(20))
e = surf(d)
show(e)
f = regmax(d,sebox())
show(e,f)'''
d = open(a, sedisk(20))
e = surf(d)
show(e)
f = regmax(d,sebox())
show(e,f)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Here it is shown the input and output result. Note that the binary
image of the aspirin tablets was obtained using just one parameter:
the radius of the circular structuring element. The problem was
solved as treating the image formed by circular bright regions.
'''
print '========================================================================='
#0
print '''
show(a)
show(f)'''
show(a)
show(f)
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# labeltext - Segmenting letters, words and paragraphs.
#
# =========================================================================
def labeltext():
print
print '''Segmenting letters, words and paragraphs.'''
print
#
print '========================================================================='
print '''
The text image is read.
'''
print '========================================================================='
#0
print '''
f = readgray('stext.tif')
show(f)'''
f = readgray('stext.tif')
show(f)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The letters are the main connected components in the image. So we
use the classical 8-connectivity criteria for identify each letter.
'''
print '========================================================================='
#0
print '''
fl=label(f,sebox())
lblshow(fl)'''
fl=label(f,sebox())
lblshow(fl)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The words are made of closed letters. In this case we use a
connectivity specified by a rectangle structuring element of 7
pixels high and 11 pixels width, so any two pixels that can be hit
by this rectangle, belong to the same connected component. The
values 7 and 11 were chosen experimentally and depend on the font
size.
'''
print '========================================================================='
#0
print '''
from numpy.oldnumeric import ones
sew = img2se(binary(ones((7,11))))
seshow(sew)
fw=label(f,sew)
lblshow(fw)'''
from numpy.oldnumeric import ones
sew = img2se(binary(ones((7,11))))
seshow(sew)
fw=label(f,sew)
lblshow(fw)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Similarly, paragraphs are closed words. In this case the
connectivity is given by a rectangle of 35 by 20 pixels.
'''
print '========================================================================='
#0
print '''
sep = img2se(binary(ones((20,35))))
fp=label(f,sep)
lblshow(fp)'''
sep = img2se(binary(ones((20,35))))
fp=label(f,sep)
lblshow(fp)
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# beef - Detect the lean meat region in a beef steak image.
#
# =========================================================================
def beef():
print
print '''Detect the lean meat region in a beef steak image.'''
print
#
print '========================================================================='
print '''
The gray-scale image of the beef steak is read.
'''
print '========================================================================='
#0
print '''
a = readgray('beef.tif');
show(a);'''
a = readgray('beef.tif');
show(a);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The input image is simplified by the application of a a small
closing. The dark area (inner lean part) is closed from the fat
white area.
'''
print '========================================================================='
#0
print '''
b=close(a,sedisk(2));
show(b);'''
b=close(a,sedisk(2));
show(b);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The external marker is built from the detection of the complete beef
region and the extraction of its internal edge. As the beef is dark,
it is detected by a low value threshold. After this threshold, small
residual regions are eliminated by the binary areaclose operator.
'''
print '========================================================================='
#0
print '''
c = threshad(a,uint8(10));
d = areaclose(c,200);
show(d);'''
c = threshad(a,uint8(10));
d = areaclose(c,200);
show(d);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The internal edge generated is 13 points thick. It is created by the
residues of an erosion by a large structuring element.
'''
print '========================================================================='
#0
print '''
e = gradm(d,secross(1),sebox(13));
show(e);'''
e = gradm(d,secross(1),sebox(13));
show(e);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The internal marker is a severe erosion of the steak. Both markers
are combined by union and displayed as overlay on the gradient image
'''
print '========================================================================='
#0
print '''
f= erode(d,secross(80));
g = union(e,f);
h = gradm(b);
show(h,g);'''
f= erode(d,secross(80));
g = union(e,f);
h = gradm(b);
show(h,g);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Constrained watershed of the gradient of the smoothed image,
restricted to the internal and external markers
'''
print '========================================================================='
#0
print '''
i=cwatershed(h,g);
show(i);'''
i=cwatershed(h,g);
show(i);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Superposition of the dilated detected contour on the original image.
'''
print '========================================================================='
#0
print '''
show(a,dilate(i));'''
show(a,dilate(i));
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# blob - Demonstrate blob measurements and display.
#
# =========================================================================
def blob():
print
print '''Demonstrate blob measurements and display.'''
print
#
print '========================================================================='
print '''
The binary image is read and then labeled. The number of blobs is
measured as the maximum label value. Both images are displayed.
'''
print '========================================================================='
#0
print '''
f = readgray('blob3.tif')
fr = label(f)
show(f)
lblshow(fr,'border')
nblobs=stats(fr,'max')
print nblobs'''
f = readgray('blob3.tif')
fr = label(f)
show(f)
lblshow(fr,'border')
nblobs=stats(fr,'max')
print nblobs
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The centroids are computed from the labeled image. After, the
centroid image is labeled, so that each centroid point has a label
value varying from 1 to the maximum number of blobs. For display
illustration, the centroids are overlayed on the original blob image
on the left and the labeled centroids are enlarged and displayed on
the right.
'''
print '========================================================================='
#0
print '''
c = blob(fr,'centroid')
cr = label(c)
show(f,c)
lblshow(dilate(cr))'''
c = blob(fr,'centroid')
cr = label(c)
show(f,c)
lblshow(dilate(cr))
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
To place a particular number on a particular blob, a number image is
generated using the function and converted to a structuring element.
A particular centroid is selected by comparing the image with the
labeled number. This output image is a binary image with a single
point at that centroid. Dilating this image by the structuring
element will "stamp" the structuring element on the centroid.
'''
print '========================================================================='
#0
print '''
fbin = cmp(cr,'==',uint16(5))
f5 = text('5')
print f5
b5 = img2se(f5)
fb5 = dilate(fbin,b5)
show(dilate(fbin))
show(f,fb5)'''
fbin = cmp(cr,'==',uint16(5))
f5 = text('5')
print f5
b5 = img2se(f5)
fb5 = dilate(fbin,b5)
show(dilate(fbin))
show(f,fb5)
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
To automate the process just described, a loop scans every label
value and "stamp" its number in a final image. The stamps are
accumulated with the function. The area is computed and plotted
against each label blob number.
'''
print '========================================================================='
#0
print '''
facc=subm(f,f)
for i in range(1,nblobs+1):
fbin = cmp(cr,'==',uint16(i))
fi = text(str(i))
bi = img2se(fi)
fbi = dilate(fbin,bi)
facc = union(facc,fbi)
show(f,facc)
darea = blob(fr,'area','data')
plot([[darea]], [['style','impulses']])'''
facc=subm(f,f)
for i in range(1,nblobs+1):
fbin = cmp(cr,'==',uint16(i))
fi = text(str(i))
bi = img2se(fi)
fbi = dilate(fbin,bi)
facc = union(facc,fbi)
show(f,facc)
darea = blob(fr,'area','data')
plot([[darea]], [['style','impulses']])
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# brain - Extract the lateral ventricle from an MRI image of the brain.
#
# =========================================================================
def brain():
print
print '''Extract the lateral ventricle from an MRI image of the brain.'''
print
#
print '========================================================================='
print '''
The MRI image of a brain slice is read.
'''
print '========================================================================='
#0
print '''
a = readgray('mribrain.tif');
show(a);'''
a = readgray('mribrain.tif');
show(a);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The ventricle is enhanced using an opening with a disk of radius 10
followed by a reconstruction.
'''
print '========================================================================='
#0
print '''
b = open(a,sedisk(10));
c = infrec(b,a);
show(b);
show(c);'''
b = open(a,sedisk(10));
c = infrec(b,a);
show(b);
show(c);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The result of the open by reconstruction is subtracted from the
original image. Note that the three operations: open, reconstruction
and the subtraction could be done at once using the (open by
reconstruction top-hat) function. On the right, the enhanced
ventricle is thresholded.
'''
print '========================================================================='
#0
print '''
d = subm(a,c);
show(d);
e = cmp(d,'>=',uint8(50));
show(e);'''
d = subm(a,c);
show(d);
e = cmp(d,'>=',uint8(50));
show(e);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Finally, the ventricle is selected as the connected object with area
larger than 70 pixels. For visualization purposes, the result of the
segmentation is overlayed on the original brain image.
'''
print '========================================================================='
#0
print '''
f= areaopen(e,70);
show(f);
show(a,f);'''
f= areaopen(e,70);
show(f);
show(a,f);
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# calc - Extract the keys of a calculator.
#
# =========================================================================
def calc():
print
print '''Extract the keys of a calculator.'''
print
#
print '========================================================================='
print '''
The gray-scale image of the calculator is read.
'''
print '========================================================================='
#0
print '''
a = readgray('keyb.tif');
show(a);'''
a = readgray('keyb.tif');
show(a);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The image edges are enhanced by the gradient operator.
'''
print '========================================================================='
#0
print '''
b = gradm(a, sebox());
show(b);'''
b = gradm(a, sebox());
show(b);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The opening top-hat procedure enhances the small objects relatively
to its background. In the calculator image, the digits are enhanced.
'''
print '========================================================================='
#0
print '''
c = openth(a,sebox(5));
show(c);'''
c = openth(a,sebox(5));
show(c);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The threshold operator is used to separated the enhanced objects.
This procedure is quite robust, since the background was reduced to
very low levels with the opening top-hat.
'''
print '========================================================================='
#0
print '''
d = threshad(c, uint8(150));
show(d);'''
d = threshad(c, uint8(150));
show(d);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
In order to have just one object (i.e., connected component) inside
each key, a dilation is applied.
'''
print '========================================================================='
#0
print '''
e = dilate(d, sebox(3));
show(e);'''
e = dilate(d, sebox(3));
show(e);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The outside markers are built by taking the watershed (skiz) of the
complement of internal markers image.
'''
print '========================================================================='
#0
print '''
f = watershed(neg(e));
show(f);'''
f = watershed(neg(e));
show(f);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The markers used are the union of the internal and external markers
detected. They are displayed as overlay on the gradient image.
'''
print '========================================================================='
#0
print '''
g = union(e,f);
show(b,g);'''
g = union(e,f);
show(b,g);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The calculator keys are extracted by applying the watershed operator
on the gradient image, constrained by the markers detected.
'''
print '========================================================================='
#0
print '''
h = cwatershed(b,g,sebox());
show(h);'''
h = cwatershed(b,g,sebox());
show(h);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
Superposition of the detected contours on the input image.
'''
print '========================================================================='
#0
print '''
show(a,h);'''
show(a,h);
print
raw_input(4*' '+'Please press return to continue...')
print
print
#
return
# =========================================================================
#
# cells - Extract blood cells and separate them.
#
# =========================================================================
def cells():
print
print '''Extract blood cells and separate them.'''
print
#
print '========================================================================='
print '''
First, the blood cells image is read. Then, the gray-scale area open
operator is applied for removing small white pores over the cells.
'''
print '========================================================================='
#0
print '''
a = readgray('bloodcells.tif');
show(a);
b = areaopen(a, 200);
show(b);'''
a = readgray('bloodcells.tif');
show(a);
b = areaopen(a, 200);
show(b);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''
The threshold of dark areas produces the segmented image (i.e., the
region where there are cells). Then the opening by a small disk
performs smoothing of the cells borders.
'''
print '========================================================================='
#0
print '''
c = cmp( uint8(0), '<=', b, '<=', uint8(140));
show(c);
d = open(c,sedisk(2,'2D','OCTAGON'));
show(d);'''
c = cmp( uint8(0), '<=', b, '<=', uint8(140));
show(c);
d = open(c,sedisk(2,'2D','OCTAGON'));
show(d);
print
raw_input(4*' '+'Please press return to continue...')
print
print
##
print '========================================================================='
print '''