summaryrefslogtreecommitdiff
path: root/Digital_Image_Processing_by_S_Jayaraman/7-Image_Segmentation.ipynb
blob: ccdb07940ff26d6503337b9d433039764f1e574e (plain)
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
{
"cells": [
 {
		   "cell_type": "markdown",
	   "metadata": {},
	   "source": [
       "# Chapter 7: Image Segmentation"
	   ]
	},
{
		   "cell_type": "markdown",
		   "metadata": {},
		   "source": [
			"## Example 7.23: Scilab_code_for_Differentiation_of_Gaussian_function.sce"
		   ]
		  },
  {
"cell_type": "code",
	   "execution_count": null,
	   "metadata": {
	    "collapsed": true
	   },
	   "outputs": [],
"source": [
"//Caption: Scilab code for Differentiation of Gaussian function\n",
"//Fig7.23\n",
"//page388\n",
"clc;\n",
"close;\n",
"sigma=input('Enter the value of sigma:')\n",
"i=-10:.1:10;\n",
"j=-10:.1:10;\n",
"r=sqrt(i.*i+j.*j);\n",
"y=(1/(sigma^2))*(((r.*r)/sigma^2)-1).*exp(-r.*r/2*sigma^2);\n",
"plot(i,y)\n",
"legend(sprintf('The sigma value is %g',sigma))\n",
"xtitle('Differentiation of Gaussian function')"
   ]
   }
,
{
		   "cell_type": "markdown",
		   "metadata": {},
		   "source": [
			"## Example 7.25: Scilab_code_for_Differentiation_of_Gaussian_Filter_function.sce"
		   ]
		  },
  {
"cell_type": "code",
	   "execution_count": null,
	   "metadata": {
	    "collapsed": true
	   },
	   "outputs": [],
"source": [
"//Caption: Scilab code for Differentiation of Gaussian Filter function\n",
"//Fig7.25\n",
"//page389\n",
"clc;\n",
"close;\n",
"sigma1 = input('Enter the value of sigma1:')\n",
"sigma2 = input('Enter the value of sigma2:')\n",
"i=-10:.1:10;\n",
"j=-10:.1:10;\n",
"r=sqrt(i.*i+j.*j);\n",
"y1 = (1/(sigma1^2))*(((r.*r)/sigma1^2)-1).*exp(-r.*r/2*sigma1^2);\n",
"y2 = (1/(sigma2^2))*(((r.*r)/sigma2^2)-1).*exp(-r.*r/2*sigma2^2);\n",
"y = y1-y2;\n",
"plot(i,y)\n",
"xtitle('Shape of DOG Filter')\n",
"//Result\n",
"//Enter the value of sigma1: 4\n",
"//Enter the value of sigma2: 1\n",
"// "
   ]
   }
,
{
		   "cell_type": "markdown",
		   "metadata": {},
		   "source": [
			"## Example 7.27: Scilab_code_for_Edge_Detection_using_Different_Edge_detectors.sce"
		   ]
		  },
  {
"cell_type": "code",
	   "execution_count": null,
	   "metadata": {
	    "collapsed": true
	   },
	   "outputs": [],
"source": [
"//Caption: Scilab code for Edge Detection using Different Edge detectors \n",
"//[1]. Sobel [2].Prewitt [3].Log  [4].Canny\n",
"//Fig7.27\n",
"//page389\n",
"close;\n",
"clc;\n",
"a = imread('E:\DIP_JAYARAMAN\Chapter7\sailing.jpg');\n",
"a = rgb2gray(a);\n",
"c = edge(a,'sobel');\n",
"d = edge(a,'prewitt');\n",
"e = edge(a,'log');\n",
"f = edge(a,'canny');\n",
"ShowImage(a,'Original Image')\n",
"title('Original Image')\n",
"figure\n",
"ShowImage(c,'Sobel')\n",
"title('Sobel')\n",
"figure\n",
"ShowImage(d,'Prewitt')\n",
"title('Prewitt')\n",
"figure\n",
"ShowImage(e,'Log')\n",
"title('Log')\n",
"figure\n",
"ShowImage(f,'Canny')\n",
"title('Canny')"
   ]
   }
,
{
		   "cell_type": "markdown",
		   "metadata": {},
		   "source": [
			"## Example 7.30: Scilab_code_to_perform_watershed_transform.sce"
		   ]
		  },
  {
"cell_type": "code",
	   "execution_count": null,
	   "metadata": {
	    "collapsed": true
	   },
	   "outputs": [],
"source": [
"//Caption: Scilab code to perform watershed transform\n",
"//Fig7.30\n",
"//Page396\n",
"clc;\n",
"close;\n",
"b = imread('E:\DIP_JAYARAMAN\Chapter7\teaset.png');\n",
"a = rgb2gray(b);\n",
"global EDGE_SOBEL;\n",
"Gradient = EdgeFilter(a, EDGE_SOBEL);\n",
"Threshold1 = CalculateOtsuThreshold(Gradient); // determine a threshold\n",
"EdgeImage = ~SegmentByThreshold(Gradient,Threshold1);\n",
"DistanceImage = DistanceTransform(EdgeImage);\n",
"Threshold2 = CalculateOtsuThreshold(DistanceImage) // determine a threshold\n",
"ThresholdImage = SegmentByThreshold(DistanceImage,Threshold2);\n",
"MarkerImage = SearchBlobs(ThresholdImage);\n",
"SegmentedImage = Watershed(Gradient,MarkerImage);\n",
"figure\n",
"ShowColorImage(b,'teaset')\n",
"title('teaset.png')\n",
"figure\n",
"ColorMapLength = length(unique(SegmentedImage));\n",
"ShowImage(SegmentedImage,'Result of Watershed Transform',jetcolormap(ColorMapLength)); "
   ]
   }
],
"metadata": {
		  "kernelspec": {
		   "display_name": "Scilab",
		   "language": "scilab",
		   "name": "scilab"
		  },
		  "language_info": {
		   "file_extension": ".sce",
		   "help_links": [
			{
			 "text": "MetaKernel Magics",
			 "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
			}
		   ],
		   "mimetype": "text/x-octave",
		   "name": "scilab",
		   "version": "0.7.1"
		  }
		 },
		 "nbformat": 4,
		 "nbformat_minor": 0
}