请帮忙解释下这段matlab程序的意思,希望是一句一句的[M,N]=size(I);for k = 1:3J = zeros(M,N);for i = 1:Mfor j = 1:Ntemp = I(i,j);s1 = 0; s2 = 0;range = [k:-1:1];for d = ranges1 = 2^(8-d) + s1; s2 = 2^(8-d+1);if temp >= s1 & temp < s2
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 09:19:17
请帮忙解释下这段matlab程序的意思,希望是一句一句的[M,N]=size(I);for k = 1:3J = zeros(M,N);for i = 1:Mfor j = 1:Ntemp = I(i,j);s1 = 0; s2 = 0;range = [k:-1:1];for d = ranges1 = 2^(8-d) + s1; s2 = 2^(8-d+1);if temp >= s1 & temp < s2
请帮忙解释下这段matlab程序的意思,希望是一句一句的
[M,N]=size(I);
for k = 1:3
J = zeros(M,N);
for i = 1:M
for j = 1:N
temp = I(i,j);
s1 = 0; s2 = 0;
range = [k:-1:1];
for d = range
s1 = 2^(8-d) + s1; s2 = 2^(8-d+1);
if temp >= s1 & temp < s2;
J(i,j) = 255; break;
end
end
end
end
J = uint8(J);
figure; imshow(J);
end
end
请帮忙解释下这段matlab程序的意思,希望是一句一句的[M,N]=size(I);for k = 1:3J = zeros(M,N);for i = 1:Mfor j = 1:Ntemp = I(i,j);s1 = 0; s2 = 0;range = [k:-1:1];for d = ranges1 = 2^(8-d) + s1; s2 = 2^(8-d+1);if temp >= s1 & temp < s2
代码后面多了个end.
[M,N]=size(I);%%得到I的行数和列数
for k = 1:3 %%最外层循环
J = zeros(M,N);%%建立和I一样大小的0矩阵,用以得到新的图像
for i = 1:M
for j = 1:N
temp = I(i,j);%%i,j为坐标,把I中横坐标为i,纵坐标为j处的像素值赋给temp
s1 = 0; s2 = 0;%%初始化s1和s2
range = [k:-1:1];%%当k=1时,range=1;当k=2时,range=[2,1];当k=3时,range=[3,2,1]
for d = range%%d和range取一样的值
s1 = 2^(8-d) + s1; s2 = 2^(8-d+1);%%s2没有进行累加,那么当d=1时,s2=256;当d=[2,1]时,第一次循环d=2,s2=128,第二次循环d=1,s2=256,该值覆盖128,所以最终s2=256;当d=[3,2,1]时,同样的道理,s2=256.s1进行累加,当d=1时,s1=128;当d=[2,1]时,第一次循环d=2,s1=64,第二次循环d=1,s1=128,所以最终s1=128+64=192;当d=[3,2,1]时,第一次循环d=3,s1=32,第二次循环d=2,s1=64,第三次循环d=1,s1=128,所以最终s1=128+64+32=224.
if temp >= s1 & temp < s2;
J(i,j) = 255; break;%%判断temp是否在s1和s2范围之内,是的话给J(i,j)赋值255.其实就是双阈值分割
end
end
end
end
J = uint8(J);
figure; imshow(J);%%显示图像J,总共三幅,第一幅的阈值128