Update to 2.0.0 tree from current Fremantle build
[opencv] / samples / octave / morphology.m
1 #! /usr/bin/env octave
2 cv;
3 highgui;
4
5 global src;
6 global image
7 global element
8 global element_shape
9 global global_pos;
10 global dest;
11 src = 0;
12 image = 0;
13 dest = 0;
14 element = 0;
15 element_shape = CV_SHAPE_RECT;
16 global_pos = 0;
17
18 function Opening(pos)
19   global src;
20   global image
21   global element
22   global element_shape
23   global global_pos;
24   global dest;
25   element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
26   cvErode(src,image,element,1);
27   cvDilate(image,dest,element,1);
28   cvShowImage("Opening&Closing window",dest);
29 endfunction
30 function Closing(pos)
31   global src;
32   global image
33   global element
34   global element_shape
35   global global_pos;
36   global dest;
37   element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
38   cvDilate(src,image,element,1);
39   cvErode(image,dest,element,1);
40   cvShowImage("Opening&Closing window",dest);
41 endfunction
42 function Erosion(pos)
43   global src;
44   global image
45   global element
46   global element_shape
47   global global_pos;
48   global dest;
49   element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
50   cvErode(src,dest,element,1);
51   cvShowImage("Erosion&Dilation window",dest);
52 endfunction
53 function Dilation(pos)
54   global src;
55   global image
56   global element
57   global element_shape
58   global global_pos;
59   global dest;
60   element = cvCreateStructuringElementEx( pos*2+1, pos*2+1, pos, pos, element_shape, [] );
61   cvDilate(src,dest,element,1);
62   cvShowImage("Erosion&Dilation window",dest);
63 endfunction
64
65 filename = "../c/baboon.jpg";
66 if (size(argv, 1)==1)
67   filename = argv(){1};
68 endif
69 src = cvLoadImage(filename,1);
70 if (! swig_this(src))
71   exit(-1);
72 endif
73
74 image = cvCloneImage(src);
75 dest = cvCloneImage(src);
76 cvNamedWindow("Opening&Closing window",1);
77 cvNamedWindow("Erosion&Dilation window",1);
78 cvShowImage("Opening&Closing window",src);
79 cvShowImage("Erosion&Dilation window",src);
80 cvCreateTrackbar("Open","Opening&Closing window",global_pos,10,@Opening);
81 cvCreateTrackbar("Close","Opening&Closing window",global_pos,10,@Closing);
82 cvCreateTrackbar("Dilate","Erosion&Dilation window",global_pos,10,@Dilation);
83 cvCreateTrackbar("Erode","Erosion&Dilation window",global_pos,10,@Erosion);
84 cvWaitKey(0);
85 cvDestroyWindow("Opening&Closing window");
86 cvDestroyWindow("Erosion&Dilation window");