Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: [Q] Add text into image matrix?

Subject: [Q] Add text into image matrix?

From: Kevin

Date: 8 Feb, 2008 17:36:03

Message: 1 of 6

Hi everyone,

This is what I would like to do:

(1) Use imread.m to load a jpg file into Matlab.
(2) Add one line of text (eg. the date of image file) to the
image.
(3) Use imwrite to save the modified image back to a jpg file.

I don't know how to do step 2. I know that I can use text.m
to add text to a figure. But I don't know how to add text to
a image (which is stored in a 3-D matrix).

Thanks.

Subject: [Q] Add text into image matrix?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 Feb, 2008 17:49:38

Message: 2 of 6

In article <foi3u2$9k0$1@fred.mathworks.com>, Kevin <khung@fake.com> wrote:

>This is what I would like to do:

>(1) Use imread.m to load a jpg file into Matlab.
>(2) Add one line of text (eg. the date of image file) to the
>image.
>(3) Use imwrite to save the modified image back to a jpg file.

>I don't know how to do step 2. I know that I can use text.m
>to add text to a figure. But I don't know how to add text to
>a image (which is stored in a 3-D matrix).

Use text() to add text to the current figure, then use
getframe() to save the axis contents (which would be image and text
both), then use frame2im() to convert from frame structure
to an image, then imwrite() that image.
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: [Q] Add text into image matrix?

From: Kevin

Date: 8 Feb, 2008 22:31:03

Message: 3 of 6

Thank you very much for your help. I tried out your ideas
and it works. But I run into image quality problem.

My original image is 2112x2816:

  B 2112x2816x3 17842176 uint8

But the image (generated by frame2im.m) is

  A 343x435x3 447615 uint8

Is it possible to increase the resolution?


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <foi4ni$sg3$1@canopus.cc.umanitoba.ca>...
> In article <foi3u2$9k0$1@fred.mathworks.com>, Kevin
<khung@fake.com> wrote:
>
> >This is what I would like to do:
>
> >(1) Use imread.m to load a jpg file into Matlab.
> >(2) Add one line of text (eg. the date of image file) to the
> >image.
> >(3) Use imwrite to save the modified image back to a jpg
file.
>
> >I don't know how to do step 2. I know that I can use text.m
> >to add text to a figure. But I don't know how to add text to
> >a image (which is stored in a 3-D matrix).
>
> Use text() to add text to the current figure, then use
> getframe() to save the axis contents (which would be image
and text
> both), then use frame2im() to convert from frame structure
> to an image, then imwrite() that image.
> --
> "Any sufficiently advanced bug is indistinguishable
from a feature."
> -- Rich Kulawiec

Subject: [Q] Add text into image matrix?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 Feb, 2008 22:39:15

Message: 4 of 6

In article <foil77$d67$1@fred.mathworks.com>, Kevin <khung@fake.com> wrote:
>Thank you very much for your help. I tried out your ideas
>and it works. But I run into image quality problem.

>My original image is 2112x2816:

> B 2112x2816x3 17842176 uint8

>But the image (generated by frame2im.m) is

> A 343x435x3 447615 uint8

>Is it possible to increase the resolution?

Hmmm, that seems to be hardcoded for getframe.

Okay, time for a different tactic: use print() to print the figure
to a file.

Also, I suggest that you look around the FEX (Mathworks File Exchange)
as I seem to recall reading about some screen capture routines there
that worked at higher resolution than getframe does.
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: [Q] Add text into image matrix?

From: Vihang Patil

Date: 9 Feb, 2008 06:56:01

Message: 5 of 6

"Kevin " <khung@fake.com> wrote in message
<foi3u2$9k0$1@fred.mathworks.com>...
> Hi everyone,
>
> This is what I would like to do:
>
> (1) Use imread.m to load a jpg file into Matlab.
> (2) Add one line of text (eg. the date of image file) to the
> image.
> (3) Use imwrite to save the modified image back to a jpg file.
>
> I don't know how to do step 2. I know that I can use text.m
> to add text to a figure. But I don't know how to add text to
> a image (which is stored in a 3-D matrix).
>
> Thanks.


This might be helpful

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14311&objectType=file

and

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14312&objectType=file

and

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12654&objectType=file

HTH
Vihang

Subject: [Q] Add text into image matrix?

From: David Portabella

Date: 17 Mar, 2008 08:25:10

Message: 6 of 6

> Use text() to add text to the current figure, then use
> getframe() to save the axis contents (which would be image
and text
> both), then use frame2im() to convert from frame structure
> to an image, then imwrite() that image.
> --

That works! :)

getframe() displays the current figure,
and takes a snapshot of the screen (for the coordinates and
size of the figure).

This has the drawback that you cannot let a matlab program
running on the background, and doing something else in the
computer.
That is, if I am using another software (e.g. notepad), the
screenshot taken by getframe will include notepad (or
getframe will prevent me for using notepad).

Is there a way to circumvent this?
that is, that figure and getframe are used in a buffer, but
not directly shown in the screen.


Many thanks,
DAvid


Tags for this Thread

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics