
如何将这段图像处理算法转化为matlaB代码?
1个回答
展开全部
函数代码
function result = smoothedfilter(img)
result = img;
[m n] = size(img);
for i=3:m-2
for j=3:n-2
v1 = [reshape(img(i-2:i-1,j-1:j+1),1,6) img(i,j)];
v2 = [reshape(img(i-1:i+1,j+1:j+2),1,6) img(i,j)];
v3 = [reshape(img(i+1:i+2,j-1:j+1),1,6) img(i,j)];
v4 = [reshape(img(i-1:i+1,j-2:j-1),1,6) img(i,j)];
v5 = [reshape(img(i-2:i-1,j-2:j-1),1,4) img(i-1,j) img(i,j-1) img(i,j)];
v6 = [reshape(img(i-2:i-1,j+1:j+2),1,4) img(i-1,j) img(i,j+1) img(i,j)];
v7 = [reshape(img(i+1:i+2,j+1:j+2),1,4) img(i+1,j) img(i,j+1) img(i,j)];
v8 = [reshape(img(i+1:i+2,j-2:j-1),1,4) img(i+1,j) img(i,j-1) img(i,j)];
v9 = reshape(img(i-1:i+1,j-1:j+1),1,9);
V = {v1 v2 v3 v4 v5 v6 v7 v8 v9};
st = zeros(1,9);
me = zeros(1,9);
for k=1:9
st(k) = std(double(V{k}));
me(k) = mean(V{k});
end
[~, k] = min(st);
result(i,j) = uint8(me(k));
end
end
end
测试代码
org = imread('37_3.bmp');
result = smoothedfilter(org);
subplot(2,2,1);imshow(org);title('原图');
subplot(2,2,2);imshow(result);title('平滑过滤之后');
h=ones(3,3)./9;
y = filter2(h,org);
y = uint8(y);
subplot(2,2,3);imshow(y);title('filter2中值过滤之后');
y = imfilter(org,h);
subplot(2,2,4);imshow(y);title('imfilter中值过滤之后');
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询