# Labelling images on the screen

**URL:** <https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033>\
**Category:** Programming Help\
**Tags:** experiment-design\
**Created:** [February 11, 2020, 10:26am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033 "2020-02-11T10:26:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 11, 2020, 10:26am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/1 "2020-02-11T10:26:07Z")

</div>

I have three images displayed in the middle of the screen, one on the center and the other two appear on either side. i want to label each image right below it. how to use ‘DrawText’ to implement it such that specified location is right below its corresponding image.

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 11, 2020, 11:55am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/2 "2020-02-11T11:55:46Z")

</div>

Have at look at `DrawFormattedText2`:

[http://psychtoolbox.org/docs/DrawFormattedText2](http://psychtoolbox.org/docs/DrawFormattedText2)

That offers lots of advanced options to manage position and lots of other formatting options. Read through the demo for that function. If you want something simpler, then type `Screen DrawText?` in the MATLAB command window and read the help, this is the underlying command that allows you to pass X and Y coordinates, but doesn’t handle wrapping or other nicities that `DrawFormattedText2` does…

---

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 12, 2020, 6:20am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/3 "2020-02-12T06:20:30Z")

</div>

I’m unable to run the demo.When i run it on the command window. I’m getting this error ‘PTB - ERROR: SYNCHRONIZATION FAILURE’. any idea why?

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 12, 2020, 7:04am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/4 "2020-02-12T07:04:11Z")

</div>

Without knowing anything about your OS or computer, no. Read what PTB returns, and you’ll see it recommends reading this documentation:

`>> doc SyncTrouble`

For development you can ignore this (you’ll find the override by reading the documentation), but if you care about timing for the actual experiment, it is wise to follow the recommendations. You will have the least problems if you use Linux for your experimental control computer…

---

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 12, 2020, 5:26pm UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/5 "2020-02-12T17:26:30Z")

</div>

Thanks. I sorted out the synchronization problem. As my images keep changing throughout. And I need the labels to correspondingly change with them, I thought it’s better overlay the text on the image. Is there any function which enables that?

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [February 12, 2020, 6:09pm UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/6 "2020-02-12T18:09:57Z")

</div>

Yes, you can just use drawtext or any if the other text functions to draw on tip of the images, by simply doing the drawtext call after the drawtexture call.

---

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 13, 2020, 5:20am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/7 "2020-02-13T05:20:54Z")

</div>

Thanks. but i dont get how i can specify the location for the text. I have a vector of texture points for the images of three continents. I want the text to appear below each of them. i tried to make a vector of texts like

` text_T=['europe' 'southamerica 'africa']`

`Screen('DrawTextures', window,T,[],rects);`  
`Screen('DrawText',window,text_T,?)`

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 13, 2020, 6:48am UTC](https://psychtoolbox.discourse.group/t/labelling-images-on-the-screen/3033/8 "2020-02-13T06:48:32Z")

</div>

Read the documentation:

[http://psychtoolbox.org/docs/Screen-DrawText](http://psychtoolbox.org/docs/Screen-DrawText)

or

[http://psychtoolbox.org/docs/DrawFormattedText2](http://psychtoolbox.org/docs/DrawFormattedText2)  
[https://raw.githubusercontent.com/Psychtoolbox-3/Psychtoolbox-3/beta/Psychtoolbox/PsychDemos/DrawFormattedText2Demo.m](https://raw.githubusercontent.com/Psychtoolbox-3/Psychtoolbox-3/beta/Psychtoolbox/PsychDemos/DrawFormattedText2Demo.m)

That tells you where you need to enter your X and Y position, though note I think neither are vectorised, you need to call them 3 times for 3 labels, or use spaces/tabs to align the labels in one char array.
