MATLAB: Does a second call to IMPIXEL clear the figure and not show previously selected points in the Image Processing Toolbox 7.2 (R2011a)

Image Processing Toolboximpixel

I am using IMPIXEL to select a point. Then when I call IMPIXEL again, the previously selected point is not shown in the figure.

Best Answer

The IMPIXEL function clears the figure once the points have been selected and you hit the Enter key. The function does not currently provide the functionality to keep previously selected points.
In order to get such functionality, a possible workaround would be to implement the functionality using a function like GINPUT or GETPTS along with IMSHOW. You can refer to the sample MATLAB script that I have written below to help you:
clc;
clear all;
close all;
% initialize number of points
np = 1;
% read sample image
img = imread('cameraman.tif');
% display image
imshow(img);
title('Click on an UPPER point');
hold on;
% get coordinates and intensity of selected point

[x,y] = ginput(1);
intensity1 = img(round(x),round(y));
% plot selected point

plot(x,y,'r+');
hold on;
% place text on image

text(x,y,[' \color{blue}' num2str(np)],'FontWeight','bold');
% change title
title('Click on matching LOWER point');
% update np
np = np+1;
% get coordinates and intensity of selected point
[x,y] = ginput(1);
intensity2 = img(round(x),round(y));
% plot selected point
plot(x,y,'r+');
hold on;
% place text on image
text(x,y,[' \color{blue}' num2str(np)],'FontWeight','bold');