% twimshow - display and quickly switch between input images/ video sequences
% Version 2.0
% Last update April 30, 2013 - Aram Danielyan
% usage examples
% twimshow(video1)
% or
% twimshow({video1 video2 ... videoN})
% video1, video2, ..., videoN - are 2-D (images) or 3-D arrays
% twimshow({video1 video2 ... videoN}, [low high])
% Display ALL sequences with [low high] intensity range.
% If [low high] is an empty matrix, dispaly range is set to
% [min(video1(:)) max(video1(:))]
% twimshow({video1 video2 ... videoN}, {[low1 high1] [low2 high2] ... [lowN highN]})
% Display squence K with the intensity range [lowK highK].
% If [lowK highK] is an empty matrix, the dispaly range for K-th sequence is set to
% [min(videoK(:)) max(videoK(:))]
% twimshow({video1 video2 ... videoN}, {[low1 high1] [low2 high2] ... [lowN highN]})
% Display squence K with the intensity range [lowK highK].
% If [lowK highK] is an empty matrix, the dispaly range for K-th sequence is set to
% [min(videoK(:)) max(videoK(:))]
% twimshow({video1 video2 ... videoN}, {[low1 high1] [low2 high2] ... [lowN highN]}, ...
% {'name1', 'name2', ...., 'nameN'})
% Show nameK as a captions when videoK is displayed
% key controls
% 1,2,3, ..., 9, 0 - switch between inputs
% left/right arrow keys - show next/previous frame
% c - change brightness/contrast via imcontrast
function twimshow(z, cmap, datasetNames, curImInd)
link_cmaps = false;
if ~iscell(z), z={z}; end
if ~exist('cmap','var') || isempty(cmap)
cmap{1}= [];
elseif ~iscell(cmap)
cmap= {cmap};
end
if (numel(cmap)==1), link_cmaps = true; end
for m=1:numel(cmap)
if isempty(cmap{m})
cmap{m} = [min(z{m}(:)) max(z{m}(:))];
end
end
if ~exist('datasetNames','var'), datasetNames=[]; end;
% fill in missing names with dataset indecies
for k=(numel(datasetNames)+1):numel(z);
datasetNames{k} = num2str(k);
end
if ~exist('curImInd','var'), curImInd = 1; end
prevImInd = 1;
hImage = [];
hTitle = [];
curFrameInd =1;
SetCurrentImage(curImInd);
set(gcf, 'WindowKeyPressFcn',@KeyPress_proc);
function KeyPress_proc(src,evnt)
switch evnt.Key
case{'t'}
SetCurrentImage(curImInd+1);
case{'rightarrow'}
SetCurrentFrame(curFrameInd+1);
case{'leftarrow'}
SetCurrentFrame(curFrameInd-1);
case{'c'}
imcontrast
case{'r'}
impixelregion
case{'1','2','3','4','5','6','7','8','9','0'}
ind=str2double(evnt.Character);
if ind==0, ind=10; end
if ind <= numel(z), SetCurrentImage(ind); end
end
end
function SetCurrentImage(imIndex)
if imIndex > numel(z), imIndex =1; end
prevImInd = curImInd;
curImInd = imIndex;
if ~link_cmaps && ~isempty(hImage)
cmap{prevImInd} = get(gca,'CLim');
set(gca,'CLim',cmap{curImInd});
end
displayimage
end
function SetCurrentFrame(frameInd)
if frameInd > size(z{curImInd},3)
frameInd = 1;
elseif frameInd < 1
frameInd = size(z{curImInd},3);
end
curFrameInd = frameInd;
displayimage
end
function displayimage
titleString = sprintf('%s Frame:%d', datasetNames{curImInd},curFrameInd);
if isempty(hImage)
figure;
hImage = imshow(z{curImInd}(:,:,curFrameInd), cmap{curImInd});
hTitle = title(gca, titleString);
return;
end
set(hImage, 'CData',z{curImInd}(:,:,curFrameInd));
set(hTitle,'String', titleString);
end
end