Thread Subject: Adding text to bitmaps

Subject: Adding text to bitmaps

From: Sven

Date: 6 Jan, 2009 18:59:04

Message: 1 of 2

Hi there,

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?

Option 1: Add my text *before* I call getframe(). I would like to avoid this if possible, as I do some post-processing that works on blank regions where my text will go.

Option 2: Somehow change the RGB values of my image(s) directly

Option 3: Loop through my movie, show each frame in a new figure. Add my text using the text() command. Resave the image using getframe().

My problem with option 2, is that I don't know how to do it :(
My problem with option 3, is that when I open a new figure, my image is scaled according to the *figure*, but I want it to keep the same number of rows/cols when I call getframe() again. How can I force an image to be displayed at one pixel per image pixel?

Thanks,
Sven.

Subject: Adding text to bitmaps

From: Walter Roberson

Date: 6 Jan, 2009 20:48:09

Message: 2 of 2

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)?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
getframe Sven 6 Jan, 2009 14:00:22
text Sven 6 Jan, 2009 14:00:22
overlay Sven 6 Jan, 2009 14:00:22
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com