Code covered by the BSD License  

Highlights from
DrawRect

DrawRect

by

 

Draws a 1-pixel rectangle on an input image with a given color ('r', 'g' or 'b').

DrawRect(wrimage,rect1,color)
% DRAWRECT 
% Draws a rectangle with a given color (r,g,b) onto a given image

% USAGE

% INPUT
% im = DrawRect(wrimage,rect1,color)
% wrimage is the input color image.
% rect1 is the rectangle coordinates in the form [x y width height].
% color is either 'r', 'g' or 'b'.

% OUTPUT
% output is im, which contains a 1 pixel thick rectangle drawn over the
% image as per inputs desired. 

% Copyright (c) 2011 Vidya Murali
% Coughlan Lab
% Smith Kettlewell Eye Research Institute
% http://www.ski.org/Rehab/Coughlan_lab/General/VidyaMurali.html
% 


% Feb 2012    - Original version
%----------------------------------------------%



function im = DrawRect(wrimage,rect1,color)

ix1=rect1(1):rect1(1)+rect1(3); iy1=rect1(2);
ix2=rect1(1):rect1(1)+rect1(3); iy2=rect1(2)+rect1(4);
iy3=rect1(2):rect1(2)+rect1(4); ix3=rect1(1);
iy4=rect1(2):rect1(2)+rect1(4); ix4=rect1(1)+rect1(3);
ix1=ceil(ix1);ix2=ceil(ix2);ix3=ceil(ix3);ix4=ceil(ix4);
iy1=ceil(iy1);iy2=ceil(iy2);iy3=ceil(iy3);iy4=ceil(iy4);


if color=='g'
wrimage(iy1,ix1,1)= 0;wrimage(iy1,ix1,2)= 255;wrimage(iy1,ix1,3)= 0;
wrimage(iy2,ix2,1)= 0;wrimage(iy2,ix2,2)= 255;wrimage(iy2,ix2,3)= 0;
wrimage(iy3,ix3,1)= 0;wrimage(iy3,ix3,2)= 255;wrimage(iy3,ix3,3)= 0;
wrimage(iy4,ix4,1)= 0;wrimage(iy4,ix4,2)= 255;wrimage(iy4,ix4,3)= 0;
end


if color=='b'
wrimage(iy1,ix1,1)= 0;wrimage(iy1,ix1,2)= 0;wrimage(iy1,ix1,3)= 255;
wrimage(iy2,ix2,1)= 0;wrimage(iy2,ix2,2)= 0;wrimage(iy2,ix2,3)= 255;
wrimage(iy3,ix3,1)= 0;wrimage(iy3,ix3,2)= 0;wrimage(iy3,ix3,3)= 255;
wrimage(iy4,ix4,1)= 0;wrimage(iy4,ix4,2)= 0;wrimage(iy4,ix4,3)= 255;
end


if color=='r'
wrimage(iy1,ix1,1)= 255;wrimage(iy1,ix1,2)= 0;wrimage(iy1,ix1,3)= 0;
wrimage(iy2,ix2,1)= 255;wrimage(iy2,ix2,2)= 0;wrimage(iy2,ix2,3)= 0;
wrimage(iy3,ix3,1)= 255;wrimage(iy3,ix3,2)= 0;wrimage(iy3,ix3,3)= 0;
wrimage(iy4,ix4,1)= 255;wrimage(iy4,ix4,2)= 0;wrimage(iy4,ix4,3)= 0;
end

im=wrimage;

Contact us