matlab中校正函数,matlab_关于倾斜校正的函数 | 学步园

对于简单的图像用简单的方法没有涉及到hough,radon。

但一定涉及一个函数imrotate;

B = imrotate(A,angle)B =imrotate(A,angle,method)B =imrotate(A,angle,method,bbox)

第一个用法围绕着图像的中心点以逆时针的方向旋转angle角度,如果想要顺时针方向旋转图像的话,那么可以指定角度的值为负。Imrotate输出图像能够包围整个图像。插值方法采用的最近邻域插值。

第二个用法增加了一个参数method。Method指定插值的方式,{‘nearest/bilinear/bicubic’}。

第三个方法另增加了一个参数,指定了返回图像的大小{},crop:使输入图像和输出图像大小相等。Loose:使输出图像能够包含整个旋转的图像。

既然是采用hough变换,那么也要用hough函数

[H, theta, rho] = hough(BW)[H, theta, rho] = hough(BW, ParameterName,ParameterValue)

得到的矩阵中H是标准hough变换得到的结果(需要了解hough变换的原理),即把参数空间分成一个个累加单元,对图像空间的每个点进行计算然后划分到每个每个累加单元,最后从累加单元所累加得到的值。其中列是角度,行是极径。theta是角度,rho是极径都是相应的矢量,就是

,构成H的坐标范围。第二个式子顾名思义,parametername指的是角度还是径值可以取rhoresolution,即径的分辨率指定一个介于0到size(bw)的值(是标量),而取Theta的时候,指定了H对应的列数,可取-90到90之间。默认是-90到89。

其实要明白这些也很简单,doc hough,用里面的示范程序运行一下,然后看看workspace里的变量值,就一目了然了。

imshow(..., param1, val1, param2, val2,...)

imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit')

imshow的超长用法,H不用说了就是要显示的图像矩阵,[]:指定了显示图像的动态范围,若是空则上下界限为H的最大值(白)和最小值(黑),接下来(前面的也是)就一个parameter一个value,省略parameter也是没有关系的,顺序也可以随意。InitialMagnification:参数值可以是一个值或是fit,指定显示图像的放大倍数,100是原图,fit使图像适应屏幕。XData,值是两个元素(也可以多于两个元素,但只有第一和最后一个元素用到)的矢量用来建立X轴的非默认空间坐标。YData也类似。同时还有其他许多的参数没有翻译,到时用到在去看看。

ceil,floor,round,fix.

ceil(x):向正无穷大取整。floor(x):向负无穷大取整。round(x):向最近的整数取整。

fix(x):向零取整

Matlab取整函数有: fix,floor, ceil, round.具体应用方法如下:

fix朝零方向取整,如fix(-1.3)=-1; fix(1.3)=1;

floor,顾名思义,就是地板,所以是取比它小的整数,即朝负无穷方向取整,如floor(-1.3)=-2;floor(1.3)=1;floor(-1.8)=-2,floor(1.8)=1;

ceil,与floor相反,它的意思是天花板,也就是取比它大的最小整数,即朝正无穷方向取整,如ceil(-1.3)=-1; ceil(1.3)=2;ceil(-1.8)=-1,ceil(1.8)=2

round四舍五入到最近的整数,

如round(-1.3)=-1;round(-1.52)=-2;round(1.3)=1;round(1.52)=2。

peaks = houghpeaks(H, numpeaks)

peaks = houghpeaks(..., param1, val1, param2, val2)

第一个式子是锁定H中峰值,numpeaks:图像中峰值的个数默认为1,返回的peaks是每一个峰值的行号和列号。

第二个也是类似以前的parameter,value。‘threshold’:顾名思义是被当做是峰值说设置的阈值。默认是0.5*max(H (:)),NHoodsize :包含两个正奇整数的向量。就是峰值附近被设置为的个数。默认大于或等于size (H )/50.

lines = houghlines(BW,theta, rho, peaks)

lines= houghlines(..., param1, val1, param2, val2)

theta,rho是有hough函数得到的矢量。peaks是有houghpeak得到的。返回的是结构体数组,数组的长度找到线段的个数。每个结构体都有四个元素,point1,point2:是指定线段起始点的坐标。另外theta和rho是累加器单元的值。

R = radon(I, theta)

[R,xp] = radon(...)

第一个式子返回每个theta角度的radon变换(沿着某一角度对图像进行的投影。)。R为宜矩阵,每一列代表的是某一角度的投影。theta默认是0:179。

第二个式子:xp是对应R每一个行的射线的坐标。

Radon 变换检测倾斜角度的原理是:对倾斜的车牌图像在一定的倾斜角度范围内进行

Radon 变换,统计在每个角度投影后所得到的投影值为0 的数目,并取数目最多所在的角度为车牌的倾斜角度。

imrotate

Rotate image

Syntax

B = imrotate(A,angle)

B = imrotate(A,angle,method)

B = imrotate(A,angle,method,bbox)

Description

B = imrotate(A,angle) rotatesimage A by angle degrees in a counterclockwise direction around its centerpoint. To rotate the image clockwise, specify a negative value for angle.imrotate makes the output image B large

enough to contain the entire rotatedimage. imrotate uses nearest neighbor interpolation, setting the values ofpixels in B that are outside the rotated image to 0 (zero).

B = imrotate(A,angle,method)rotates image A, using the interpolation method specified by method. method isa text string that can have one of these values. The default value is enclosedin braces ({}).

Value

Description

{'nearest'}

Nearest-neighbor interpolation

'bilinear'

Bilinear interpolation

'bicubic'

Bicubic interpolation

Note   Bicubic interpolation can produce pixel values outside the original range.

B =imrotate(A,angle,method,bbox) rotates image A, where bbox specifies the size ofthe returned image. bbox is a text string that can have one of the followingvalues. The default value is enclosed in braces ({}).

Value

Description

'crop'

Make output image B the same size as the input image A, cropping the rotated image to fit

{'loose'}

Make output image B large enough to contain the entire rotated image. B is generally larger than A.

Class Support

The input image can be numeric or logical. The outputimage is of the same class as the input image.

Performance Note

This function may take advantage of hardwareoptimization for data types uint8, uint16, and single to run faster.

Examples

Read a solar spectra image, stored in FITS format, androtate the image to bring it into horizontal alignment. A rotation of -1 degreeis all that is required.

I = fitsread('solarspectra.fts');

I = mat2gray(I);

J = imrotate(I,-1,'bilinear','crop');

figure, imshow(I)

figure, imshow(J)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值