MATLAB中if for 嵌套,请教一个关于if中嵌套 if的问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我的code是这样的

ThresholdRatio =0.8;

edge_threshold=max_grad* ThresholdRatio; % pixels' gradient which is larger than edge_threshold will be recognized as edge

max_pixel=max(max(smoothed_image(:)));

min_pixel=min(min(smoothed_image(:)));

threshold_1=min_pixel+(max_pixel-min_pixel)/3;   % thresholds for pseudo coloration

threshold_2=max_pixel-(max_pixel-min_pixel)/3;

[h12 w12]=size(smoothed_image);

pseudo_gradient_R=[];

pseudo_gradient_G=[];

pseudo_gradient_B=[];

k1=1; % weights of RGB channels, they can be modified to acquire best performance

k2=1;

k3=1;

for i=1:h12

for j=1:w12

smoothed_image(i,j)=rad2deg(smoothed_image(i,j));

if gradient_gray(i,j)>=edge_threshold

pseudo_gradient_R(i,j)=255;      % color edge with red

pseudo_gradient_G(i,j)=0;

pseudo_gradient_B(i,j)=0;

else

if smoothed_image(i,j) >= min_pixel &&   smoothed_image(i,j) <= threshold_1

pseudo_gradient_R(i,j)=0;      % color rest pixels

pseudo_gradient_G(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*min_pixel)/2*(threshold_1-min_pixel)^k2));

pseudo_gradient_B(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*threshold_1)/2*(min_pixel-threshold_1)^k3));

elseif   smoothed_image(i,j) > threshold_1 &&   smoothed_image(i,j) <= threshold_2

pseudo_gradient_R(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*threshold_1)/2*(threshold_2-threshold_1)^k1));

pseudo_gradient_G(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*threshold_2)/2*(threshold_1-threshold_2)^k2));

pseudo_gradient_B(i,j)=0;

else %(smoothed_image(i,j) > threshold_2) && (smoothed_image(i,j) <= max_pixel)

pseudo_gradient_R(i,j)= 255;

pseudo_gradient_G(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*threshold_2)/2*(max_pixel-threshold_2)^k2));

pseudo_gradient_B(i,j)= abs(255*sin((pi*smoothed_image(i,j)-pi*threshold_2)/2*(max_pixel-threshold_2)^k3));

end

end

end

end

请高手指点

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值