<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241962</link>
    <title>MATLAB Central Newsreader - Adding text to bitmaps</title>
    <description>Feed for thread: Adding text to bitmaps</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 06 Jan 2009 18:59:04 -0500</pubDate>
      <title>Adding text to bitmaps</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241962#620132</link>
      <author>Sven </author>
      <description>Hi there,&lt;br&gt;
&lt;br&gt;
I'm trying to add custom text to each frame of a movie, as made from within matlab using getframe();&lt;br&gt;
&lt;br&gt;
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).&lt;br&gt;
&lt;br&gt;
How should I go about doing this?&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Option 2: Somehow change the RGB values of my image(s) directly&lt;br&gt;
&lt;br&gt;
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().&lt;br&gt;
&lt;br&gt;
My problem with option 2, is that I don't know how to do it :(&lt;br&gt;
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?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Sven.</description>
    </item>
    <item>
      <pubDate>Tue, 06 Jan 2009 20:48:09 -0500</pubDate>
      <title>Re: Adding text to bitmaps</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241962#620158</link>
      <author>Walter Roberson</author>
      <description>Sven wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; I'm trying to add custom text to each frame of a movie, as made from within matlab using&lt;br&gt;
&amp;gt; getframe();&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My problem is that I've already used getframe, so I'm working with an array of RGB bitmap&lt;br&gt;
&amp;gt; images (rows x cols x 3), and trying to embed new text into them, therefore simply calling&lt;br&gt;
&amp;gt; text() doesn't do what I want (ie, it just overlays vector text on top of the current figure).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How should I go about doing this?&lt;br&gt;
&lt;br&gt;
Create a second figure with a uicontrol('Style','text') in it. Use a specific background&lt;br&gt;
color that you can easily recognize such as [0 0 0] if you want to be able to&lt;br&gt;
merge your text smoothly over a variable background, or set it to whatever your fixed&lt;br&gt;
background colour is that you want around the caption. Ensure the Units property&lt;br&gt;
of the uicontrol is set to pixels and HorizontalAlignment is set to 'left'.&lt;br&gt;
get() the Position property of the uicontrol and remember it.&lt;br&gt;
&lt;br&gt;
Then, for each caption you want to build, set the String property of the uicontrol&lt;br&gt;
to the desired string. After setting the String (not before!) get() the Extent&lt;br&gt;
property of the uicontrol. The third and fourth elements of that are the actual&lt;br&gt;
width and height occupied by that particular string (varies from string to string&lt;br&gt;
due to proportional spacing.) Now combine the remembered position of the uicontrol&lt;br&gt;
together with the height and width determined by the Extent in order to build&lt;br&gt;
the rect parameter to getframe() off of that figure, to capture just the bits&lt;br&gt;
of the string. Now overwrite or add (addition) the captured text into the frame.&lt;br&gt;
&lt;br&gt;
There is one small trick to take into account in this: uicontrol('Style','text')&lt;br&gt;
writes down from the -top- of the uicontrol, not aligned at the -bottom-, but&lt;br&gt;
the uicontrol Position is from the bottom. Thus the rect you build should use&lt;br&gt;
a base (bottom) coordinate which is the uicontrol bottom plus the uicontrol height&lt;br&gt;
minus the Extent height.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
.signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?</description>
    </item>
  </channel>
</rss>

