Move Line on an Image with Up and Down Arrow
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Enea Baumann
el 18 de Abr. de 2018
Comentada: Jan
el 21 de Abr. de 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 comentarios
Walter Roberson
el 21 de Abr. de 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
el 21 de Abr. de 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.
Respuesta aceptada
Walter Roberson
el 18 de Abr. de 2018
3 comentarios
Walter Roberson
el 19 de Abr. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!