Code covered by the BSD License  

Highlights from
Embed Text and Graphics in an Image

5.0 | 1 rating Rate this file 16 Downloads (last 30 days) File Size: 4.15 KB File ID: #38721 Version: 1.0
image thumbnail

Embed Text and Graphics in an Image


Brett Shoelson (view profile)


Burn or embed text and graphics in an image.

| Watch this File

File Information

Use insertInImage to embed, or burn, any text or graphics item into an image. You can specify, using a cell array of parameter-value pairs (PVs), or using a structure, any valid properties of the specified object to insert. ALL ITEMS MUST BE SPECIFIED IN PIXEL COORDINATES, and must not extend beyond the edges of the image!
BASEIMAGE: an image, or a handle to an image (or parent object containing an image), in which the object is to be embedded. (The image need not be displayed, unless a handle is provided.)
INSERTIONCOMMAND: text, rectangle, line, ellipse, etc. to embed in the image. Internally, insertInImage calls FEVAL; anything that works inside an feval command will workhere. For example, you can insert the string 'TESTING' at [x,y] = [20,30] using feval( @() text('TESTING',20,30]), so the insertionCommand for this would be:
@() text('TESTING',20,30).
@() text(x,y,string)
@() rectangle('position',[x y w h])
@() line(x,y)
PVs (OPTIONAL): Cell array or structure of any parameter-value pairs valid for the TYPE of object you wish to insert.(Note that this _may_ include a 'position' parameter, which will overwrite any position set with the insertion command. For example, when you insert a string, PVs can be any Parameter-Value pairs valid for TEXT objects. (See 'Text Properties' for details.)
IMGOUT: output RGB image of the same class as imgin, with embedded text or graphic item(s).

(Thet lines, text, and circles are burned in the image herewith.)


Create Button Label(String,Varargin) inspired this file.

Required Products Image Processing Toolbox
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
15 Apr 2014 Brett Shoelson

Brett Shoelson (view profile)

Try calling insertInImage with round(bbox) as an argument. Let me know it that works for you.

Comment only
14 Apr 2014 Richa

Richa (view profile)


I want to save the bounding box generated by regionprops on the image. I am trying to use your function but am getting the following error:
Subscript indices must either be real positive integers or logicals.

Error in insertInImage (line 144)
imgOut(bbox(2):bbox(2)+bbox(4),bbox(1):bbox(1)+bbox(3),jj) = ...

Error in vertebrae1 (line 69)
imgOut = insertInImage(subImage,f,params);

Can you please help how to figure out this error?
Thanks and Regards

Comment only
15 Nov 2013 Brett Shoelson

Brett Shoelson (view profile)

Thanks for the kind comment and review, Jan. I'm glad this is useful to you.

I haven't played with this function for a while, but I just realized that, as written, my code doesn't honor the "edgeColor" property of text--edges are rendered the same color as the text itself, regardless of how it's specified. I will work on that, but in the interim, a workaround for having a differently-colored box around text is to use a rectangle to bound to bound it.

Happy MATLABbing!

Comment only
15 Nov 2013 Jan Froehlich

Finally the solution I searched for years. Adjustable Font-Size, Color, Font-Type, even alignment can be controlled like this: " 'HorizontalAlignment','center' ".

Thank you so much for your submission Brett.

Contact us