function adjfighandle = ImadjustGUI(imgin)
% IMADJUSTGUI: UI for interactive selection of IMADJUST parameters
%
% Syntax: IMADJUSTGUI(IMGIN)
% h = IMADJUSTGUI(IMGIN); (Outputs handle to the GUI figure.)
%
% IMADJUSTGUI launches an interactive, uicontrolled figure
% for use with the Image Processing Toolbox function
% IMADJUST. The class support for the input argument is the
% same as that for imadjust.
%
% The function will display two versions of the input image;
% the version of the left will be the original, un-adjusted
% image. The version on the right will change interactively
% when the slider controls are moved, updating the five
% arguments for imadjust: low_in, high_in, low_out,
% high_out, and gamma.(HELP IMADJUST for more details).
%
% When the "DONE/EXPORT" button is pressed, the output image
% will be written to the base workspace, along with the
% parameters used to create it, and the text of the command
% that will recreate it independent of ImadjustGUI.
%
% NOTE: This is an update of the IntensityAdjust GUI I
% previously shared on the File Exchange. REQUIRES THE Image
% Processing Toolbox.
%
% Written by Brett Shoelson, Ph.D.
% brett.shoelson@mathworks.com
% 9/03/2012
% Comments and suggestions welcome!
%
% Copyright 2012 MathWorks, Inc.
%
% SEE ALSO: IMADJUST
% Modifications:
% 2/23/13: Incorporated UIGETVARIABLES (via GETNEWIMAGE) to allow loading
% from workspace variables.
% 2/25/13: Added "Auto-Adjust" button to add stretchlim-based starting
% point. (Thanks to Abhijit Bhattacharjee for the suggestion!)
bgc = [0.553 0.659 0.678];
highlightColor = [0.85 0.9 0.9];
adjfig = figure('NumberTitle','off',...
'name','Select Image Adjustment Values',...
'units','normalized',...
'position',[0.1 0.1 0.8 0.85],...
'tag','intensityadjfig',...
'menubar','none',...
'windowstyle','normal',...
'color',bgc);
set(adjfig,'defaultuicontrolunits','normalized');
ht = uitoolbar(adjfig);
tmp = im2double(imread('file_open.png'));
tmp(tmp==0) = NaN;
uitoggletool(ht,...
'CData', tmp,...
'oncallback', @GetNewFile,...
'offcallback', '',...
'Tooltipstring', 'Load new image.',...
'Tag', 'loadImageTool');
tmp = imread('DefaultD.png');
uitoggletool(ht,...
'CData', tmp,...
'separator', 'on',...
'oncallback', @resetDefaults,...
'Tooltipstring', 'Resets all sliders to default values.');
if nargin == 0
imgin = 'peppers.png';
end
if ischar(imgin)
imname = imgin;
imgin = iptImread(imname);
else
imname = 'Original';
end
%
[objpos,objdim] = distributeObjects(2,0.025,0.975,0.025);
ax(1) = axes('parent',adjfig,...
'position',[objpos(1) 0.45 objdim 0.515],...
'xtick',[],'ytick',[]);
imshow(imgin,'parent',ax(1));
title(imname,'parent',ax(1),'interpreter','none');
ax(2) = axes('parent',adjfig,...
'position',[objpos(2) 0.45 objdim 0.515],...
'xtick',[],'ytick',[]);
imgOutHandle = imshow(imgin,'parent',ax(2));
title('Modified Image','parent',ax(2),'interpreter','none');
expandAxes(ax);
set(ax,'handlevisibility','callback');
% Histograms
colors = [1 0 0; 0 1 0; 0 0 1];
[hobjpos,hobjdim] = distributeObjects(3,objpos(1)+0.025,objdim+objpos(1)-0.025,0.0375);
histax = zeros(6,1);
for ii = 1:3
histax(ii) = subplot(1,6,ii,...
'parent',adjfig,...
'position',[hobjpos(ii) 0.3 hobjdim 0.1],...
'xtick',[],'ytick',[]);
refreshHistogram(histax(ii),imgin(:,:,ii),ii);
end
[hobjpos,hobjdim] = distributeObjects(3,objpos(2)+0.05,objdim+objpos(2)-0.05,0.0375);
for ii = 1:3
histax(ii+3) = subplot(1,6,ii+3,...
'parent',adjfig,...
'position',[hobjpos(ii) 0.3 hobjdim 0.1],...
'xtick',[],'ytick',[]);
refreshHistogram(histax(ii+3),imgin(:,:,ii),ii);
end
set(adjfig,'handlevisibility','callback');
%
processOpt = uibuttongroup('units','normalized',...
'visible','off',...
'parent',adjfig,...
'backgroundcolor',highlightColor,...
'position',[0.775 0.2 0.2 0.075]);
uicontrol('Style','Radio',...
'String','Process All Planes Together',...
'pos',[0.05 0.55 0.8 0.4],...
'parent',processOpt,...
'backgroundcolor',highlightColor,...
'HandleVisibility','off',...
'fontsize',12,...
'fontweight','bold');
uicontrol('Style','Radio',...
'String','Process Planes Individually',...
'pos',[0.05 0.05 0.8 0.4],...
'parent',processOpt,...
'backgroundcolor',highlightColor,...
'HandleVisibility','off',...
'fontsize',12,...
'fontweight','bold');
% Initialize some button group properties.
set(processOpt,'SelectionChangeFcn',@changePanel)
set(processOpt,'Visible','on');
processPanel(1) = uipanel('parent',adjfig,...
'backgroundcolor',highlightColor,...
'position',[0.025 0.025 0.725 0.25],...
'visible','on');
processPanel(2) = uipanel('parent',adjfig,...
'backgroundcolor',highlightColor,...
'position',[0.025 0.025 0.725 0.25],...
'visible','off');
%
[objpos,objdim] = distributeObjects(3,0.05,0.95,0.05);
% [sliderHandle,panelHandle,editHandle] =
% sliderPanel(parent,PanelPVs,SliderPVs,EditPVs,LabelPVs,numFormat);
%%% PROCESS TOGETHER
uicontrol('style','text',...
'string','J = imadjust(I, [LOW_IN; HIGH_IN], [LOW_OUT; HIGH_OUT], GAMMA)',...
'parent',processPanel(1),...
'position',[0.05 0.85 0.9 0.1],...
'fontsize',12,...
'backgroundcolor', highlightColor,...
'fontweight','bold');
[lowInSlider,~,lowInText] = sliderPanel(processPanel(1),...
{'Position', [objpos(1), 0.455, objdim, 0.35],'Title', 'LOW-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[lowOutSlider,~,lowOutText] = sliderPanel(processPanel(1),...
{'Position', [objpos(2), 0.455, objdim, 0.35],'Title', 'LOW-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highInSlider,~,highInText] = sliderPanel(processPanel(1),...
{'Position', [objpos(1), 0.05, objdim, 0.35],'Title', 'HIGH-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highOutSlider,~,highOutText] = sliderPanel(processPanel(1),...
{'Position', [objpos(2), 0.05, objdim, 0.35],'Title', 'HIGH-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[gammaSlider,~,gammaSliderText] = sliderPanel(processPanel(1),...
{'Position', [objpos(3), 0.455, objdim, 0.35],'Title', 'Gamma','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 10, 'Value', 1,'tag','gamma','callback',@update,'backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
%%% PROCESS SEPARATELY
uicontrol('style','text',...
'string','J = imadjust(I, [LOW_IN; HIGH_IN], [LOW_OUT; HIGH_OUT], GAMMA)',...
'parent',processPanel(2),...
'position',[0.05 0.85 0.9 0.1],...
'fontsize',12,...
'backgroundcolor', highlightColor,...
'fontweight','bold');
uicontrol('style','text',...
'string','R',...
'parent',processPanel(2),...
'position',[objpos(1) 0.75 objdim 0.1],...
'fontsize',18,...
'backgroundcolor', highlightColor,...
'foregroundcolor','r',...
'fontweight','bold');
uicontrol('style','text',...
'string','G',...
'parent',processPanel(2),...
'position',[objpos(2) 0.75 objdim 0.1],...
'fontsize',18,...
'backgroundcolor', highlightColor,...
'foregroundcolor',[0 0.5 0],...
'fontweight','bold');
uicontrol('style','text',...
'string','B',...
'parent',processPanel(2),...
'position',[objpos(3) 0.75 objdim 0.1],...
'fontsize',18,...
'backgroundcolor', highlightColor,...
'foregroundcolor','b',...
'fontweight','bold');
[objpos,objdim] = distributeObjects(3,0.015,0.985,0.025);
[hobjpos,hobjdim] = distributeObjects(3,objpos(1),objpos(1)+objdim,0.005);
[vobjpos,vobjdim] = distributeObjects(2,0.025,0.7,0.015);
[lowInSliderR,~,lowInTextR] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[lowOutSliderR,~,lowOutTextR] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highInSliderR,~,highInTextR] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highOutSliderR,~,highOutTextR] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[gammaSliderR,~,gammaSliderTextR] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(3), vobjpos(2), hobjdim, vobjdim],'Title', 'Gamma','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 10, 'Value', 1,'tag','gamma','callback',@update,'backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
%
[hobjpos,hobjdim] = distributeObjects(3,objpos(2),objpos(2)+objdim,0.01);
[lowInSliderG,~,lowInTextG] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[lowOutSliderG,~,lowOutTextG] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highInSliderG,~,highInTextG] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highOutSliderG,~,highOutTextG] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[gammaSliderG,~,gammaSliderTextG] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(3), vobjpos(2), hobjdim, vobjdim],'Title', 'Gamma','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 10, 'Value', 1,'tag','gamma','callback',@update,'backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
%
[hobjpos,hobjdim] = distributeObjects(3,objpos(3),objpos(3)+objdim,0.01);
[lowInSliderB,~,lowInTextB] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[lowOutSliderB,~,lowOutTextB] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(2), hobjdim, vobjdim],'Title', 'LOW-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 0,'tag','lowout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highInSliderB,~,highInTextB] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(1), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-IN','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highin','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[highOutSliderB,~,highOutTextB] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(2), vobjpos(1), hobjdim, vobjdim],'Title', 'HIGH-OUT','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 1, 'Value', 1,'tag','highout','callback',@update,'Backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
[gammaSliderB,~,gammaSliderTextB] = sliderPanel(processPanel(2),...
{'Position', [hobjpos(3), vobjpos(2), hobjdim, vobjdim],'Title', 'Gamma','Backgroundcolor', highlightColor},...
{'Min', 0, 'Max', 10, 'Value', 1,'tag','gamma','callback',@update,'backgroundcolor', bgc},...
{'backgroundcolor', highlightColor},...
{'Backgroundcolor', highlightColor},...
'%0.2f');
%%% DONE
uicontrol('parent',adjfig,...
'style','pushbutton',...
'string','DONE / EXPORT',...
'units','normalized',...
'position',[0.775 0.025 0.2 0.08],...
'foregroundcolor',[1 .4 .4],...
'fontname','Helvetica',...
'fontsize',14,...
'fontweight','bold',...
'callback',@finish);
luckyButton = uicontrol('parent',adjfig,...
'style','pushbutton',...
'string','Auto-Adjust',...
'units','normalized',...
'position',[0.775 0.125 0.2 0.05],...
'foregroundcolor','k',...
'fontname','Helvetica',...
'fontsize',14,...
'fontweight','bold',...
'tooltipstring','Use |stretchlim| uniformly on all planes to saturate the top and bottom 1% of the intensities.',...
'callback',@IFeelLucky);
if nargout > 0
adjfighandle = adjfig;
else
clear adjfighandle;
end
function changePanel(varargin)
if strcmp(get(processPanel(1),'visible'),'on')
set(processPanel(1),'visible','off')
set(processPanel(2),'visible','on')
set(luckyButton,'tooltipstring','Use |stretchlim| plane-by-plane to saturate the top and bottom 1% of the intensities.')
else
set(processPanel(1),'visible','on')
set(processPanel(2),'visible','off')
set(luckyButton,'tooltipstring','Use |stretchlim| uniformly on all planes to saturate the top and bottom 1% of the intensities.')
end
end %finish
function finish(varargin)
processTogether = strcmp(get(processPanel(1),'visible'),'on');
[lowin,lowout,highin,highout,gammaval] = getparams(processTogether);
%
fprintf('\n\nCALLING SYTNAX:\n**************************\n');
% J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT],GAMMA)
if processTogether
fprintf('imgout = imadjust(imgin,[%0.2f; %0.2f],[%0.2f; %0.2f], %0.2f);',lowin,highin,lowout,highout,gammaval);
fprintf('\n\nOR\n\nprocessImage = @(x) imadjust(x,[%0.2f; %0.2f],[%0.2f; %0.2f], %0.2f);',lowin,highin,lowout,highout,gammaval);
fprintf('\nimgout = processImage(imgin);');
% fprintf('\n\nOR\n\nprocessImage = @(x,li,hi,lo,ho,g) imadjust(x,[li; hi],[lo; ho], g);');
% fprintf('\nimgout = processImage(imgin,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f);',lowin,highin,lowout,highout,gammaval)
else
fprintf('imgout = imadjust(imgin,[%0.2f %0.2f %0.2f; %0.2f %0.2f %0.2f],[%0.2f %0.2f %0.2f; %0.2f %0.2f %0.2f], [%0.2f %0.2f %0.2f]);',lowin,highin,lowout,highout,gammaval);
fprintf('\n\nOR\n\nprocessImage = @(x) imadjust(x,[%0.2f %0.2f %0.2f; %0.2f %0.2f %0.2f],[%0.2f %0.2f %0.2f; %0.2f %0.2f %0.2f], [%0.2f %0.2f %0.2f]);',lowin,highin,lowout,highout,gammaval);
fprintf('\nimgout = processImage(imgin);');
end
fprintf('\n**************************\n\n')
varname = evalin('base','genvarname(''ImgOut'',who)');
assignin('base',varname,get(imgOutHandle,'cdata'));
fprintf('Output image written to variable %s in the base workspace.\n\n',varname);
end %finish
function GetNewFile(varargin)
set(gcbo,'state','off');
[imgin,cmap,fname,~,userCanceled] = getNewImage(false);
if userCanceled
return
end
if isempty(fname),fname = 'Original'; end
imshow(imgin,cmap,'parent',ax(1));
title(fname,'parent',ax(1),'interpreter','none');
imgOutHandle = imshow(imgin,cmap,'parent',ax(2));
title('Modified Image','interpreter','none');
set(ax,'handlevisibility','callback');
expandAxes(ax);
update('all');
end %GetNewFile
function [lowin,lowout,highin,highout,gammaval,ii] = getparams(processTogether)
if processTogether
lowin = get(lowInSlider,'value');
lowout = get(lowOutSlider,'value');
highin = get(highInSlider,'value');
highout = get(highOutSlider,'value');
gammaval = get(gammaSlider,'value');
highin(highin == 0) = eps;
lowin(lowin >= highin) = highin-eps;
set(lowInSlider,'value',lowin);
set(lowInText,'string',num2str(lowin));
set(highInSlider,'value',highin);
set(highInText,'string',num2str(highin));
drawnow
else
lowin = [get(lowInSliderR,'value') get(lowInSliderG,'value') get(lowInSliderB,'value')];
lowout = [get(lowOutSliderR,'value') get(lowOutSliderG,'value') get(lowOutSliderB,'value')];
highin = [get(highInSliderR,'value') get(highInSliderG,'value') get(highInSliderB,'value')];
highout = [get(highOutSliderR,'value') get(highOutSliderG,'value') get(highOutSliderB,'value')];
gammaval = [get(gammaSliderR,'value') get(gammaSliderG,'value') get(gammaSliderB,'value')];
highin(highin == 0) = eps;
for ii = 1:3
if lowin(ii) >= highin(ii)
lowin(ii) = highin(ii) -eps;
end
end
set(lowInSliderR,'value',lowin(1));
set(lowInSliderG,'value',lowin(2));
set(lowInSliderB,'value',lowin(3));
set(lowInTextR,'string',num2str(lowin(1)));
set(lowInTextG,'string',num2str(lowin(2)));
set(lowInTextB,'string',num2str(lowin(3)));
set(highInSliderR,'value',highin(1));
set(highInSliderG,'value',highin(2));
set(highInSliderB,'value',highin(3));
set(highInTextR,'string',num2str(highin(1)));
set(highInTextG,'string',num2str(highin(2)));
set(highInTextB,'string',num2str(highin(3)));
drawnow
end
end %getparams
function IFeelLucky(varargin)
% USE STRETCHLIM
sl = stretchlim(imgin);
opt = get(get(processOpt,'SelectedObject'),'string');
switch opt
case 'Process All Planes Together'
if size(imgin,3) ~= 1
beep
disp('Processing all planes of an RGB Image simultaneously. You may get better results processing plane-by-plane.');
end
sl = mean(sl,2);
set(lowInSlider,'value',sl(1));
set(highInSlider,'value',sl(2));
case 'Process Planes Individually'
set(lowInSliderR,'value',sl(1));
set(highInSliderR,'value',sl(2));
set(lowInSliderG,'value',sl(3));
set(highInSliderG,'value',sl(4));
set(lowInSliderB,'value',sl(5));
set(highInSliderB,'value',sl(6));
end
drawnow;
update;
end %IFeelLucky
function imout = iptImread(imname,varargin)
[~,~,ext] = fileparts(imname);
switch ext
case '.dcm'
imout = dicomread(imname);
case {'.fits','.fts'}
imout = fitsread(imname);
case '.img'
try
imout = analyze75read(imname);
catch
try
imout = interfilered(imname);
catch
error('Unknown image format.');
end
end
case '.nitf'
imout = nitfread(imname);
case '.hdr'
imout = hdrread(imname);
otherwise
imout = imread(imname);
end
end %iptImread
function refreshHistogram(theAx,thePlane,ind,varargin)
axes(theAx);
imhist(thePlane);
fo = findall(theAx,'type','line','linestyle','-');
set(fo,'color',colors(mod(ind-1,3)+1,:));
end %refreshHistogram
function resetDefaults(varargin)
set(gcbo,'state','off');
processTogether = strcmp(get(processPanel(1),'visible'),'on');
if processTogether
set([lowInSlider,lowOutSlider],'value',0);
set([highInSlider,highOutSlider,gammaSlider],'value',1);
set([lowInText,lowOutText],'string','0');
set([highInText,highOutText,gammaSliderText],'string','1');
else
set([lowInSliderR,lowOutSliderR,lowInSliderG,lowOutSliderG,lowInSliderB,lowOutSliderB],'value',0);
set([highInSliderR,highOutSliderR,gammaSliderR,highInSliderG,highOutSliderG,gammaSliderG,highInSliderB,highOutSliderB,gammaSliderB],'value',1);
set([lowInTextR,lowOutTextR,lowInTextG,lowOutTextG,lowInTextB,lowOutTextB],'string','0');
set([highInTextR,highOutTextR,gammaSliderTextR,highInTextG,highOutTextG,gammaSliderTextG,highInTextB,highOutTextB,gammaSliderTextB],'string','1');
end
update;
end %resetDefaults
function ii = update(opt,varargin)
processTogether = strcmp(get(processPanel(1),'visible'),'on');
[lowin,lowout,highin,highout,gammaval] = getparams(processTogether);
imgout = imadjust(imgin, [lowin;highin], [lowout;highout], gammaval);
set(imgOutHandle,'cdata',imgout);
if nargin ~= 0 && ischar(opt) && strcmp(opt,'all')
for ii = 1:6
refreshHistogram(histax(ii),imgout(:,:,mod(ii-1,3)+1),ii);
end
else
for ii = 1:3
refreshHistogram(histax(ii+3),imgout(:,:,ii),ii);
end
end
end %update
end