image thumbnail
from Display the fusion of two images by Dany Simard
This is a simple but efficient tool (GUI) for the visualization of 2 superposed images from workspa

DisplayFusionGUI(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Dany Simard                                                  %
%  dany.simard@gmail.com                                        %
%  CHUM, Universit de Montral , Qubec                        %
%  Visualization tool for 2D image fusion                       %
%  Version 1.0                                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = DisplayFusionGUI(varargin)
% DISPLAYFUSIONGUI M-file for DisplayFusionGUI.fig
%      DISPLAYFUSIONGUI, by itself, creates a new DISPLAYFUSIONGUI or raises the existing
%      singleton*.
%
%      H = DISPLAYFUSIONGUI returns the handle to a new DISPLAYFUSIONGUI or the handle to
%      the existing singleton*.
%
%      DISPLAYFUSIONGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DISPLAYFUSIONGUI.M with the given input arguments.
%
%      DISPLAYFUSIONGUI('Property','Value',...) creates a new DISPLAYFUSIONGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before DisplayFusionGUI_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to DisplayFusionGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help DisplayFusionGUI

% Last Modified by GUIDE v2.5 05-Jan-2007 15:55:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @DisplayFusionGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @DisplayFusionGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


%% --- Executes just before DisplayFusionGUI is made visible.
function DisplayFusionGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to DisplayFusionGUI (see VARARGIN)

    handles.output = hObject;
    handles.Im1=zeros(2);
    handles.Im2=zeros(2);
    handles.DispFusion=0.5;
    handles.facteurRGB=[1,0,0];
    handles.Mode=2;
    handles.name={'Im1','Im2'};
    handles.Points='PM';
    handles.PositionsMarqueurs.Pixel=0;
    set(handles.slider1,'Value',handles.DispFusion);
    Afficher(hObject, eventdata, handles)
    % Update handles structure
    guidata(hObject, handles);


%% --- Outputs from this function are returned to the command line.
function varargout = DisplayFusionGUI_OutputFcn(hObject, eventdata, handles) 

% Get default command line output from handles structure
    varargout{1} = handles.output;

%% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)

    handles.DispFusion=get(handles.slider1,'Value');
    Afficher(hObject, eventdata, handles)
    % Update handles structure
    guidata(hObject, handles);

%% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)

    if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor',[.9 .9 .9]);
    end
%%
function Afficher(hObject, eventdata, handles)

    ImGRAY=double(handles.Im1);
    ImFusion=double(handles.Im2);
    normGRAY=max(ImGRAY(:));
    normFusion=max(ImFusion(:));
    if normGRAY==0
        normGRAY=1;
    end
    if normFusion==0
        normFusion=1;
    end
    
    if handles.Mode==1
        DispGray=1-handles.DispFusion;
        imagesc(cat(3,ImGRAY/normGRAY.*DispGray+handles.facteurRGB(1)*ImFusion/normFusion.*handles.DispFusion,...
                  ImGRAY/normGRAY.*DispGray+handles.facteurRGB(2)*ImFusion/normFusion.*handles.DispFusion,...
                  ImGRAY/normGRAY.*DispGray+handles.facteurRGB(3)*ImFusion/normFusion.*handles.DispFusion),...
                  'Parent',handles.axes1,[0,1]);
    elseif handles.Mode==2
        if handles.facteurRGB==[1,0,0];
            FRGB=[0,1,1];
        elseif handles.facteurRGB==[1,1,1];
            FRGB=[1,1,1];
        end
        imagesc(abs(cat(3,ImGRAY/normGRAY.*1-FRGB(1)*ImFusion/normFusion.*0.5*handles.DispFusion,...
                  ImGRAY/normGRAY.*1-FRGB(2)*ImFusion/normFusion.*0.5*handles.DispFusion,...
                  ImGRAY/normGRAY.*1-FRGB(3)*ImFusion/normFusion.*0.5*handles.DispFusion)),...
                  'Parent',handles.axes1,[0,1]);
    end
    axis(handles.axes1,'off')

    if handles.PositionsMarqueurs.Pixel
        hold(handles.axes1,'on')
        plot(handles.PositionsMarqueurs.Pixel(:,1),handles.PositionsMarqueurs.Pixel(:,2),'x','Parent',handles.axes1);
        hold(handles.axes1,'off')
    end

%% --- Executes on button press in load.
function load_Callback(hObject, eventdata, handles)

    dlg_title=('Load Images');
    def={handles.name{1},handles.name{2}};
    qst={'Name of the first image on the workspace:',...
         'Name of the second image on the workspace:'};
    answer=inputdlg(qst,dlg_title,1,def);
    if ~isempty(answer) 
        try
            if isempty(answer{2})
                handles.Im1=evalin('base', answer{1});
                handles.Im2=zeros(size(handles.Im1));
            elseif isempty(answer{1})
                handles.Im2=evalin('base', answer{2});
                handles.Im1=zeros(size(handles.Im2));
            else
                handles.Im1=evalin('base', answer{1});
                handles.Im2=evalin('base', answer{2});
            end
        catch
            warndlg('Invalid name(s)')
        end
        if size(handles.Im1)~=size(handles.Im2)
          errordlg('Two images with the same size are needed!!')
        else
        handles.name=answer;
        Afficher(hObject, eventdata, handles)
        % Update handles structure
        guidata(hObject, handles);
        end
    end
    


% --- Executes on selection change in popTransparency.
function popTransparency_Callback(hObject, eventdata, handles)

    contents = get(hObject,'String');
    Temp=contents{get(hObject,'Value')};
    if strcmp(Temp,'Red') || strcmp(Temp,'Transparency')
        handles.facteurRGB=[1,0,0];
    elseif strcmp(Temp,'Grey/White')
        handles.facteurRGB=[1,1,1];
    end
    
    Afficher(hObject, eventdata, handles)
    % Update handles structure
    guidata(hObject, handles);
    
% --- Executes during object creation, after setting all properties.
function popTransparency_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popMode.
function popMode_Callback(hObject, eventdata, handles)

    contents = get(hObject,'String');
    Temp=contents{get(hObject,'Value')};
    if  strcmp(Temp,'50/50')
        handles.Mode=1;
    elseif strcmp(Temp,'Mode') ||strcmp(Temp,'Addition')
        handles.Mode=2;
    end

    Afficher(hObject, eventdata, handles)
    % Update handles structure
    guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function popMode_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%% --- Executes on button press in loadpoints.
function loadpoints_Callback(hObject, eventdata, handles)

    dlg_title=('Load Points');
    def={handles.Points};
    options.Interpreter='tex';
    qst={'Name of the variable on the workspace \newlinecontaining the 2D points position in pixels (Columns,Rows):'};
    answer=inputdlg(qst,dlg_title,1,def,options);
    if ~isempty(answer)
        try
            handles.PositionsMarqueurs.Pixel=evalin('base', answer{1});
            if size(handles.PositionsMarqueurs.Pixel,2)==2;
            handles.Points=answer{1};
            Afficher(hObject, eventdata, handles)
            % Update handles structure
            guidata(hObject, handles);
            else
                warndlg('Invalid variable')
            end
        catch
            warndlg('Invalid name')
        end
    end




% --- Executes on button press in clearpoints.
function clearpoints_Callback(hObject, eventdata, handles)
% hObject    handle to clearpoints (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    handles.PositionsMarqueurs.Pixel=0;
    Afficher(hObject, eventdata, handles)
    % Update handles structure
    guidata(hObject, handles);

Contact us at files@mathworks.com