Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe14.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.19 (Windows/20081209)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Adding text to bitmaps
References: <gk09lo$4pn$1@fred.mathworks.com>
In-Reply-To: <gk09lo$4pn$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 38
Message-ID: <YrP8l.41452$mE3.13631@newsfe14.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe14.iad 1231274872 24.79.146.116 (Tue, 06 Jan 2009 20:47:52 UTC)
NNTP-Posting-Date: Tue, 06 Jan 2009 20:47:52 UTC
Date: Tue, 06 Jan 2009 14:48:09 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:510104


Sven wrote:

> I'm trying to add custom text to each frame of a movie, as made from within matlab using
> getframe();
> 
> My problem is that I've already used getframe, so I'm working with an array of RGB bitmap
> images (rows x cols x 3), and trying to embed new text into them, therefore simply calling
> text() doesn't do what I want (ie, it just overlays vector text on top of the current figure).
> 
> How should I go about doing this?

Create a second figure with a uicontrol('Style','text') in it. Use a specific background
color that you can easily recognize such as [0 0 0] if you want to be able to
merge your text smoothly over a variable background, or set it to whatever your fixed
background colour is that you want around the caption. Ensure the Units property
of the uicontrol is set to pixels and HorizontalAlignment is set to 'left'.
get() the Position property of the uicontrol and remember it.

Then, for each caption you want to build, set the String property of the uicontrol
to the desired string. After setting the String (not before!) get() the Extent
property of the uicontrol. The third and fourth elements of that are the actual
width and height occupied by that particular string (varies from string to string
due to proportional spacing.) Now combine the remembered position of the uicontrol
together with the height and width determined by the Extent in order to build
the rect parameter to getframe() off of that figure, to capture just the bits
of the string. Now overwrite or add (addition) the captured text into the frame.

There is one small trick to take into account in this: uicontrol('Style','text')
writes down from the -top- of the uicontrol, not aligned at the -bottom-, but
the uicontrol Position is from the bottom. Thus the rect you build should use
a base (bottom) coordinate which is the uicontrol bottom plus the uicontrol height
minus the Extent height.

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?