- 325
- 0
- 约3.14千字
- 约 5页
- 2017-01-06 发布于江西
- 举报
图像倾斜校正_基于MATLAB
目的:
实现对图像的倾斜校正。
方法一:
利用霍夫变换,代码如下:
clear,clc,close all;
I=imread(1.jpg);
bw=rgb2gray(I);
bw=im2bw(I,graythresh(bw));
bw=double(bw);
BW=edge(bw,canny);
imshow(BW);title(canny 边界图像);
[H,T,R]=hough(BW);
figure,imshow(H,[],XData,T,YData,R,InitialMagnification,fit);
xlabel(\theta),ylabel(\rho);
axis on, axis normal,hold on;
P=houghpeaks(H,4,threshold,ceil(0.3*max(H(:))));
x=T(P(:,2)); y = R(P(:,1));
plot(x,y,s,color,white);
lines=houghlines(BW,T,R,P,FillGap,50,MinLength,7);
figure,imshow(BW),title(直线标识图像);
max_len = 0;
hold on;
for k=1:length(lines)
xy=[lines(k).point1;lines(k).point2];
% 标出线段
plot(xy(:,1),xy(:,2),LineWidth,2,Color,green);
% 标出线段的起始和终端点
plot(xy(1,1),xy(1,2),x,LineWidth,2,Color,yellow);
plot(xy(2,1),xy(2,2),x,LineWidth,2,Color,red);
len=norm(lines(k).point1-lines(k).point2);
Len(k)=len;
if (lenmax_len)
max_len=len;
xy_long=xy;
end
end
% 强调最长的部分
plot(xy_long(:,1),xy_long(:,2),LineWidth,2,Color,blue);
[L1 Index1]=max(Len(:));
% 最长线段的起始和终止点
x1=[lines(Index1).point1(1) lines(Index1).point2(1)];
y1=[lines(Index1).point1(2) lines(Index1).point2(2)];
% 求得线段的斜率
K1=-(lines(Index1).point1(2)-lines(Index1).point2(2))/...
(lines(Index1).point1(1)-lines(Index1).point2(1))
angle=atan(K1)*180/pi
A = imrotate(I,-angle,bilinear);% imrate 是逆时针的所以取一个负号
figure,imshow(A);
结果:
方法二:
由于这里的图形比较规则,可针对性地对图形进行边缘检测,求倾斜角,再根据角度进行校正。代码如下:
clear all; clc; close all;
Img = imread(c:\\ce.jpg);
figure;
subplot(2, 2, 1); imshow(Img); title(原图);
I = rgb2gray(Img);
subplot(2, 2, 2); imshow(I); title(灰度图像);
bw = im2bw(I, graythresh(I));
bw = edge(bw, canny);
subplot(2, 2, 3); imshow(bw); title(canny边界图像);
[r, c] = find(bw);
[rmin, indr] = min(r);
[cmin, indc] = min(c);
p1 = [rmin, c(indr)];
p2 = [r(indc) cmin];
hold on;
plot([p1(2) p2(2)], [p1(1) p2(1)], r-o);
k = (p2(1)-p1(1))/(p2(2)-p1(2));
theta = atan(k)/pi*180;
I1(:, :, 1) = imrotate(Img(:, :, 1), theta, bilinear);
I1(:, :, 2) = imrotate(Img(:, :, 2), theta,
您可能关注的文档
- 2016中山淘贝电子商务有限公司《员工手册》.doc
- 2016组合导航系统复习题.doc
- 20080925审后修改水资源评价报告.doc
- An analysis of the problems and insufficiency in oral English teaching 英语口语教学调查与研究.doc
- android的电子书阅读器.doc
- bbs软件工程论文.doc
- CNG加气站工艺流程和主要设备.doc
- C语言程序设计-航班管理系统.doc
- EDA课程设计---基于FPGA的洗衣机控制器的设计.docx
- EDA课设抢答器.docx
- 【上交所-2026研报】上海锦和商业经营管理(集团)股份有限公司2025年年度报告.pdf
- 【上交所-2026研报】横店影视股份有限公司2025年年度报告.pdf
- 【港交所-2026研报】比特元宇宙 中期报告 2025-2026.pdf
- 【上交所-2026研报】晶方科技2025年年度报告.pdf
- 【蔚云科技-2026研报】2025亚马逊【自动割草机】行业分析年度研究.pdf
- 【港交所-2026研报】智升集团控股 中期报告2025-26.pdf
- 【上交所-2026研报】2025年年度报告.pdf
- 【世界卫生组织-2026研报】Recommended composition of influenza virus vaccines for use in the 2026-2027 northern hemisphere influenza season.pdf
- 【港交所-2026研报】WT集团 2025-2026 中期报告.pdf
- 【港交所-2026研报】新世界发展 中期报告 2025-2026.pdf
最近下载
- 第二章-多媒体数据压缩技术.ppt VIP
- 2026年春季统编版(部编版)2024新教材二年级下册道德与法治教学计划、教学设计及教学反思(附目录).pdf
- 24.抽取文本汇词云(教学课件)-四年级信息科技全一册 (人教版2024).pptx VIP
- 2025年军队文职人员统一招聘面试( 航空航天)题库附答案.doc VIP
- PLC基础知识大全培训PPT课件.pptx VIP
- 《高中数学•同步课堂学与练》高二(人教B版选修第二册)第05讲 正态分布(解析版).pdf VIP
- 2025年支部书记抓基层党建工作述职报告范文.docx VIP
- 高教社2023马工程国际私法学教学课件u5.pptx VIP
- 学生宿舍卫生检查表.docx VIP
- 年末存货盘点表.docx VIP
原创力文档

文档评论(0)