Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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 9

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 9

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 9

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 9

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 9

"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 9

> 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

Subject: [Q] Add text into image matrix?

From: Ramraj

Date: 15 Oct, 2009 15:54:19

Message: 7 of 9

I had a similar problem. My colleagues were previously using the screen capture routine but I found the most convenient way would be to use ImageMagick, an open source commandline image manipulation program alongwith matlab and call that program to insert text, shapesm, apply effects, etc from inside matlab itself. Completely solves the purpose for me...

Ramraj

"David Portabella" <david.portabella@gmail.com> wrote in message <frl9t6$82k$1@fred.mathworks.com>...
> > 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
>
>

Subject: [Q] Add text into image matrix?

From: Karel Lebeda

Date: 11 Mar, 2013 17:15:18

Message: 8 of 9

"Kevin" 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.

Hi, I made my own rasterizer, you can find a prototype at http://www.mathworks.com/matlabcentral/fileexchange/40538-matprint. I wait for some feedback now and if it seemed to be useful, I'd work some more on it...
KL

Subject: [Q] Add text into image matrix?

From: Karel Lebeda

Date: 11 Mar, 2013 17:17:22

Message: 9 of 9

"Kevin" 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.

Hi, I made my own rasterizer, you can find a prototype at http://www.mathworks.com/matlabcentral/fileexchange/40538-matprint. I wait for some feedback now and if it seemed to be useful, I'd work some more on it...
KL

Tags for this Thread

No tags are associated with this thread.

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.

Contact us