Skip to content
Snippets Groups Projects
Commit 76788817 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Figures-extras: added image inset generation

parent fa752294
No related branches found
No related tags found
No related merge requests found
......@@ -28,8 +28,10 @@ function apply_extras(ax, im_props, extras)
add_arrow(ax, extras)
case 'segment'
add_segment(ax, extras)
case 'inset'
add_inset(ax, extras)
case 'inset_zoom'
add_inset(ax, extras, 'zoom')
case 'inset_image'
add_inset(ax, extras, 'image')
end
end
......@@ -147,25 +149,46 @@ function add_segment(ax, ex_props)
'LineWidth', ex_props.line_width, 'LineStyle', ex_props.line_style)
end
function add_inset(ax, ex_props)
function add_inset(ax, ex_props, type)
cdata = permute(getimage(ax), [2 1 3]);
switch (lower(type))
case 'zoom'
cdata = permute(getimage(ax), [2 1 3]);
shifts = min(ex_props.region(3:4) ./ ex_props.position(3:4) - 0.5, 0);
region_start = ex_props.region(1:2) + shifts;
region_end = ex_props.region(1:2) + ex_props.region(3:4) - 1 - shifts;
yy = linspace(region_start(1), region_end(1), ex_props.position(3));
xx = linspace(region_start(2), region_end(2), ex_props.position(4));
method_type = 'nearest';
oversampling = [1, 1];
shifts = min(ex_props.region(3:4) ./ ex_props.position(3:4) - 0.5, 0);
region_start = ex_props.region(1:2) + shifts;
region_end = ex_props.region(1:2) + ex_props.region(3:4) - 1 - shifts;
case 'image'
cdata = im2double(permute(ex_props.image, [2 1 3]));
region = [1, 1, size(cdata, 1), size(cdata, 2)];
method_type = 'nearest';
oversampling = ceil(region(3:4) ./ ex_props.position(3:4));
shifts = min(region(3:4) ./ (ex_props.position(3:4) .* oversampling) - 0.5, 0);
region_start = region(1:2) + shifts;
region_end = region(1:2) + region(3:4) - 1 - shifts;
otherwise
error('gtFigureAddExtras:wrong_argument', ...
'No known inset type: %s', type)
end
yy = linspace(region_start(1), region_end(1), ex_props.position(3) * oversampling(1));
xx = linspace(region_start(2), region_end(2), ex_props.position(4) * oversampling(2));
if (numel(size(cdata)) == 3)
zz = [1 2 3];
[xx, yy, zz] = ndgrid(xx, yy, zz);
inset_data = interp3(cdata, xx, yy, zz, 'nearest');
inset_data = interp3(cdata, xx, yy, zz, method_type, 0);
else
[xx, yy] = ndgrid(xx, yy);
inset_data = interp2(cdata, xx, yy, 'nearest');
inset_data = interp2(cdata, xx, yy, method_type, 0);
end
inset_data = reshape(inset_data, oversampling(2), ex_props.position(4), oversampling(1), ex_props.position(3), []);
inset_data = squeeze(sum(sum(inset_data, 1), 3)) / prod(oversampling);
hold(ax, 'on')
% watch out for the inversion of coordinates xx and yy here
......@@ -175,8 +198,5 @@ function add_inset(ax, ex_props)
hold(ax, 'off')
add_box(ax, ex_props);
ex_props_region = ex_props;
ex_props_region.position = ex_props_region.region;
add_box(ax, ex_props_region);
end
......@@ -12,8 +12,10 @@ function extras = gtFigureCreateExtras(type, varargin)
extras = create_arrow(varargin{:});
case 'segment'
extras = create_segment(varargin{:});
case 'inset'
extras = create_inset(varargin{:});
case 'inset_zoom'
extras = create_inset_zoom(varargin{:});
case 'inset_image'
extras = create_inset_image(varargin{:});
end
extras.type = type;
end
......@@ -84,7 +86,7 @@ function extras = create_segment(varargin)
extras = parse_pv_pairs(extras, varargin);
end
function extras = create_inset(varargin)
function extras = create_inset_zoom(varargin)
extras = struct( ...
'line_width', 1, ...
'line_style', '-', ...
......@@ -94,3 +96,13 @@ function extras = create_inset(varargin)
extras = parse_pv_pairs(extras, varargin);
end
function extras = create_inset_image(varargin)
extras = struct( ...
'line_width', 1, ...
'line_style', '-', ...
'image', [], ...
'position', [1 1 10 10], ...
'color', [1 1 1] );
extras = parse_pv_pairs(extras, varargin);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment