Individual word locations in string / word interest areas

Hello,


I am creating an experiment using the Eyelink toolbox. We will be having people read text, and I want to create an interest area around each word. I'm wondering if there is an easy way to either: 

1) automatically generate an interest area for each individual word or 

2) easily get the location of each word in a text string so I can use that information to create rectangular interest areas.


The best option I have so far is looping through a "DrawFormattedText" command for each word and getting the text bound for each word, but this is a little clunky and also doesn't work very well when I have line breaks. 


Is there a way for me to generate these interest areas automatically in Matlab using the Psychtoolbox/Eyelink toolbox extensions?


Thanks!

Amanda


Hi Amanda,

I am not aware of such functionality in the toolbox. I would do roughly the same as you.
1. make sure the FGTL based drawtext plugin is installed and working correctly (that includes, make sure your psychtoolbox is up to date). help DrawTextPlugin
2. Use Screen('DrawText') directly to draw text, if you draw word by word, there is little benefit to DrawFormattedText
3. before you Screen('DrawText'), use Screen('TextBounds') to get info about the bounding box of the text. This is a pixel-tight box IIRC, so you would have to adjust that a bit still. My advice would be to make AOIs as large as possible, so expand them vertically and horizontally equally on both sides of a gap until they meet.
4. yes, you will have to deal with line breaks manually. You can steal some relevant code from the internals of DrawFormattedText for that.

All the best,
Dee

On Tue, Feb 14, 2017 at 11:00 PM, avanlams@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:


Hello,


I am creating an experiment using the Eyelink toolbox. We will be having people read text, and I want to create an interest area around each word. I'm wondering if there is an easy way to either:

1) automatically generate an interest area for each individual word or

2) easily get the location of each word in a text string so I can use that information to create rectangular interest areas.


The best option I have so far is looping through a "DrawFormattedText" command for each word and getting the text bound for each word, but this is a little clunky and also doesn't work very well when I have line breaks.


Is there a way for me to generate these interest areas automatically in Matlab using the Psychtoolbox/Eyelink toolbox extensions?


Thanks!

Amanda





This sounded like a somewhat useful feature to have, so DrawFormattedText in the next beta will be able to do this. Optionally returns a list of bounding boxes, one for each individual word, as defined by use of the strtok() function, ie. Words are units of text which are separated by white-space like ' ' blanks, tabs, line-feeds, newlines etc.

For early adopters, get the new file from my git repo:

https://raw.githubusercontent.com/kleinerm/Psychtoolbox-3/master/Psychtoolbox/PsychBasic/DrawFormattedText.m

DrawFormattedTextDemo demos its use (lines 84-88) the new 'wordboxes' return arg:
https://raw.githubusercontent.com/kleinerm/Psychtoolbox-3/master/Psychtoolbox/PsychDemos/DrawFormattedTextDemo.m

I made some other potential verschlimmbesserungen to DrawFormattedText which survived light testing.

-mario
Hi Mario,

yes, this is a useful feature. The demo works well. I just had to change isargout(4) to nargout == 4 in a few places and also initalize wordbounds. Is isargout octave only?

Thanks,
Ian.



On 15 February 2017 at 11:57, mario.kleiner@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

This sounded like a somewhat useful feature to have, so DrawFormattedText in the next beta will be able to do this. Optionally returns a list of bounding boxes, one for each individual word, as defined by use of the strtok() function, ie. Words are units of text which are separated by white-space like ' ' blanks, tabs, line-feeds, newlines etc.

For early adopters, get the new file from my git repo:

https://raw.githubusercontent. com/kleinerm/Psychtoolbox-3/ master/Psychtoolbox/ PsychBasic/DrawFormattedText.m

DrawFormattedTextDemo demos its use (lines 84-88) the new 'wordboxes' return arg:
https://raw.githubusercontent. com/kleinerm/Psychtoolbox-3/ master/Psychtoolbox/ PsychDemos/ DrawFormattedTextDemo.m

I made some other potential verschlimmbesserungen to DrawFormattedText which survived light testing.

-mario


This is perfect, thanks! Runs well for me.


Amanda
Yes, sadly. Octaves approach would have allowed for higher efficiency in case of future new return arguments, as the function has to use a much less efficient code path for the per-word bounding boxes. On Octave isargout() will also return false if the caller uses the ~ place-holder to ignore a return argument. But the fixes are already made in my git repo since around noon.

-mario