首页 > 代码库 > PS 滤镜——Skewing

PS 滤镜——Skewing

%%%%  Skewing

clc;
clear all;
close all;

addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');

Image=imread('4.jpg');

Image=double(Image);
theta=pi/9;    % 控制倾斜的角度
[row, col, layer]=size(Image);

% % % % % Horizontal Skewing
% % row_new=row;
% % col_new=floor(row*tan(theta))+1+col;
% % Image_new=zeros(row_new, col_new,3);
% % Trans=(row-1)*tan(theta);
% % for i=1:row
% %     Dis=(row-i)*tan(theta);
% %     for j=1:col_new
% %         y0=i;
% %         % x0=j+Dis-Trans;     %%%%% Left skew
% %         x0=j-Dis;             %%%%% Right skew
% %         if(x0>1 && x0<col)
% %         %     Image_new(i,j)=0;
% %         x1=floor(x0);
% %         p=x0-x1;
% %         Image_new(i,j,:)=(1-p)*Image(y0,x1,:)+p*Image(y0,x1+1,:);
% %         end
% %     end
% % end



% % % % % Vertical Skewing
col_new=col;
row_new=floor(col*tan(theta))+1+row;
 Image_new=zeros(row_new, col_new,3);
 Trans=(col-1)*tan(theta);
for j=1:col_new
    Dis=j*tan(theta);
        for i=1:row_new
            % y0=i+Dis-Trans;       %%%%% Left skew
            y0=i-Dis;           %%%%% Right skew
            x0=j;
            if(y0>1 && y0<row)
                %     Image_new(i,j)=0;
                y1=floor(y0);
                p=y0-y1;
                Image_new(i,j, : )=(1-p)*Image(y1,x0, : )+p*Image(y1+1,x0,:);
            end
    end
end

imshow(Image_new/255);
        


原图

技术分享

水平 skew  theta=pi/6

技术分享

垂直 skew theta=pi/9

技术分享

PS 滤镜——Skewing