demo3
Contents
initialize
clear rgb = im2double(imread('birds1.jpg')); imshow(rgb); do_input = false; if ~do_input load demo3 end
select pixel values
if do_input [c r p] = impixel; save demo3 c r p end disp(p)
1.0000 0.2275 0.0039 0.1922 0.5294 0.0078 0.0235 0.2235 0.8275
show pixel locations
imshow(rgb); hold on plot(c,r,'wo'); for n=1:length(c) text(c(n)+10,r(n),sprintf('%d',n),'Color','w'); end hold off
instantiate distance tool
imshow(rgb); if do_input hd = imdistline; else hd = imdistline(gca, pts(:,1), pts(:,2)); end % sometimes the distance tool is not rendered properly when publishing
distance api
The Distance tool contains a structure of function handles, called an API, that can be used to retrieve distance information and control other aspects of Distance tool behavior.
api = iptgetapi(hd); w = api.getDistance(); fprintf('distance %g pixels\n',w); pts = api.getPosition(); if do_input save demo3 c r p pts end point1 = pts(1,:); point2 = pts(2,:); fprintf('point1 %g %g point2 %g %g\n',point1,point2); fprintf('norm(point1-point2) = %g\n',norm(point1-point2)); % delete(api) % clear api hd
distance 129 pixels point1 135.5 189.5 point2 135.5 318.5 norm(point1-point2) = 129