How To Smooth The Image Edge

 Risposta accettata

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh il 27 Mag 2015
Modificato: Salaheddin Hosseinzadeh il 27 Mag 2015

0 voti

Salam Behnam!
I guess by smoothing you mean getting rid of the jagged edges.
What do you think of performing a dilation with a huge radial element and then perform thining?
I just did this here is the result
I hope this is good enough. I did it with a disk of 10 pixels radious you maybe reduce/increase the disk size and get a better smoothing.
Good Luck!

3 Commenti

behnam emami
behnam emami il 27 Mag 2015
Yes, this was my answer Please send Code Here Thank You
Dear Behnam,
You can search MATLAB help for the keywords in my answer. Please also have a look at Image Analyst response, that is far more scientific.
dilatedImage = imdilate(image,strel('disk',10));
thinedImage = bwmorph(dilatedImage,'thin',inf);
Good luck!
behnam emami
behnam emami il 27 Mag 2015
Thank You Mr Salaheddin Hosseinzadeh

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 27 Mag 2015
Modificato: Image Analyst il 27 Gen 2016

5 voti

One way is to blur the image with imfilter() or conv2() before you do the edge detection. Another way is to smooth the outline coordinates with a Savitzky-Golay filter, sgolayfilt() in the Signal Processing Toolbox.
See demo and image in the comment below - tell it to show the older comments because it's collapsed now.

19 Commenti

Dear Image Analyst,
I just checked sgolayfilt, is there a 2 dimensional version of this in MATLAB?
Thanks a lot.
Salaheddin: See attached demo. You have a choice of several images to pick from. It thresholds to find outlines, then calls sgolayfilt() to smooth both the x and y coordinate vectors.
The effect is clearer (more obvious) when you run the demo and can see the images full size.
Dear Image Analyst.
Thank you sooo much! It's amazing. I will try this against imfilter but I don't think if that does any good! I learned something new, which means a lot to me!
Regards,
Salah
DanitD
DanitD il 27 Gen 2016
Modificato: DanitD il 27 Gen 2016
Hello,
I would like to know where did you take the (savitzky_golay_filter_smooth_outline.m)function from? Any reference to cite?!
Thanks,
The Savitzky-Golay filter is in the Signal Processing Toolbox. It takes it's name after its two inventors. Basically it's a moving window where it replaces the center of the window with a value taken from a polynomial fit of the data in the window.
The m-file you reference was written by myself. Glad you (hopefully) like it. Vote for my answer if you do.
DanitD
DanitD il 28 Gen 2016
Yes, very useful indeed! thanks for sharing.
Attached are two more of my Savitzky-Golay filter demos.
Kamu
Kamu il 16 Feb 2017
Modificato: Kamu il 16 Feb 2017
Thanks Image Analyst. However, how can I use the outcome image with Savitzky-Golay filter for further image processing steps (like regionprops)?
You can send the smoothed outlines into poly2mask() if you want. This will define a new, smoother region of interest within which you make your measurements with regionprops().
sufian ahmed
sufian ahmed il 22 Set 2017
this filter can i use before canny edge detection to remove noise and smooth edges ? i need smooth edges. Now i use median filter
Bram Mast
Bram Mast il 16 Gen 2019
Thank you Image Analyst.
I have a problem using the SG filter. I don't get closed regions after aplying the filter to angular regions. How can I fix this ?
Thank you
Bram:
You probably forgot to make the last point the same as the first point before filtering, so that the curve is closed. If you did, then attach your data.
Bram Mast
Bram Mast il 14 Feb 2019
After you have extracted the boundary and applied a smoothing filter on the coordinates, which command can you use to extract information about de boundary (area, perimeter, ...) ?
newbie
newbie il 20 Mar 2019
Modificato: newbie il 20 Mar 2019
Hello Image Analyst,
I am working on a similar problem where the SG filter is not closing the region despite making sure that first and last points are the same.
Can you suggest any way to smooth out the kinks at the edges?
Here is an example (First figure is showing the whole data set which forms a circle and second figure is a zoom in of the edges):
I am also attaching the raw data passed to sgolayfilt function. I used a window size of 311 and a degree of 3
Fig2 - Blue line - raw data; red dots - smoothed data;
Hi Image Analyst and everyone in this loop.
I have an image as follows,
I have tired all the filters like savitzky_golay_filter and other filters I found online. None of it is helping me smooth the edges in the image. Could you please help me with this.
Thanks in advace,
~Harshan
Blur the image with imfilter() and then threshold at 0.5 if you want a binary image again.
windowSize = 5;
kernel = ones(windowSize) / windowSize^2;
blurryImage = imfilter(double(binaryImage), kernel);
binaryImage = blurryImage > 0.5;
Hi Image Analyst, I tired using the above, it is not showing any improvement. I tried changing the threshold too. It ain't helping. Is there any other way to get sleek and continous edges? Please help me out, Im a beginner.
The below is the Image after what u told me to try VS before that. FYI
I don't know the resolution. Maybe those jaggies are just one pixel big? If so, you'd have to increase the number of pixels then blur and threshold.
I have tired working on it for the past two weeks sir, I couldnt still get what I want. Let me explain my project clearly.. Please suggest me how I can work on it.
Project: Finding the edges of a door and used those edges as a trajectory for a sensor that checks edges for Gap/Flush.
Problem: I used Savitzky Golay, Edge Linking and Line Segment Fitting from your blog:
(https://www.peterkovesi.com/matlabfns/#step2line). After all this I am not able to get good edges, its either not smooth or has a lot of unnecessary edges.
Method I used: Image Analyst's Savitzky filter smoothening at three diffrent thresholds, obtain three images and blend them. The output is again processed to Edge linking and line segmenting program which I got from ur blog.
Questions:
  1. How to remove unnecessary edges out of the image.
  2. How to smoothening images so that i can use it for trajectory
I have attached the images of my last output.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by