Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2008-05-03
年龄: 39
帖子: 2
声望力: 0 ![]() |
![]()
我是一个新手,在做区域生长处理镜面反射的科目。
大家教我怎么运行下面这个东东嘛 (有一个原图,我还不知道怎么弄进去):cry: function contraGrowth(img) re=imread(img); yuantu=re; re=double(re); jname=sprintf('%s%s','j',img); ename=sprintf('%s%s','e',img); de=imread(jname); ed=imread(ename); [x,y]=Get2(de) to=1; while x~=0&y~=0 r=0.0;g=0.0;b=0.0; num=0.0; %1 假设没有位于边界的点,否则要考虑超界 eq=equation(de(x-1,y-1, ![]() if eq~=1 r=r+4*re(x-1,y-1,1); g=g+4*re(x-1,y-1,2); b=b+4*re(x-1,y-1,3); num=num+4; end %2 eq=equation(de(x-1,y, ![]() if eq~=1 r=r+6*re(x-1,y,1); g=g+6*re(x-1,y,2); b=b+6*re(x-1,y,3); num=num+6; end %3 eq=equation(de(x-1,y+1, ![]() if eq~=1 r=r+4*re(x-1,y+1,1); g=g+4*re(x-1,y+1,2); b=b+4*re(x-1,y+1,3); num=num+4; end %4 eq=equation(de(x,y-1, ![]() if eq~=1 r=r+6*re(x,y-1,1); g=g+6*re(x,y-1,2); b=b+6*re(x,y-1,3); num=num+6; end %5 eq=equation(de(x,y+1, ![]() if eq~=1 r=r+6*re(x,y+1,1); g=g+6*re(x,y+1,2); b=b+6*re(x,y+1,3); num=num+6; end %6 eq=equation(de(x+1,y-1, ![]() if eq~=1 r=r+4*re(x+1,y-1,1); g=g+4*re(x+1,y-1,2); b=b+4*re(x+1,y-1,3); num=num+4; end %7 eq=equation(de(x+1,y, ![]() if eq~=1 r=r+6*re(x+1,y,1); g=g+6*re(x+1,y,2); b=b+6*re(x+1,y,3); num=num+6; end %8 eq=equation(de(x+1,y+1, ![]() if eq~=1 r=r+4*re(x+1,y+1,1); g=g+4*re(x+1,y+1,2); b=b+4*re(x+1,y+1,3); num=num+4; end %9 % r=r+re(x,y,1); % g=g+re(x,y,2); % b=b+re(x,y,3); % num=num+1; r1=r/num; g1=g/num; b1=b/num; re(x,y,1)=r1;re(x,y,2)=g1;re(x,y,3)=b1; de(x,y, ![]() to=to+1; if mod(to,4)==1 [x,y]=Get1(de); end if mod(to,4)==2 [x,y]=Get2(de); end if mod(to,4)==3 [x,y]=Get3(de); end if mod(to,4)==0 [x,y]=Get4(de); end end figure, subplot(1,2,1),imshow(yuantu); subplot(1,2,2),imshow(uint8(re)); name=sprintf('%s%s','r',img); imwrite(uint8(re),name); %从上向下求取第一个红色点的位置,如果整幅图像没有则返回[0,0] function [x,y]=Get1(img) [M,N]=size(img(:,:,1)); x=0;y=0; for i=1:M for j=1:N if img(i,j,1)==255&img(i,j,2)==0&img(i,j,3)==0 x=i; y=j; return; end end end %从下向上求取第一个红色点的位置,如果整幅图像没有则返回[0,0] function [x,y]=Get2(img) [M,N]=size(img(:,:,1)); x=0;y=0; for i=1:M for j=1:N if img(M-i+1,N-j+1,1)==255&img(M-i+1,N-j+1,2)==0&img(M-i+1,N-j+1,3)==0 x=M-i+1; y=N-j+1; return; end end end %从左向右求取第一个红色点的位置,如果整幅图像没有则返回[0,0] function [x,y]=Get3(img) [M,N]=size(img(:,:,1)); x=0;y=0; for i=1:N for j=1:M if img(j,i,1)==255&img(j,i,2)==0&img(j,i,3)==0 x=j; y=i; return; end end end %从右向左求取第一个红色点的位置,如果整幅图像没有则返回[0,0] function [x,y]=Get4(img) [M,N]=size(img(:,:,1)); x=0;y=0; for i=1:N for j=1:M if img(M-j+1,N-i+1,1)==255&img(M-j+1,N-i+1,2)==0&img(M-j+1,N-i+1,3)==0 x=M-j+1; y=N-i+1; return; end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function eq=equation(x) if x(1)==255&x(2)==0&x(3)==0 eq=1; else eq=0; end |
![]() |
![]() |
![]() |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
[资料]Matlab中文参考手册 | ansis | MATLAB论坛 | 56 | 2008-10-07 22:05 |
【求助】用MATLAB实现牛顿环的光学仿真 | zukaldl | MATLAB论坛 | 4 | 2008-07-31 08:38 |
[求助]求取样调函数基准点曲率问题 | payson | MATLAB论坛 | 0 | 2008-05-01 08:24 |
【求助】请高手帮忙——限滑差速器 | trueboy | MATLAB论坛 | 0 | 2008-01-12 14:49 |
Color Management and Color Transformations in MATLAB | TechnicalArticles | MATLAB技术文章 | 0 | 2008-01-06 16:32 |