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

标签:
matlab图片编辑偏移平行四边形 |
分类: matlab |
今天写论文,发现要画一个流程图,需要对图像进行操作,也就是平移一下,写了一个Matlab程序实现了4种平移效果,效果如下
len = fix((i) *
(tan(theta*pi/180)));
% 向右平移
for j=1:width
II(i,j+len,:) = I(i,j,:);
end
len = fix((width-j+1) *
(tan(theta*pi/180))); %
向上平移
for i=1:height
II(i+len,j,:) = I(i,j,:);
tranp(i+len,j) = 1;
end
向上偏移
不多说了,上代码:
实现向左右偏移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((height-i+1)
* (tan(theta*pi/180))); %
向左平移
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(j *
(tan(theta*pi/180))); % 向下平移
end
II = uint8(II);
imwrite(II, [imagename(1:end-4) '_origin.bmp'],'bmp');
后一篇:Matlab 如何给散点着色