加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

使用Matlab对图片进行平行四边形式的平移

(2014-12-20 19:57:44)
标签:

matlab

图片编辑

偏移

平行四边形

分类: matlab
今天写论文,发现要画一个流程图,需要对图像进行操作,也就是平移一下,写了一个Matlab程序实现了4种平移效果,效果如下
向上偏移

不多说了,上代码:

实现向左右偏移matlab代码:
%% little fun by Heng Fan
function II = transform(imagename, theta)
%% I --- 原始图像
%% theta --- 拉伸角度
%% II --- 变换后的图像

I = imread(imagename);
[height, width, channel] = size(I);
b = fix(tan(theta*pi/180) * height);
new_width = width + b;
new_height = height;
II = zeros(new_height, new_width, 3);
II(:,:,:) = 255;

for i=1:height
    len = fix((i) * (tan(theta*pi/180)));               % 向右平移
%     len = fix((height-i+1) * (tan(theta*pi/180)));    % 向左平移
    for j=1:width
        II(i,j+len,:) = I(i,j,:);
    end
end

II = uint8(II);
imwrite(II, [imagename(1:end-4) '_origin.bmp'],'bmp');

实现上下偏移的matlab代码;

%% little fun by Heng Fan
function II = transform(imagename, theta)
%% I --- 原始图像
%% theta --- 拉伸角度
%% II --- 变换后的图像

I = imread(imagename);
[height, width, channel] = size(I);
b = fix(tan(theta*pi/180) * width);
new_height = height + b;
new_width = width;
II = zeros(new_height, new_width, 3);
II(:,:,:) = 255;
trans = ones(new_height, new_width);
tranp(1:new_height,1:new_width)=0;

for j=1:width
    len = fix((width-j+1) * (tan(theta*pi/180)));    % 向上平移
%     len = fix(j * (tan(theta*pi/180)));   % 向下平移
    for i=1:height
        II(i+len,j,:) = I(i,j,:);
        tranp(i+len,j) = 1;
    end
end

II = uint8(II);
imwrite(II, [imagename(1:end-4) '_origin.bmp'],'bmp');

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有