display directions when asking user to select a pixel in an image in matlab

You can display the image to the user using the imshow() function. To get user input via the mouse, you can use the ginput() function. Here's an example code that displays an image in a figure window, and prompts the user to select a pixel. It also displays some directions to the user:

main.m
% Read the image
img = imread('your_image.jpg');

% Display the image in a figure window
imshow(img);

% Display directions for selecting a pixel
disp('Please click on a pixel to select it. Press enter when done.');

% Wait for the user to select a pixel
[x, y] = ginput(1);

% Print the coordinates of the selected pixel to the console
fprintf('You selected pixel (x: %d, y: %d)\n', x, y);
391 chars
15 lines

Note that ginput() will wait for the user to select a pixel. The argument 1 tells the function to wait for only one user click. The coordinates of the selected pixel are returned as two separate values, x and y.

gistlibby LogSnag