Commit 41a9f6f8 authored by p.jhagema's avatar p.jhagema
Browse files

helper tool for figures: addToolsToToolbar. adds a crop and autoContrastbutton to figures

parent 3fcd1b4e
Pipeline #265407 failed with stage
in 45 seconds
function addAutoContrastToToolbar()
% ADDAUTOCONTRASTTOTOOLBAR adds an button in the toolbar to easily access
% the autoContrast function.
%
% ``addAutoContrastToToolbar()``
%
% This function alters the behavior of all figure windows after invocation.
% It alters the default function which is called by matlab upon creation of
% a new figure. Afterwards new figures have a new tool represented by a
% light bulb to adjust the contrast of an image.
%
% Returns
% -------
% This function changes the behavior of all figure created after
% invocation.
%
% See also
% --------
% autoContrast
%
% Example
% -------
%
% .. code-block:: matlab
%
% addAutoContrastToToolbar()
% figure;
% imagesc(rand(128))
% HoloTomoToolbox
% Copyright (C) 2019 Institut fuer Roentgenphysik, Universitaet Goettingen
%
% This program 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.
%
% This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
%
fig_cmd = ...
['addToolbarExplorationButtons(gcf);'...
'AutoContrastBtn = uipushtool(uitoolbar(gcf),''TooltipString'',''Auto Contrast Tool'', ''ClickedCallback'',''eval(''''autoContrast'''')'');'...
'[img,map] = imread(fullfile(matlabroot,''toolbox'',''matlab'',''icons'',''demoicon.gif''));'...
'AutoContrastBtn.CData = ind2rgb(img,map); '];
set(groot,'defaultFigureCreateFcn',fig_cmd)
end
......@@ -5,7 +5,7 @@ function autoCaxis = autoContrast(region)
% ----------
% region : region
% Region for which the contrast is optimized. If no input is given, the region is
% selected manually by drawing a rectangle in the current figure.
% selected manually by drawing a rectangle (imrect) in the current figure.
%
% Returns
% -------
......@@ -55,12 +55,9 @@ imageOriginal = getimage(currentFig);
% create mask
dimMask = round(region.getPosition);
mask = zeros(size(imageOriginal));
mask(dimMask(2):dimMask(2)+dimMask(4)-1,dimMask(1):dimMask(1)+dimMask(3)-1) = 1;
% only consider part of the image which lies within specified region
imageRegion = imageOriginal(mask==1);
imageRegion = reshape(imageRegion, dimMask(4), dimMask(3));
imageRegion = imageOriginal(dimMask(2):dimMask(2)+dimMask(4)-1,dimMask(1):dimMask(1)+dimMask(3)-1);
% apply median and averaging filter to remove outliers from the image which
% would otherwise lead to incorrect minimum and maximum values
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment