Clear Filters
Clear Filters

Move Line on an Image with Up and Down Arrow

3 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 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 on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Apr 2018
  3 Comments
Walter Roberson
Walter Roberson on 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

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!