Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a rectangle with an outlined border?

I want to draw a rectangle to outline an area of an image that I've plotted in one axes of a figure. I have multiple axes in this figure, so I am using the rectangle() function. What I want is to draw a white rectangle a thin black border just inside and just outside the rectangle. The part of the image inside the rectangle should be visible, so all 'facecolor' should be 'none'. I have tried drawing 3 rectangles, two black ones with thin linewidths and one thicker white one, but the problem is that 'Position' is defined in axes units and 'LineWidth' is defined in point units, so that the scaling doesn't work too well, especially when the figure is resized.

FYI, the outline is so that the white rectangle is more visible against a light background. The images plotted vary widely, so a single color won't be universally visible for my data.

Any suggestions on how I can do this?

like image 333
user1207668 Avatar asked Feb 13 '12 20:02

user1207668


1 Answers

How about just using different line widths for black and white rectangle?

imshow('cameraman.tif')
rectangle('position',[80 30 100 100],'edgecolor','k','LineWidth',4)
rectangle('position',[80 30 100 100],'edgecolor','w','LineWidth',1)

cameraman with rectangle (Save As)

Hmm, the corners look much better on MATLAB figure than as PNG file.

Better with getframe:

cameraman with rectangle (getframe)

like image 155
yuk Avatar answered Sep 20 '22 22:09

yuk