matlab 光栅 傅里叶,【图像】【转帖】利用matlab绘制光栅条纹图像
這里好冷。。。。把帖子完善一下吧
:
grating.m
程序代碼:function IMA = grating(m,n,varargin)
% 繪制光柵圖
% grating(m,n) 繪制光柵圖(灰度圖),m為灰度值矩陣的行數,n為列數
% grating(m,n,'PARAM1',val1, 'PARAM2',val2, ...) 用成對出現的參數名/參數值
% 指定光柵圖的顯示屬性,可用的參數名/參數值如下:
% 'Direction' -- 設定光柵條紋的方向,其參數值為:
% 'horizontal' -- 水平條紋
% 'Vertical' -- 豎直條紋
% 'circle' -- 同心圓條紋
% 'radiated' -- 輻射狀條紋
%
% 'Velocity' -- 設定角速度,其參數值為標量
%
% 'Angle' -- 設定初始相位角,其參數值為標量
%
% 'Color' -- 設定光柵條紋的顏色,其參數值為:
% 'Gray' -- 黑白條紋
% 'Rgb' -- 彩色條紋
%
% IMA = grating( ... ) 返回光柵圖對應的灰度值矩陣
%
% CopyRight:xiezhh(謝中華)
% 2011.11.26
% Example:
% grating(512,512,'direction','rad','Velocity',5000,'color','rgb');
% grating(512,512,'Velocity',20,'maxgrayval',200)
% grating(512,512,'direction','ver','Velocity',40)
% grating(512,512,'Velocity',20,'maxgrayval',200,'direction','cir')
if nargin < 2
error('輸入參數過少');
end
[Direction,Vel,Ang,Col,MaxGrayVal] = parseInputs(varargin{:});
if strncmpi(Direction,'hor',3)
x = (1:m)';
Theta = x*pi/Vel;
Theta = repmat(Theta,[1,n]);
elseif strncmpi(Direction,'ver',3)
x = 1:n;
Theta = x*pi/Vel;
Theta = repmat(Theta,[m,1]);
elseif strncmpi(Direction,'cir',3)
x = repmat((1:n),[m,1])-n/2;
y = repmat((1:m)',[1,n])-m/2;
D = sqrt(x.^2 + y.^2);
Theta = D*pi/Vel;
elseif strncmpi(Direction,'rad',3)
x = repmat((1:n),[m,1])-n/2;
y = repmat((1:m)',[1,n])-m/2;
Theta = atan2(y,x);
Theta = Theta*Vel;
else
error('方向參數只能為Horizontal,Vertical,Circle, Radiated 之一');
end
if strncmpi(Col,'gra',3)
I = cos(Theta + Ang);
I = mat2gray(I);
IM = uint8(MaxGrayVal*I);
elseif strncmpi(Col,'rgb',3)
I = zeros(m,n);
IM = uint8(zeros(m,n,3));
for i = 1:3
I = cos(Theta + i*Ang);
IM(:,:,i) = uint8(MaxGrayVal*mat2gray(I));
end
else
error('顏色參數只能為Gray, Rgb 之一');
end
if nargout == 0
figure;
imshow(IM);
else
IMA = IM;
end
%--------------------------------------------------------------------------
% 解析輸入參數
%--------------------------------------------------------------------------
function [Direction,Vel,Ang,Col,MaxGrayVal] = parseInputs(varargin)
if mod(nargin,2)~=0
error('輸入參數個數不對,應為成對出現');
end
pnames = {'direction','velocity','angle' 'color','maxgrayvalue'};
dflts = {'horizontal',30,pi/3,'gray',255};
[Direction,Vel,Ang,Col,MaxGrayVal] = ...
internal.stats.parseArgs(pnames, dflts, varargin{:});
validateattributes(Direction,{'char'},{'nonempty'},mfilename,'direction');
validateattributes(Vel,{'numeric'},{'scalar','nonempty'},mfilename,'velocity');
validateattributes(Ang,{'numeric'},{'scalar','nonempty'},mfilename,'angle');
validateattributes(Col,{'char'},{'nonempty'},mfilename,'color');
validateattributes(MaxGrayVal,{'numeric'},{'scalar','nonempty'},mfilename,'maxgrayvalue');
總結
以上是生活随笔為你收集整理的matlab 光栅 傅里叶,【图像】【转帖】利用matlab绘制光栅条纹图像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 随笔201808
- 下一篇: 计算机外联管理办法,外联部管理制度