text on image position

Dear all,
I have created a simple GUI that shows a anatomical MRI volume. All works ok except one thing. I would like to insert some text informations on the image in the same (relative) position, for example in the upper left corner of the image. For this aim, I used the text command putting the text I want to see in the (x,y) coordinates of the image, that is inserted in a axes object.
The problem is that the position of the text changes when the resolution of the loaded image changes and it is not always in the same relative position (respect to the image).
What I have to do? To change axes or text properties?
Thanks a lot
Domenico

4 comentarios

Rik
Rik el 25 de Mayo de 2020
What code are you currently using and where do you want your text object to appear?
Domenico
Domenico el 25 de Mayo de 2020
Editada: Stephen23 el 26 de Mayo de 2020
Something like this:
axes(handles.axes1);
imagesc(v(:, :, z));
text(x,y,'text to write',properties...) ;
where x and y are the coordinates where the text is inserted, for example 10,18. The problem is that they shold be relative to axes1 properties instead to be fixed, I suppose.
Thank you
Mohammad Sami
Mohammad Sami el 26 de Mayo de 2020
Starting in R2020a, annotations created with the annotation function are supported in App Designer figures. To create an annotation, call the annotation function, specifying the UI figure as the first input argument.
The annotations are displayed using relative positions, so they will remain in the same place.
Domenico
Domenico el 26 de Mayo de 2020
I have a 2017b unfortunately

Iniciar sesión para comentar.

Respuestas (2)

Mohammad Sami
Mohammad Sami el 26 de Mayo de 2020

0 votos

What if you used the limits of your axes and then create a relative x and y position.
axes(handles.axes1);
imagesc(v(:, :, z));
xl = xlim(handles.axes1);
yl = ylim(handles.axes1);
rx = 0.5; %relative x position
ry = 0.5; %relative y position
x = xl(1) + rx*(xl(2)-xl(1));
y = yl(1) + ry*(yl(2)-yl(1));
%text(x,y,'text to write',properties...) ;

3 comentarios

Domenico
Domenico el 26 de Mayo de 2020
Thanks a lot, I will try and let you know.
Domenico
Domenico el 27 de Mayo de 2020
It works! Thanks a lot!
Rik
Rik el 27 de Mayo de 2020
If it works, feel free to accept this answer.
Just out of curiosity: did you also see my answer?

Iniciar sesión para comentar.

Rik
Rik el 26 de Mayo de 2020

0 votos

You can set the Unit property to Normalized. Note that this uses normal axis coordinates, so the y-axis is flipped.
(the full backstory of the image can be found here)
%get an example image
defimage = pow2(get(0,'DefaultImageCData'),47);
IM = bitshift(defimage,-37);IM = fix(IM);
IM = bitand(IM,31);IM = IM/max(IM(:));
imagesc(IM);
for x=linspace(0.1,0.9,4)
for y=linspace(0.1,0.9,4)
text(x,y,sprintf('text at (%.1f,%.1f)',x,y),'Units','Normalized') ;
end
end

1 comentario

Domenico
Domenico el 28 de Mayo de 2020
Dear Rik,
sorry for the delay. Yes, I saw your answer and it works, even if it seems that the other solution works faster.
Thank you very much for your reply.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Mayo de 2020

Comentada:

el 28 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by