Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you add a border to an image?

Status
Not open for further replies.

Lehane

Mechanical
May 2, 2011
6
I am trying to analyse an image in Matlab and need to be able to see the left edge of the image. At the moment I add a 1 pixel border to the image (or just to the left side) in a photo program like Gimp. This is time consuming so I'm looking for a way to get Matlab to add the border for me.

At the moment I use

dispIm = imread(file,'tif');
imshow(dispIm);

Which then opens the image ready for analysis. What code can I add to add the black border?
 
Replies continue below

Recommended for you

good you solved it. Matlab has a computer vision toolbox that may be handy. Will be interesting to see how many CV researchers switch from C to Matlab because of it. Open CV is still a good resource though.

[peace]
Fe
 
You could use ImageMagick to add borders to your outputs. For Linux:
Code:
clear;clc;close all;
A = [0.866-0.5*i, 0.866+0.5*i, 0.000+1,0*i]'
h = figure(1);
compass(A)
W = 4; H = 3;
set(h,'PaperUnits','inches')
set(h,'PaperOrientation','portrait');
set(h,'PaperSize',[H,W])
set(h,'PaperPosition',[0,0,W,H])
FN = findall(h,'-property','FontName');
set(FN,'FontName','/usr/share/fonts/dejavu/DejaVuSerifCondensed.ttf');
FS = findall(h,'-property','FontSize');
set(FS,'FontSize',6);
print(h,'-dpng','bordertest.png');
system('convert bordertest.png -bordercolor green -border 10x10 bordertest.png')
In Windows, convert has some issues... but here is a discussion of how to get ImageMagick convert working in Windows:

//signed//
Christopher K. Hubley
Mechanical Engineer
Sunpower Incorporated
Athens, Ohio
 
I forgot in the previous post: The result of the above code is attached. Also, the important line from the above example is:
Code:
system('convert bordertest.png -bordercolor green -border 10x10 bordertest.png')
Clearly, you could change the border color to whatever you'd like.

//signed//
Christopher K. Hubley
Mechanical Engineer
Sunpower Incorporated
Athens, Ohio
 
 http://files.engineering.com/getfile.aspx?folder=3a61ed7d-3fbc-4eb2-8317-e1a5986ac6b0&file=bordertest.png
Status
Not open for further replies.

Part and Inventory Search

Sponsor