2017-04-04 82 views
1

我有从保存图像c功能获得的RGB图像,如下所示。如何改进/平滑图像中存在的边缘。如何从图像中获得的图像平滑边缘c功能

enter image description here

它由尖锐的边缘,在那里我需要理顺它们。我无法找到一个解决方案来执行此RGB图像。而不是在图像中看到的楼梯效果,我想平衡边缘。请提前帮助感谢。

+0

是如何从你的[前一个问题]不同的(http://stackoverflow.com/questions/43179988/how-to-trace-the-surface-area-as-well-as-smoothen -a-特定区域合的图像)? – beaker

+0

在我之前的问题中,我已经完成了分割和蒙版以平滑图像。我想知道是否有其他方法可以用于彩色图像。 –

回答

1

也许imresize将帮助您:

% here im just generating an image similar to yours 
A = zeros(20); 
for ii = -2:2 
    A = A + (ii + 3)*diag(ones(20-abs(ii),1),ii); 
end 
A([1:5 16:20],:) = 0;A(:,[1:5 16:20]) = 0; 
subplot(121); 
imagesc(A); 
title('original') 
% resizing image with bi-linear interpolation 
B = imresize(A,100,'bilinear'); 
subplot(122); 
imagesc(B); 
title('resized') 

编辑

这里我调整+过滤+取整:

% generates image 
A = zeros(20); 
for ii = -2:2 
    A = A + (ii + 3)*diag(ones(20-abs(ii),1),ii); 
end 
A([1:5 16:20],:) = 0;A(:,[1:5 16:20]) = 0; 
subplot(121); 
imagesc(A); 
title('original') 
% resizing 
B = imresize(A,20,'nearest'); 
% filtering & rounding 
C = ceil(imgaussfilt(B,8)); 
subplot(122); 
imagesc(C); 
title('resized') 

enter image description here

+0

调整大小使图像看起来模糊!如何克服已经产生的楼梯效应?非常感谢你的回答! –

1

解决方案

使用imfilter和fspecial执行图像与高斯的卷积。

I = imread('im.png'); 
H = fspecial('gaussian',5,5); 
I2 = imfilter(I,H); 

变化“blurlevel”参数(它决定了高斯内核的大小),以使图像平滑或尖锐。

结果 enter image description here

+0

非常感谢您的回答!我想要将图像中的梯子看起来像一个台阶。 –

0

如果你只是寻找直边,像高程地图,你可以尝试contourf

cmap = colormap(); 
[col,row] = meshgrid(1:size(img,2), 1:size(img,1)); 
v = linspace(min(img(:)),max(img(:)),size(cmap,1)); 
contourf(col,row,img,v,'edgecolor','none'); 
axis('ij'); 

这将使用我生成的测试函数产生以下结果。

enter image description here