图像处理之霍夫变换Word文件下载.docx
- 文档编号:20613131
- 上传时间:2023-01-24
- 格式:DOCX
- 页数:15
- 大小:140.43KB
图像处理之霍夫变换Word文件下载.docx
《图像处理之霍夫变换Word文件下载.docx》由会员分享,可在线阅读,更多相关《图像处理之霍夫变换Word文件下载.docx(15页珍藏版)》请在冰豆网上搜索。
[java]
viewplaincopy
1.//
prepare
for
hough
transform
2.int
centerX
=
width
/
2;
3.int
centerY
height
4.double
hough_interval
PI_VALUE/(double)hough_space;
5.
6.int
max
Math.max(width,
height);
7.int
max_length
(int)(Math.sqrt(2.0D)
*
max);
8.hough_1d
new
int[2
hough_space
max_length];
实现从像素RGB空间到霍夫空间变换的代码为:
start
now....
2.int[][]
image_2d
convert1Dto2D(inPixels);
3.for
(int
row
0;
<
height;
row++)
{
4.
col
width;
col++)
int
p
image_2d[row][col]
&
0xff;
6.
if(p
==
0)
continue;
//
which
means
background
color
7.
8.
since
we
does
not
know
the
theta
angle
and
r
value,
9.
have
to
calculate
all
space
each
pixel
point
10.
then
got
possible
pair.
11.
x
cos(theta)
+
y
sin(theta)
12.
for(int
cell=0;
cell
hough_space;
cell++
)
13.
(int)((col
-
centerX)
Math.cos(cell
hough_interval)
(row
centerY)
Math.sin(cell
hough_interval));
14.
+=
max_length;
from
zero,
(-max_length)
15.
if
(max
0
||
>
2
max_length))
{//
make
sure
did
out
of
scope[0,
2*max_lenght]
16.
17.
}
18.
hough_2d[cell][max]
+=1;
19.
20.
21.}
寻找最大霍夫值计算霍夫阈值的代码如下:
find
value
max_hough
3.for(int
i=0;
i<
i++)
j=0;
j<
2*max_length;
j++)
hough_1d[(i
j
hough_space)]
hough_2d[i][j];
if(hough_2d[i][j]
max_hough)
10.}
11.System.out.println("
MAX
HOUGH
VALUE
"
max_hough);
13.//
transfer
back
image
pixels
parameter
14.int
hough_threshold
(int)(threshold
从霍夫空间反变换回像素数据空间代码如下:
if(hough_2d[row][col]
hough_threshold)
discard
it
hough_value
hough_2d[row][col];
boolean
isLine
true;
i=-1;
j=-1;
if(i
!
yf
i;
xf
j;
if(xf
2*max_length)
(yf
hough_space)
-=
21.
22.
if(hough_2d[yf][xf]
hough_value)
23.
24.
25.
false;
26.
break;
27.
28.
29.
30.
31.
if(!
isLine)
32.
33.
data
now...
34.
double
dy
Math.sin(row
hough_interval);
35.
dx
Math.cos(row
36.
((row
4)
3
4))
37.
subrow
++subrow)
38.
subcol
((subrow
dy))
dx)
centerX;
39.
((subcol
width)
(subcol
0))
40.
image_2d[subrow][subcol]
-16776961;
41.
42.
43.
else
44.
++subcol)
45.
dx))
dy)
centerY;
46.
height)
(subrow
47.
48.
49.
50.
51.
52.}
霍夫变换源图如下:
霍夫变换以后,在霍夫空间显示如下:
(白色表示已经找到直线信号)
最终反变换回到像素空间效果如下:
一个更好的运行监测直线的结果(输入为二值图像):
完整的霍夫变换源代码如下:
1.package
com.gloomyfish.image.transform;
2.
3.import
java.awt.image.BufferedImage;
5.import
com.process.blur.study.AbstractBufferedImageOp;
7.public
class
HoughLineFilter
extends
AbstractBufferedImageOp
public
final
static
PI_VALUE
Math.PI;
private
500;
int[]
hough_1d;
int[][]
hough_2d;
float
threshold;
scale;
offset;
HoughLineFilter()
default
parameters
scale
1.0f;
offset
0.0f;
threshold
0.5f;
void
setHoughSpace(int
space)
this.hough_space
space;
getThreshold()
return
setThreshold(float
threshold)
this.threshold
getScale()
setScale(float
scale)
this.scale
getOffset()
52.
setOffset(float
offset)
53.
this.offset
54.
55.
56.
@Override
57.
BufferedImage
filter(BufferedImage
src,
dest)
58.
src.getWidth();
59.
src.getHeight();
60.
61.
(
dest
null
62.
createCompatibleDestImage(
);
63.
64.
inPixels
int[width*height];
65.
outPixels
66.
getRGB(
0,
width,
height,
67.
houghTransform(inPixels,
outPixels);
68.
setRGB(
dest,
69.
dest;
70.
71.
72.
houghTransform(int[]
inPixels,
outPixels)
73.
74.
75.
76.
77.
78.
79.
80.
hough_1d
81.
82.
define
temp
2D
array
initialize
83.
hough_2d
int[hough_space][2*max_length];
84.
85.
86.
hough_2d[i][j]
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.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像 处理 变换