lihangjie8 发表于 2006-5-23 20:33

谢谢各位兄弟帮个忙啊

<P>有那位兄弟帮助我下吗?运行下下面这个程序,随便帮我找副图,得到最后的三副图,我毕业设计用。万分感谢啊,或者酬谢,</P>
<P ><FONT face="Times New Roman">function=im(in1,in2)%</FONT>将非索引图像转换成索引图像,<FONT face="Times New Roman">in1</FONT>为文件名,<FONT face="Times New Roman">in2</FONT>为文件格式。<FONT face="Times New Roman">%</FONT></P>
<P ><FONT face="Times New Roman">if nargin==2</FONT></P>
<P ><FONT face="Times New Roman">if errargn(m filename,nargin,,nargout,),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">g=in1;type=in2;</FONT></P>
<P ><FONT face="Times New Roman">if errargt(m filename,g,‘str</FONT>′<FONT face="Times New Roman">),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">iferrargt(m filename,type,</FONT>′<FONT face="Times New Roman">str</FONT>′<FONT face="Times New Roman">),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">if=im read(g,type);</FONT></P>
<P ><FONT face="Times New Roman">if strcmp(type,</FONT>′<FONT face="Times New Roman">bmp</FONT>′<FONT face="Times New Roman">)</FONT>︱<FONT face="Times New Roman">strcmp(type,</FONT>′<FONT face="Times New Roman">jpg</FONT>′<FONT face="Times New Roman">),=rgb2ind(f);end</FONT></P>
<P ><FONT face="Times New Roman">end</FONT></P>
<P >下面我们将介绍三种方法:强制消噪、默认阈值消噪和独立阈值消噪。为以后验证我们的消噪效果,我们人为的做一加噪函数<FONT face="Times New Roman">addnoise:</FONT></P>
<P ><FONT face="Times New Roman">function=addnoise(in1,in2,in3)%</FONT>加噪声函数,<FONT face="Times New Roman">in1</FONT>为文件名,<FONT face="Times New Roman">in2</FONT>为文件格式,<FONT face="Times New Roman">in3</FONT>为一整数,<FONT face="Times New Roman">g</FONT>为含噪图像。</P>
<P ><FONT face="Times New Roman">ifnargin==3</FONT></P>
<P ><FONT face="Times New Roman">if errargn(m filename,nargin,,nargout,),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">=im(in1,in2);n=in3;</FONT></P>
<P ><FONT face="Times New Roman">if errargt(m filename,in1,’str’),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">if errargt(m filename,in2,’str’),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">if errargt(m filename,n,’int’),error(‘3’);end</FONT></P>
<P ><FONT face="Times New Roman">init=2055615866;randn(‘seed’,init);g=X+n*randn(size(X));end</FONT></P>
<P ><FONT face="Times New Roman">X,map]=im(‘a:\.cprod.bmp’, ‘bmp’);</FONT></P>
<P ><FONT face="Times New Roman">save f0 X map;</FONT></P>
<P ><FONT face="Times New Roman">%</FONT>加噪并画出含噪声图像</P>
<P ><FONT face="Times New Roman">=addnoise(‘a:.\cprod.bmp’, ‘bmp’,15);</FONT></P>
<P ><FONT face="Times New Roman">figure(2)</FONT></P>
<P ><FONT face="Times New Roman">subplot(221);subimage(g,map);title(</FONT>′含噪声图像′<FONT face="Times New Roman">);</FONT></P>
<P ><FONT face="Times New Roman">%</FONT>强制消噪</P>
<P ><FONT face="Times New Roman">=wavedec2(g,3,</FONT>′<FONT face="Times New Roman">sym4</FONT>′<FONT face="Times New Roman">); %</FONT>用小波函数<FONT face="Times New Roman">sym4</FONT>对图像进行<FONT face="Times New Roman">3</FONT>层小波分解</P>
<P ><FONT face="Times New Roman">a3=wrcoef2(</FONT>′<FONT face="Times New Roman">a</FONT>′<FONT face="Times New Roman">,c,s,</FONT>′<FONT face="Times New Roman">sym4</FONT>′<FONT face="Times New Roman">,3); </FONT></P>
<P ><FONT face="Times New Roman">save f1 a3;%</FONT>保存强制消噪后的结果<FONT face="Times New Roman">a3</FONT>到<FONT face="Times New Roman">f1</FONT>中</P>
<P ><FONT face="Times New Roman">%</FONT>默认阈值消噪</P>
<P ><FONT face="Times New Roman">%</FONT>用<FONT face="Times New Roman">ddencmp</FONT>获取在消噪过程中的默认阈值</P>
<P ><FONT face="Times New Roman">=ddencmp(</FONT>′<FONT face="Times New Roman">den</FONT>′<FONT face="Times New Roman">,wv</FONT>′<FONT face="Times New Roman">, ,g);</FONT></P>
<P ><FONT face="Times New Roman">subplot(221);subimage(g,map;title(</FONT>′含噪声图像<FONT face="Times New Roman">)</FONT>′<FONT face="Times New Roman">);</FONT></P>
<P ><FONT face="Times New Roman">g0=wdencmp(</FONT>′<FONT face="Times New Roman">gb1</FONT>′<FONT face="Times New Roman">,g,</FONT>′<FONT face="Times New Roman">sym4</FONT>′<FONT face="Times New Roman">,3,thr,sorh,keepapp);</FONT></P>
<P ><FONT face="Times New Roman">subplot(222);subimage(g0,map);title(</FONT>′全阈值消噪后的图像′<FONT face="Times New Roman">);</FONT></P>
<P ><FONT face="Times New Roman">%</FONT>独立阈值消噪</P>
<P ><FONT face="Times New Roman">thrh=;thrv=;thrd=;</FONT></P>
<P ><FONT face="Times New Roman">thrh=;thrv=;thrd=;</FONT></P>
<P ><FONT face="Times New Roman">thr=; %</FONT>设置水平、垂直、斜线方向阈值</P>
<P ><FONT face="Times New Roman">g1=wdencmp(</FONT>′<FONT face="Times New Roman">lvd</FONT>′<FONT face="Times New Roman">,g,</FONT>′<FONT face="Times New Roman">sym4</FONT>′<FONT face="Times New Roman">,3,thr,</FONT>′<FONT face="Times New Roman">h</FONT>′<FONT face="Times New Roman">);%</FONT>采取每层不同阈值进行消噪</P>
<P ><FONT face="Times New Roman">subplot(223);subimage(g1,map);title(</FONT>′独立阈值消噪后的图像′<FONT face="Times New Roman">);</FONT></P>
<P ><FONT face="Times New Roman">save f2 g0 g1;%</FONT>保存默认阈值消噪后的结果<FONT face="Times New Roman">g0</FONT>和独立阈值消噪后的结果<FONT face="Times New Roman">g1</FONT>到<FONT face="Times New Roman">f2</FONT>中</P>
<P>我不胜感激哦   等你们的好消息 </P>
页: [1]
查看完整版本: 谢谢各位兄弟帮个忙啊