2

I realize that App designer does not support interactive figure manipulation, but I am wondering if I can open a separate figure window (not a UI window) with my graphic displayed on it so that I can still get the location of my mouse clicks. Currently the code below displays the figure on my GUI, and then opens another blank figure that records my mouse clicks. This is fine, but I need to also display the figure in the new window as well, and am having trouble doing so.

first frame = vid(:,:,:,1);
imshow(firstframe,'Parent',app.UIAxes); 
[centers_X centers_Y]=getpts;
Qiana Curcuru
  • 67
  • 1
  • 6
  • Did you try to use `figure` to open a new window? – sco1 Feb 22 '18 at 18:44
  • yes, I get "Specify a UIAxes as the value for 'Parent'." I assume this is because I am in app designer so I don't think I can just open a regular figure unless it is a UI figure – Qiana Curcuru Feb 22 '18 at 19:39
  • `h.f = figure; h.a = axes('Parent', h.f); RGB = imread('peppers.png'); imshow(RGB, 'Parent', h.a);` works just fine for me as an app designer callback. – sco1 Feb 22 '18 at 19:44
  • It's hard to tell what you need help with. Could you please [edit] this question and start by saying _what you're trying to do_ (e.g. "_I would like to get the position of mouse clicks in a uifigure_") instead of asking about a specific solution that you have in mind (i.e. "_how do I open a new window so that I can transfer mouse clicks to a uifigure from it_"). The best structure in your case would be "what I want; what I tried; what problem I ran into". Please also take a look at [mcve]. – Dev-iL Sep 17 '18 at 15:13

1 Answers1

0

What worked for me was setting a callback on the image rather than the axes:

ih = imshow(firstframe,'Parent',app.UIAxes);
ih.ButtonDownFcn = {@im_ButtonDownFcn, app}; %app will be passed to the callback

Then in a separate file in the same folder (or as a private function within the appdesigner... it should work but I haven't tried it):

function im_ButtonDownFcn(im, hit, app)
mouse_pos = flip(hit.IntersectionPoint(1:2)); %gives floats. Round if you want integers e.g. for indexing pixels
craq
  • 1,441
  • 2
  • 20
  • 39