I've recently been working with some customers who need to display extra information on top of a plot. Steve showed some examples for superimposing lines on images in such a way so they are visible despite what's going on in the picture. Today I'll show you a few such techniques here.
Contents
Making Lines Visible
I'll start with two techniques for making sure lines show up on a background of other information. These are
- two lines, with different color and linewidth
- two lines, with different linestyle
First let's see what happens with a single line.
load clown image(X),colormap(map) axis off hold on rect = [ 150 40 80 70] h = rectangle('position',rect);
rect = 150 40 80 70
It's kind of hard to see this black edge of the rectangle outlining the eye on the right. Let me make it more visible by thickening it, and placing a thinner line inside.
set(h,'LineWidth',5) h2 = rectangle('position',rect); set(h2,'EdgeColor','w','LineWidth',2)
Let me adjust the linestyle instead of the width.
set(h,'LineWidth',2,'LineStyle','-') set(h2,'LineStyle',':')
Making Markers Visible
Similarly, you can ensure that markers are visible on your plots by exploiting the separable colors for the face and edge.
delete([h h2]) hm = plot(60,125,'s') set(hm,'MarkerSize',10,'MarkerEdgeColor','w','MarkerFaceColor','m') hold off
hm =
177
What Techniques Do You Use?
Do you have some other graphical techniques to ensure all the elements are clearly visible? Let me know here.
Get
the MATLAB code
Published with MATLAB® 7.10



What is crucially missing in matlab is functionality which allows to draw primitives (lines, boxes, circles, text etc.) directly into the image, such that the enriched contents is not just visible in the figure but finds its way into the image (matrix) itself.
I help myself with cumbersome code using getframe(), which is really tiring. A short snippet of a 100+ lines function drawing text into an image:
More Matlab support for this would be cool, especially since Matlab is very much used by the image processing & Vision community.
Christian
Hi Christian,
That exact functionality is available as part of the Video and Image Processing Blockset, which as of 10b release is also available for MATLAB. Have a look at the following functionality to see if it meets your needs:
http://www.mathworks.com/access/helpdesk/help/toolbox/vipblks/ref/video.shapeinserterclass.html
and
http://www.mathworks.cn/access/helpdesk/help/toolbox/vipblks/ref/video.markerinserterclass.html
Witek
Developer of Video and Image Processing Blockset
witek@mathworks.com
Oops, I meant 10a.
FYI, the MATLAB Graphics User Guide has a section called “Adding Text to Images” (http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f2-14242.html#f2-20036) that provides an example of embedding text in an image. It uses GETFRAME as well. I think that’s the state of the art in core MATLAB. VIP Blockset is great, but you need Simulink.
Geoff,
Like I mentioned in my post, Video blockset is available in MATLAB since 10a release. I guess my statement should have been move explicit:
It DOES NOT require Simulink.
Witek
Hi Witek,
thank you for the link, that is indeed interesting. However, I do not understand why this functionality is not part of the image processing toolbox.
Best regards,
Christian
The ability to “burn” geometric shapes into images is also provided by the ROI tools in the Image Processing Toolbox.
im = imread('pout.tif'); h_line = imline(gca,[10 10; 100 100]); mask = h_line.createMask(); im(mask) = 255; imshow(im)http://www.mathworks.com/access/helpdesk/help/toolbox/images/imroi.html#imroi-createMask
Alex
True, you may not need Simulink, but it seems sort of crazy to have to get an entire toolbox for something that seems like it could easily belong (in limited form, at least) in the Image Processing Toolbox…
Christian and Arjun,
I see your point. You can use the technique described by Alex. That’s already in Image Processing toolbox and it will not require a purchase of a new product.
Other people may care more about other functionality that’s in Video blockset and for them using the previously mentioned functions (System objects) may make more sense.
BTW. Additional benefits of the aforementioned objects include ANSI C code generation, i.e. they can generate C code that can be used independently of the MathWorks products. You may care about that. Video blockset also has other CV functionality such as Optical Flow, estimation of the fundamental matrix, etc.
HTH,
Witek