Home > SaliencyToolbox > drawDisk.m

drawDisk

PURPOSE ^

drawDisk - draws a solid disk into a 2d image.

SYNOPSIS ^

function resultMap = drawDisk(bgMap,center,radius,value)

DESCRIPTION ^

 drawDisk - draws a solid disk into a 2d image.

 resultMap = drawDisk(bgMap,center,radius,value)
    Draws a solid disk with radius 'radius' around 'center'
    into the background map 'bgMap' and fills it
    with 'value'.
    Returns a map structure if bgMap is given as a map structure.
    Returns a 2d array if bgMap is given as a 2d array.

 See also plotSalientLocation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % drawDisk - draws a solid disk into a 2d image.
0002 %
0003 % resultMap = drawDisk(bgMap,center,radius,value)
0004 %    Draws a solid disk with radius 'radius' around 'center'
0005 %    into the background map 'bgMap' and fills it
0006 %    with 'value'.
0007 %    Returns a map structure if bgMap is given as a map structure.
0008 %    Returns a 2d array if bgMap is given as a 2d array.
0009 %
0010 % See also plotSalientLocation.
0011 
0012 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0013 % by Dirk B. Walther and the California Institute of Technology.
0014 % See the enclosed LICENSE.TXT document for the license agreement.
0015 % More information about this project is available at:
0016 % http://www.saliencytoolbox.net
0017 
0018 function resultMap = drawDisk(bgMap,center,radius,value)
0019 
0020 if isstruct(bgMap)
0021   bg = bgMap.data;
0022 else
0023   bg = bgMap;
0024 end
0025 
0026 % create the disk
0027 [xx,yy] = meshgrid(-radius:radius);
0028 disk = (xx.^2 + yy.^2 <= radius^2);
0029 
0030 % need to clip the top?
0031 tb = center(1) - radius; td = 1;
0032 if (tb < 1)
0033   td = 2 - tb;
0034   tb = 1;
0035 end
0036 
0037 % need to clip the bottom?
0038 bb = center(1) + radius; bd = size(disk,2);
0039 if (bb > size(bg,1))
0040   bd = bd - (bb - size(bg,1));
0041   bb = size(bg,1);
0042 end
0043 
0044 % need to clip left?
0045 lb = center(2) - radius; ld = 1;
0046 if (lb < 1)
0047   ld = 2 - lb;
0048   lb = 1;
0049 end
0050 
0051 % need to clip right?
0052 rb = center(2) + radius; rd = size(disk,2);
0053 if (rb > size(bg,2))
0054   rd = rd - (rb - size(bg,2));
0055   rb = size(bg,2);
0056 end
0057 
0058 % draw the disk into the result
0059 result = bg;
0060 cutRes = result(tb:bb,lb:rb);
0061 cutDisk = disk(td:bd,ld:rd);
0062 cutRes(cutDisk) = value;
0063 result(tb:bb,lb:rb) = cutRes;
0064 
0065 if isstruct(bgMap)
0066   resultMap = bgMap;
0067   resultMap.data = result;
0068   resultMap.label = [resultMap.label ' disk'];
0069 else
0070   resultMap = result;
0071 end

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005