Home > SuperSegger > Internal > ag.m

ag

PURPOSE ^

ag : autogain, it increases the contrast of image im, using imin and imax.

SYNOPSIS ^

function [im,im_min,imax] = ag (im,imin,imax)

DESCRIPTION ^

 ag : autogain, it increases the contrast of image im, using imin and imax.
 It subtracts the the minimum from of the image, divides by the max and
 then normalizes to 255.

 INPUT : 
       im : image
       imin : min value used to set autogained image (default : min of image)
       imax : max value used to set autogained image (default : max of image)
 OUTPUT :
       im : autogained image with increased contrast.


 Copyright (C) 2016 Wiggins Lab 
 Written by Paul Wiggins.
 University of Washington, 2016
 This file is part of SuperSegger.
 
 SuperSegger is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SuperSegger is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [im,im_min,imax] = ag (im,imin,imax)
0002 % ag : autogain, it increases the contrast of image im, using imin and imax.
0003 % It subtracts the the minimum from of the image, divides by the max and
0004 % then normalizes to 255.
0005 %
0006 % INPUT :
0007 %       im : image
0008 %       imin : min value used to set autogained image (default : min of image)
0009 %       imax : max value used to set autogained image (default : max of image)
0010 % OUTPUT :
0011 %       im : autogained image with increased contrast.
0012 %
0013 %
0014 % Copyright (C) 2016 Wiggins Lab
0015 % Written by Paul Wiggins.
0016 % University of Washington, 2016
0017 % This file is part of SuperSegger.
0018 %
0019 % SuperSegger is free software: you can redistribute it and/or modify
0020 % it under the terms of the GNU General Public License as published by
0021 % the Free Software Foundation, either version 3 of the License, or
0022 % (at your option) any later version.
0023 %
0024 % SuperSegger is distributed in the hope that it will be useful,
0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 % GNU General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU General Public License
0030 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0031 
0032 im = double(im);
0033 
0034 im(isinf(im(:))) = nan;
0035 
0036 if exist( 'imin', 'var') && ~isempty(  imin )
0037     im_min = imin;
0038 else
0039     im_min = min(im(:));
0040 end
0041 
0042 if ~exist( 'imax', 'var') || isempty(imax)
0043     imax = max(im(:));
0044 end
0045 
0046 im_max = imax-im_min;
0047 
0048 % subtract min
0049 im = im - double(im_min);
0050 
0051 
0052    % autogain and normalization to uint8
0053 im = uint8(255*im/double(im_max));
0054 
0055 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005