1

I have an RGB image obtained from saving the imagesc function as shown below. how to refine/smoothen the edges present in the image.

enter image description here

It consists of sharper edges, where I need to smoothen them. Im not able to find a solution for performing this for an RGB image. Instead of the staircase effect seen in the image I'd like to even out the edges. Please help thanks in advance.

  • How is this different from your [previous question](http://stackoverflow.com/questions/43179988/how-to-trace-the-surface-area-as-well-as-smoothen-a-specific-region-in-an-image)? – beaker Apr 04 '17 at 14:42
  • In my previous question I had done segmentation and masking to smoothen the image. I wanted to know if there are other ways to do it for colour images. – Abirami Anbalagan Apr 05 '17 at 14:46

3 Answers3

1

maybe imresize will help you:

% 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')

EDIT

here I do resize + filtering + rounding:

% 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

user2999345
  • 4,195
  • 1
  • 13
  • 20
  • Resize is making the image look blurred!!! How to overcome the staircase effect that has been generated? Thank you so much for the answer! – Abirami Anbalagan Apr 04 '17 at 07:49
1

solution

use imfilter and fspecial to perform a convolution of you image with gaussian.

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

change 'blurlevel' parameter (which determines the gaussian kernel size) to make the image smoother or sharper.

result enter image description here

ibezito
  • 5,782
  • 2
  • 22
  • 46
0

If you are just looking for straighter edges, like an elevation map you can try 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');

This produces the following result using a test function that I generated.

enter image description here

jodag
  • 19,885
  • 5
  • 47
  • 66