function  showImage(data, location, range)
%
%
% Original Author: Koen Van Leemput (kvle)
% Modified by Christian Thode Larsen, christian.thode.larsen@gmail.com

if (nargin < 3)
  range = double([min(data(:)), max(data(:))]);
end

[Nx, Ny, Nz] = size(data);

if (nargin < 2 || isempty(location))
    location = [round(Nx * 0.5), round(Ny * 0.5), round(Nz * 0.5)];
end

xySlice = squeeze(data(:, :, location(3), :));
xzSlice = squeeze(data(:, location(2), :, :));
yzSlice = squeeze(data(location(1), :, :, :));


if (ndims(data) < 4)
  patchedSlices = [xySlice, xzSlice; yzSlice', zeros(Nz) + range(1)];
  patchedSlices = (single(patchedSlices) - range(1)) / (range(2) - range(1));
  imshow(patchedSlices',  'InitialMagnification', 'fit');
else
  % RGB data
  patchedSlices = [xySlice, xzSlice; permute(yzSlice, [2, 1, 3]), zeros(Nz, Nz, 3)];  
  imshow(permute(patchedSlices, [2, 1, 3]), 'InitialMagnification', 'fit');
end
