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
|
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chapter 9: Image Compression"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 9.59: Program_performs_Block_Truncation_Coding.sce"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"//Caption: Program performs Block Truncation Coding(BTC) by choosing different \n",
"//block sizes\n",
"//Fig.9.59: MATLAB Example1\n",
"//page514\n",
"close;\n",
"clc;\n",
"x =imread('E:\Digital_Image_Processing_Jayaraman\Chapter9\lenna.jpg'); //SIVP toolbox\n",
"//x=imresize(x,[256 256]);\n",
"x1=x;\n",
"x=double(x);\n",
"[m1 n1]=size(x);\n",
"blk=input('Enter the block size:');\n",
"for i = 1 : blk : m1 \n",
"for j = 1 : blk : n1 \n",
" y = x(i:i+(blk-1),j:j+(blk-1)) ; \n",
" m = mean(mean(y)); \n",
" sig=std2(y);\n",
" b = y > m ; //the binary block \n",
" K = sum(sum(b)); \n",
" if (K ~= blk^2 ) & ( K ~= 0) \n",
" ml = m-sig*sqrt(K/((blk^2)-K)); \n",
" mu = m+sig*sqrt(((blk^2)-K)/K); \n",
" x(i:i+(blk-1), j:j+(blk-1)) = b*mu+(1- b)*ml; \n",
" end \n",
"end \n",
"end \n",
"//imshow(uint8(x))\n",
"//title('Reconstructed Image')\n",
"x = uint8(x);\n",
"figure(1)\n",
"imshow(x1)\n",
"title('Original Image'); //IPD toolbox\n",
"figure(2)\n",
"ShowImage(x, 'Reconstructed Image'); //IPD toolbox\n",
"title('Block Size = 8')"
]
}
,
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 9.9: Program_performs_Block_Truncation_Coding_BTC.sce"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"//Caption: Program performs Block Truncation Coding(BTC) \n",
"//Example 9.9\n",
"//page512\n",
"close;\n",
"clear;\n",
"clc;\n",
"x = [65,75,80,70;72,75,82,68;84,72,62,65;66,68,72,80];\n",
"disp(x,'Original Block is x =')\n",
"[m1 n1]=size(x);\n",
"blk=input('Enter the block size:');\n",
"for i = 1 : blk : m1 \n",
"for j = 1 : blk : n1 \n",
" y = x(i:i+(blk-1),j:j+(blk-1)) ; \n",
" m = mean(mean(y)); \n",
" disp(m,'mean value is m =')\n",
" sig=std2(y);\n",
" disp(sig,'Standard deviation of the block is =')\n",
" b = y > m ; //the binary block \n",
" disp(b,'Binary allocation matrix is B=')\n",
" K = sum(sum(b)); \n",
" disp(K,'number of ones =')\n",
" if (K ~= blk^2 ) & ( K ~= 0) \n",
" ml = m-sig*sqrt(K/((blk^2)-K)); \n",
" disp(ml,'The value of a =')\n",
" mu = m+sig*sqrt(((blk^2)-K)/K); \n",
" disp(mu,'The value of b =')\n",
" x(i:i+(blk-1), j:j+(blk-1)) = b*mu+(1- b)*ml; \n",
" end \n",
"end \n",
"end \n",
"disp(round(x),'Reconstructed Block is x =')\n",
"//Result\n",
"//Original Block is x = \n",
"// \n",
"// 65. 75. 80. 70. \n",
"// 72. 75. 82. 68. \n",
"// 84. 72. 62. 65. \n",
"// 66. 68. 72. 80. \n",
"// \n",
"//Enter the block size:4\n",
"//mean value is m = 72.25 \n",
"//Standard deviation of the block is = 6.6282225 \n",
"//Binary allocation matrix is B= \n",
"// \n",
"// F T T F \n",
"// F T T F \n",
"// T F F F \n",
"// F F F T \n",
"// \n",
"//number of ones = 6\n",
"//The value of a = 67.115801 \n",
"//The value of b = 80.806998 \n",
"//Reconstructed Block is x = \n",
"// \n",
"// 67. 81. 81. 67. \n",
"// 67. 81. 81. 67. \n",
"// 81. 67. 67. 67. \n",
"// 67. 67. 67. 81. "
]
}
],
"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
}
|