之前写过一个MATLAB在图片上画框的代码, http://blog.csdn.net/carson2005/article/details/17262811
最近使用后发现效果不好,貌似有个bug,这里做更改,
function [state result] = draw_rect(img, rectVec, showOrNot)
%img: input color image
%rectVec: input vector of rect draw on image. element in rectVec: x, y,
%width, height
rgb = [255 0 0];
result = img;
[imgH, imgW] = size(img);
if size(img,3) == 3 %draw on color image
for k=1:3
for i=1:size(rectVec,1)
if( rectVec(i,1)>=0 && rectVec(i,2)>=0 && rectVec(i,1)+rectVec(i,3)<=imgW && rectVec(i,2)+rectVec(i,4)<=imgH )
result( rectVec(i,2),rectVec(i,1):(rectVec(i,1)+rectVec(i,3)),k ) = rgb(1,k);%top line
result( rectVec(i,2)+1,rectVec(i,1):(rectVec(i,1)+rectVec(i,3)),k ) = rgb(1,k);
resu