Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Active Figure Zoom for Selecting Points

4.5
4.5 | 2 ratings Rate this file 17 Downloads (last 30 days) File Size: 8.29 KB File ID: #38959 Version: 1.1
image thumbnail

Active Figure Zoom for Selecting Points

by

Tristan Ursell (view profile)

 

09 Nov 2012 (Updated )

Select points at a user-specified zoom level that moves around the image as you click.

| Watch this File

File Information
Description

Tristan Ursell
November 2013
Active zoom for polyline selection.

[X,Y]=getline_zoom(Im1);
[X,Y]=getline_zoom(Im1,'plot');
[X,Y]=getline_zoom(Im1,'loop_path');
[X,Y]=getline_zoom(Im1,'stationary');
[X,Y]=getline_zoom(Im1,'interp',res);
[X,Y]=getline_zoom(Im1,'interp',res,'method',mt1);

Have you ever wanted to carefully select points from an image but could not get close enough to see where you wanted to select? Have you ever wanted to create a smooth, evenly spaced set of parametric contour points from a minimum of user-selected points? Then this function is for you -- it allows the user to select points from an image at a user specified zoom level that moves along with the points selected in a centered frame of reference. The resulting contour can then be interpolated to constant arc-length resolution, smoothed, and even closed into a loop.

Im1 is the input image (matrix) from which points will be selected.

The optional parameter 'interp' creates evenly spaced X Y points with the resolution 'res', where res = 1, will space the X,Y points one pixel apart in arc length. The secondary option 'method' selects between a 'linear' and 'spline' interpolation, the latter being a differentially smooth curve. The default method is 'linear'.

The optional parameter 'loop_path' will loop the path so that the last point is the same as the first point. If the method is 'spline', then the looped path will also be smoothed such that the derivatives match at the beginning and ending points.

The optional parameter 'stationary' will keep the zoom and image position fixed, but all other options will be active.

Hold 'shift' or 'control' and then click to end polyline selection.

This script requires the 'ginput' function.

This script will generate its own figure handle.

SEE ALSO: getpts, getline, getrect, zoom

Credit to John D'Errico for writing the useful 'interparc' function included within this function.

Example:

Im1=imread('rice.png');

[X0,Y0] = getline_zoom(Im1,'plot');
[X1,Y1] = getline_zoom(Im1,'plot','interp',0.5,'method','spline');
[X2,Y2] = getline_zoom(Im1,'plot','interp',0.5,'method','spline','loop_path');

Acknowledgements

Interparc inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
27 May 2016 Antoine Brassard Simard

Really helped me also. I would suggest to change line #141 for : Im_temp=Im1(max([yb,1]):min([yt,size(Im1,1)]),max([xl,1]):min([xr,size(Im1,2)]));

That would avoid the program to crash when the temporary image reaches one of the original image boundary.

27 Dec 2015 Albert Kao

Hi Tristan,

Thank you for posting this code -- it was very helpful for my project!

I just have a couple of suggestions to improve the accuracy of your code:

1. In line 198 (calculating the length of the curve), summing across the raw selected points will always underestimate the length of the 'true' curve, since you are subsampling the curve. Instead, I would use interparc.m to generate a smoother curve (roughly at the resolution that is desired by the user), and estimate the length of the curve using those interpolated points. This takes more computation but on certain applications the extra accuracy might be important.

2. I would change line 205 (using interparc.m) to the following:

O1 = interparc(round(Ltot/res) + 1,X,Y,mt1);

to account for the two edge points.

Otherwise, great work!

Updates
08 Nov 2013 1.1

added smoothing, looping, fixed resolution, and other improvements.

Contact us