Adding line change the size of the image

Hi!
I am currently working on adding lines above a image in App Designer, but when I add these lines, the image changes size and I don't want it to. Can someone help me please?
M is a 4D matrix(160,130,26,14)
profondeur, hauteur, largeur, temps are sliders, and angle 1,5 are knob
I=M(:,:,floor(profondeur),floor(temps));
affichagelignex(app);
J=imresize(I,[160 130]);
imshow(J,[],'Parent',app.UIAxes);
function affichagelignex(app)
profondeur = app.zaxegauchedroiteSlider.Value;
hauteur = app.yaxeavantarrireSlider.Value;
largeur = app.xaxepiedstteSlider.Value;
angle1 = app.AngleXYKnob.Value;
angle5 = app.AngleXZKnob.Value;
persistent h1
persistent h5
if (isempty(h1)&& isempty(h5))
h1=line(app.UIAxes,[0 130],[largeur largeur],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur largeur],'Color','green');
else
h1=line(app.UIAxes,[0 130],[largeur-hauteur*tand(angle1) largeur+(130-hauteur)*tand(angle1)],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur-profondeur*tand(angle5) largeur+(26-profondeur)*tand(angle5)],'Color','green');
end

Respuestas (1)

Chad Greene
Chad Greene el 6 de Mayo de 2021
Can you get the axis limits before plotting the lines, and then set the axis back to those limits afterwards? Something like this:
ax = axis; % GET THE AXIS LIMITS
if (isempty(h1)&& isempty(h5))
h1=line(app.UIAxes,[0 130],[largeur largeur],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur largeur],'Color','green');
else
h1=line(app.UIAxes,[0 130],[largeur-hauteur*tand(angle1) largeur+(130-hauteur)*tand(angle1)],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur-profondeur*tand(angle5) largeur+(26-profondeur)*tand(angle5)],'Color','green');
end
axis(ax) % SET THE AXIS LIMITS

10 comentarios

Aurélie B
Aurélie B el 6 de Mayo de 2021
Thank you for repling
I tried what you sent, but the matrix is still becoming smaller once i changed the sliders or knob of the app and i don't know why
Chad Greene
Chad Greene el 6 de Mayo de 2021
Can you provide before- and after- images to show what you mean when you say the image or the matrix gets smaller?
Aurélie B
Aurélie B el 6 de Mayo de 2021
This is before adding the lines and after.
When I add the lines before changing the sliders, it is okay, but when I do a rotation of the lines, the image becomes really small
Aurélie B
Aurélie B el 6 de Mayo de 2021
Moreover, if you know how to clear the 'old lines' that you can see behind the image, i'd take it too. I tried clear affichagelignex but it didn't work
For the size of the image, I wonder if the position of the axes is being changed when the new lines are plotted. Try this:
axh = gca; % get current axis handle
axpos = get(axh,'position'); % get the current position of the axes
if (isempty(h1)&& isempty(h5))
h1=line(app.UIAxes,[0 130],[largeur largeur],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur largeur],'Color','green');
else
h1=line(app.UIAxes,[0 130],[largeur-hauteur*tand(angle1) largeur+(130-hauteur)*tand(angle1)],'Color','green');
h5=line(app.UIAxes3,[0 26],[largeur-profondeur*tand(angle5) largeur+(26-profondeur)*tand(angle5)],'Color','green');
end
set(axh,'position',axpos) % sets the position of the axis back
Regarding deleting the old lines, you might need to return the handles of the line objects from the function like this:
[h1,h5] = function affichagelignex(app)
and then try deleting those line objects before calling affichagelignex, like this:
try
delete(h1)
delete(h5)
end
Aurélie B
Aurélie B el 6 de Mayo de 2021
Editada: Aurélie B el 6 de Mayo de 2021
Regarding deleting the old lines, it works, thank you very much!
Unfortunately, regarding the size of the image, it still doesn't work.. I think that the lines still have the good dimensions but the image reduces
Is the viewing angle changing when new lines are plotted? Maybe try the same idea, but get the viewing angle before plotting the lines and set it afterward:
[az,el]= view;
and then
view(az,el)
Aurélie B
Aurélie B el 6 de Mayo de 2021
Still not working :'( I tried to 'analyse' the problem : when the ends of the line are not on the left and right of the image but on top and bottom, the image is reduced and seems to be moving. Else, there is no problem
Chad Greene
Chad Greene el 6 de Mayo de 2021
Good heavens. I'm sorry, we've reached the end of my ideas for troubleshooting. Hopefully someone with app designing experience can chime in with better ideas. Good luck!
Aurélie B
Aurélie B el 6 de Mayo de 2021
Thank you so much for helping me :)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Mayo de 2021

Comentada:

el 6 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by