From 7b42ac30b6667a163fa7beae09a04aec06e42d9e Mon Sep 17 00:00:00 2001 From: Sue Ann Koay Date: Wed, 21 Sep 2016 12:38:19 -0400 Subject: [PATCH] Added required dependencies. --- .gitignore | 3 +++ MovieSlider.m | 2 +- rebin.m | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 rebin.m diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05ee704 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +#ignore thumbnails created by windows +Thumbs.db +*.asv diff --git a/MovieSlider.m b/MovieSlider.m index 7173327..59c433b 100644 --- a/MovieSlider.m +++ b/MovieSlider.m @@ -442,7 +442,7 @@ function setContrast(obj, contrast) saturation = MovieSlider.CONTRAST_RANGE(obj.contrastIndex); sel = [1, 1 + find(diff(obj.pixelCDF) ~= 0)]; - iValue = binarySearch(obj.pixelCDF(sel), [saturation, 1-saturation], 0, 0.5); + iValue = interp1(obj.pixelCDF(sel), 1:numel(sel), [saturation, 1-saturation], 'linear', 'extrap'); obj.pixelRange = obj.pixelValue([1 end]); inRange = iValue > 1 & iValue < numel(sel); iValue = iValue(inRange); diff --git a/rebin.m b/rebin.m new file mode 100644 index 0000000..21abbdf --- /dev/null +++ b/rebin.m @@ -0,0 +1,36 @@ +function rebinned = rebin(data, grouping, dimensions, aggregateFcn, varargin) + + if nargin < 3 || isempty(dimensions) + [~,dimensions] = max(size(data)); + end + if nargin < 4 || isempty(aggregateFcn) + aggregateFcn = @mean; + end + + for dim = dimensions + original = size(data); + standardized = [ prod(original(1:dim-1)) ... + , original(dim) ... + , prod(original(dim+1:end)) ... + ]; + data = reshape(data, standardized); + + numGroups = ceil(original(dim) / grouping); + if islogical(data) + rebinned = false(standardized(1), numGroups, standardized(end)); + elseif isinteger(data) + rebinned = zeros(standardized(1), numGroups, standardized(end), 'like', data); + else + rebinned = nan(standardized(1), numGroups, standardized(end), 'like', data); + end + iSource = 1; + for iGroup = 1:numGroups + rebinned(:,iGroup,:) = aggregateFcn(data(:,iSource:min(iSource+grouping-1, end),:), 2, varargin{:}); + iSource = iSource + grouping; + end + rebinned = reshape(rebinned, [original(1:dim-1), numGroups, original(dim+1:end)]); + + data = rebinned; + end + +end