contrastModulate - contrast modulates an image according to a map resultImg = contrastModulate(img, modulationMap, baseContrast, baseColor) contrast modulates image img such that that it has full contrast where modulationMask is 1. Img is an Image structure, modulationMap a map assumed to be scaled between 0 and 1 and of the same size as img. baseContrast (between 0 and 1) is the image contrast where modulationMap = 0. baseColor is the color at locations with low contrast. resultImg = contrastModulate(img, modulationMap, baseContrast) assumes baseColor = [1 1 1] (white). resultImg = contrastModulate(img, modulationMap, baseContrast) assumes baseContrast = 0 (opaque). See also plotSalientLocation, dataStructures.
0001 function resultImg = contrastModulate(img, modulationMap, varargin) 0002 % contrastModulate - contrast modulates an image according to a map 0003 % 0004 % resultImg = contrastModulate(img, modulationMap, baseContrast, baseColor) 0005 % contrast modulates image img such that that it has full 0006 % contrast where modulationMask is 1. 0007 % Img is an Image structure, modulationMap a map assumed 0008 % to be scaled between 0 and 1 and of the same size as img. 0009 % baseContrast (between 0 and 1) is the image contrast 0010 % where modulationMap = 0. 0011 % baseColor is the color at locations with low contrast. 0012 % 0013 % resultImg = contrastModulate(img, modulationMap, baseContrast) 0014 % assumes baseColor = [1 1 1] (white). 0015 % 0016 % resultImg = contrastModulate(img, modulationMap, baseContrast) 0017 % assumes baseContrast = 0 (opaque). 0018 % 0019 % See also plotSalientLocation, dataStructures. 0020 0021 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2007 0022 % by Dirk B. Walther and the California Institute of Technology. 0023 % See the enclosed LICENSE.TXT document for the license agreement. 0024 % More information about this project is available at: 0025 % http://www.saliencytoolbox.net 0026 0027 if length(varargin) >= 1 0028 baseCon = varargin{1}; 0029 else 0030 baseCon = 0; 0031 end 0032 0033 if length(varargin) >= 2 0034 baseCol = varargin{2}; 0035 if numel(baseCol) == 1 0036 baseCol = baseCol * [1 1 1]; 0037 end 0038 else 0039 baseCol = [1 1 1]; 0040 end 0041 0042 imData = loadImage(img); 0043 if img.dims == 2 0044 imData = repmat(imData,[1 1 3]); 0045 end 0046 0047 m = modulationMap.data; 0048 if (size(m,1) ~= img.size(1) || size(m,2) ~= img.size(2)) 0049 fatal('Image and modulation map must have the same size!'); 0050 end 0051 0052 alpha = m * (1 - baseCon) + baseCon; 0053 beta = 1 - alpha; 0054 for c = 1:3 0055 res(:,:,c) = alpha.*imData(:,:,c) + beta*baseCol(c); 0056 end 0057 0058 if isnan(img.filename) 0059 label = 'contrast modulated image'; 0060 else 0061 label = ['contrast modulated ' img.filename]; 0062 end 0063 resultImg = initializeImage(res,label);