End of the year is a pretty fun time for me. I get some extra free time in between my holiday break to do some fun MATLAB-ing! :) Just yesterday, I was trying to find a good way to nicely trace out an object (i.e. digitize an image) with a smooth line. In the Image Processing Toolbox, there are many interactive tools to help me draw lines and shapes. Using imfreehand to do this was difficult. The mouse is not meant for drawing accurately. Perhaps a tablet and a stylus would have helped, which I don't own.
impoly will let me better select points along the object, but it creates a polygon. If I want a smooth object, I would need to select many points along the outline of the object.
What I wanted was a way to connect the polygon point with a smooth line. That's when I discovered Will's hobbysplines. It nicely connects control points with Bézier curves. This was much better and more robust than my initial attempt to use splines on two dimensions. I could get close, but it was difficult to match up the slopes at the end points.
The function accepts extra options, in addition to the required control points, which allow you to specify the slope of the curves and the "tension" of the curves as they approach the control points. Will includes an example script to demonstrate the various options.
Will's function creates the plot based on the inputs. I wanted to use the smooth curve in my own visualization, so I modified his code to output the actual coordinates for the smoothed curve. With 23 control points I selected using impoly, look how nicely I was able to create a smooth outline of the object. Thanks for this file, Will!
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.