Move Line on an Image with Up and Down Arrow

4 Ansichten (letzte 30 Tage)
Enea Baumann
Enea Baumann am 18 Apr. 2018
Kommentiert: Jan am 21 Apr. 2018
Hi Everyone
I have a series of pictures which i want to process with Matlab. I should be able to open the first image, then move a line up and downwards with the up and down arrow and finally change to next picture with return.
I was able to define a callback function which registers the keyboard actions.
If I press the uparrow it adds 1 to a variable s.
If I press the downarrow it subtracts 1 from a variable s.
If I press return it adds 1 to a variable k.
function y = KeyPressCb(~,evnt)
fprintf('%s\n',evnt.Key);
global s
global k
if strcmp(evnt.Key,'uparrow')==1
s=s+1;
elseif strcmp(evnt.Key, 'downarrow')==1
s=s-1;
elseif strcmp(evnt.Key, 'return')==1
k = k + 1;
end
end
Now I want to return this values to the main program, so that i can use this two variables (k and s) to change the line coordinates and the image array counter. How do i do that?
Is there an other, easier way to do it?
Greetings
  2 Kommentare
Walter Roberson
Walter Roberson am 21 Apr. 2018
We are not free private consulting. The "price" we ask is that the questions and responses are public for everyone to learn from. When someone edits away a question after it has been answered, the volunteers tend to feel as if they have been taken advantage of.
Jan
Jan am 21 Apr. 2018
@Wunman Usam: Please do not remove the contents of your question after an answer has been given. This is considered to be impolite, because the nature of this forum is to share solutions in public. If you delete the question afterwards, the time spent for posting an answer is lost for the community.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 18 Apr. 2018
  3 Kommentare
Walter Roberson
Walter Roberson am 19 Apr. 2018
function driver
y = 0; %shared variable
ax = gca;
fig = ancestor(ax, 'figure');
plot( ax, randn(1,50) * 10 );
XL = get(ax, 'XLim');
hold(ax, 'on')
h = plot(ax, XL, [y y]);
hold(ax, 'off');
set(fig, 'WindowKeyPressFcn', @KeyPressCb);
function KeyPressCb(~,evnt)
if strcmp(evnt.Key,'uparrow')
fprintf('up!\n');
y = y + 1;
set(h, 'YData', [y y]);
elseif strcmp(evnt.Key, 'downarrow')
fprintf('down!\n');
y = y - 1;
set(h, 'YData', [y y]);
end
end
end
Enea Baumann
Enea Baumann am 19 Apr. 2018
Wow! Thank you so much!!!!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by