views:

106

answers:

2

alt text

Hello, I have a segmented image as shown. Is there a way to smoothen the lines so that it does not look so wavy? Thanks.

+4  A: 

The following code requires Image Processing Toolbox:

url = 'http://i182.photobucket.com/albums/x11/veronicafmy/FYP/picture5segmentedimage.jpg';
rgb = imread(url);
bw = im2bw(rgb2gray(rgb), 0.5);
se = strel('line',50,74); % 74 degrees determined by inspection
bw2 = imclose(bw,se);
se2 = strel('line',50,74+90);
bw3 = imclose(bw2,se2);

Here's the result:

smoothed result

Optional step: postprocess by thinning:

bw4 = bwmorph(bw3,'thin',inf);
Steve Eddins
...ahh the art of dilation and erosion ;)
Amro
A: 

I think you should ask yourself why it has to be smoother. If you have segmented an image and gotten that result, are you sure that smoothening will give you a correct result? If it does then Steve Eddins answer seems to do the trick.

If, on the other hand, the object you are trying to segment is much smoother than the result I'd suggest one of two approaches.

  1. If the target object is a cross (two lines), I'd probably calculate the lines and change the representation to two line segments. These can then be rendered at whatever precision and smoothness. To do this you could either find the center and rotation using some kind of feature detection algorithm, or you could use hough transforms to find the lines. The latter is probably much simpler.

  2. If the target can have any form then I'd look into a better segmentation algorithm. There are segmentation algorithms that is not based on hard thresholds. I have used graph partitioning algorithms for this, and while slow, they work well.

kigurai