Move Line on an Image with Up and Down Arrow

2 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2018-4-21
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 2018-4-21
@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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-4-18
  3 个评论
Walter Roberson
Walter Roberson 2018-4-19
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by