imnoise2.m
生活随笔
收集整理的這篇文章主要介紹了
imnoise2.m
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
function R=imnoise2(type,M,N,a,b)%type是函數類型,M*N是噪聲數組的大小,a,b為兩個參數
%設置默認值
if nargin==1%如果函數的輸入參數為1,則默認a=0;b=1;M=1;N=1a=0;b=1;M=1;N=1;
elseif nargin==3%如果函數的輸入參數為3,則默認a=0;b=1a=0;b=1;
end
%開始運行程序
switch lower(type)case 'gaussian'%如果是高斯類型,執行下面方程R=a+b*randn(M,N);case 'salt & pepper'%如果是焦鹽類型,當輸入參數小于等于3,a=0.05,b=0.05if nargin<=3a=0.05;b=0.05;end%檢驗Pa+Pb是否大于1if(a+b)>1error('The sum Pa+Pb must be not exceed >1')endR(1:M,1:N)=0.5;X=rand(M,N);%(0,1)范圍內產生一個M*N大小的均勻隨機數組c=find(X<=a);%尋找X中小于等于a的數,并賦值為0R(c)=0;u=a+b;c=find(X>a & X<=u);%尋找X中大于a并小于等于u的數,并賦值為1R(c)=1;case 'lognormal'%對數正態類型,當輸入參數小于等于3,a=1,b=0.25,執行下面方程if nargin<=3a=1;b=0.25;endR=a*exp(b*randn(M,N));case 'rayleigh'%瑞利類型,執行下面方程R=a+(-b*log(1-rand(M,N))).^0.5;case 'exponential'%指數類型,執行下面方程if nargin<=3%如果輸入參數小于等于3,a=1a=1;endif a<=0%如果a=0,錯誤類型error('Parameter a must be positive for exponential type.')endk=-1/a;R=k*log(1-rand(M,N));case 'erlang'%厄蘭類型,如果輸入參數小于等于3,a=2,b=5if nargin<=3a=2;b=5;endif(b~=round(b)|b<=0)%如果b=0,錯誤類型error('Param b must a positive integer for Erlang.')end k=-1/a;R=zeros(M,N);for j=1:bR=R+k*log(1-rand(M,N));endotherwise%如果不是以上類型,輸出未知分配類型error('Unknown distribution type.')
end
總結
以上是生活随笔為你收集整理的imnoise2.m的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA王思聪吃热狗程序_易语言制作王校
- 下一篇: GIS软件开发入门需要学习哪些内容?