Skip to content

Instantly share code, notes, and snippets.

@alexstorer
Created February 28, 2014 00:43
Show Gist options
  • Select an option

  • Save alexstorer/9262886 to your computer and use it in GitHub Desktop.

Select an option

Save alexstorer/9262886 to your computer and use it in GitHub Desktop.

Revisions

  1. alexstorer created this gist Feb 28, 2014.
    30 changes: 30 additions & 0 deletions measurepxdist.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    function [ d ] = measurepxdist( imloc )
    %MEASUREPXDIST Measure distance between pixels in an image
    % Returns distance in pixels.
    % Shows line between left-click and right-click.
    imshow(imloc)
    im = gcf();
    hold on
    title('Click the two points, left click and right click, q to quit','FontSize',16)

    q = 113;
    button = 0;
    p1 = [0 0];
    p2 = [0 0];
    while (button ~= q)
    [x, y, button] = ginput(1);
    if button==1
    p1 = [x y];
    elseif button==3
    p2 = [x y];
    end
    d = sqrt(sum((p1-p2).^2));
    try
    delete(g1)
    end

    g1 = plot([p1(1) p2(1)],[p1(2) p2(2)],'rx-');
    xlabel(['Distance is ' num2str(d)])
    end
    close(im)
    end