From: Dorf Recinos on
Hi,

I'm trying to build a GUI in matlab whereby a user can get a line profile of an image using improfile. I'm able to load the image into an axes object and manipulate it through other functions (convert it to grayscale, etc.) , however, I'm unable to use the buttondownfcn when I click on the image(axes) itself.

I have a very simple test code,
function hPreview_ButtonDownFcn(hObject, eventdata, handles)
disp(x);

If I have no image displayed in the axes, I get 'x' as my output. After loading the image, I don't get anything.

I'm loading my image using: image(my_image, 'Parent', handles.hPreview).

Can anyone help me out with this issue?

Thanks.
From: Walter Roberson on
Dorf Recinos wrote:

> I'm trying to build a GUI in matlab whereby a user can get a line
> profile of an image using improfile. I'm able to load the image into an
> axes object and manipulate it through other functions (convert it to
> grayscale, etc.) , however, I'm unable to use the buttondownfcn when I
> click on the image(axes) itself.
>
> I have a very simple test code, function hPreview_ButtonDownFcn(hObject,
> eventdata, handles)
> disp(x);
>
> If I have no image displayed in the axes, I get 'x' as my output. After
> loading the image, I don't get anything.
>
> I'm loading my image using: image(my_image, 'Parent', handles.hPreview).
>
> Can anyone help me out with this issue?

We can deduce from what you wrote that your button down fcn is applied to the
axes but not to the image. If you do not set the HitTest property of the image
to 'off' then as long as the cursor is over the image, the image's
buttondownfcn would have control.

Also, you have to be careful about how you load the image. If you have not set
the axes ReplaceChildren property, either manually or via a "hold" call, then
the default behaviour is that high-level plotting calls such as image() and
plot() do the equivalent of clearing the axes, including the callbacks.