Code covered by the BSD License  

Highlights from
confortho

image thumbnail

confortho

by

 

06 Jun 2009 (Updated )

Confortho generates orthogonal views of 3D confocal microscopic image stacks.

confortho(varargin)
function varargout = confortho(varargin)
% CONFORTHO M-file for confortho.fig
%      CONFORTHO, by itself, creates a new CONFORTHO or raises the existing
%      singleton*.
%
%      H = CONFORTHO returns the handle to a new CONFORTHO or the handle to
%      the existing singleton*.
%
%      CONFORTHO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CONFORTHO.M with the given input arguments.
%
%      CONFORTHO('Property','Value',...) creates a new CONFORTHO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before confortho_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to confortho_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 confortho

% Last Modified by GUIDE v2.5 28-Jan-2013 16:06:16

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @confortho_OpeningFcn, ...
                   'gui_OutputFcn',  @confortho_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 confortho is made visible.
function confortho_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 confortho (see VARARGIN)
global COLORS;
global STARTED;
global TH;
global EXITPRESSED;
%global UNMIXEDCHANNELS;
%global SMOOTHEDCHANNELS;
%global STRETCHEDCHANNELS;
%global REMIXEDCHANNELS;
%global FINALIMAGE;
%global FINALIMAGE;
%global CURRENT_X;
%global CURRENT_Y;
%global CURRENT_Z;
global OUTPUTWINDOWHANDLE;
global CLICKED;
global PROCESSEDSOMETHING;
CLICKED=0;
versionText='1.12';
set(handles.versionText,'string',['v',versionText]);
%UNMIXEDCHANNELS={[],[],[],[]};
%SMOOTHEDCHANNELS={[],[],[],[]};
%STRETCHEDCHANNELS={{[],[],[],[]},{[],[],[],[]},{[],[],[],[]}};
%REMIXEDCHANNELS={{[],[],[]},{[],[],[]},{[],[],[]}};
%CURRENT_X=0;
%CURRENT_Y=0;
%CURRENT_Z=0;
EXITPRESSED=0;
PROCESSEDSOMETHING=0;
OUTPUTWINDOWHANDLE=0;
STARTED=0;
handles.val_inputType=1;
handles.val_channel1Name='';
handles.val_channel2Name='';
handles.val_channel3Name='';
handles.val_channel4Name='';
handles.val_colorStackName='';
handles.val_aspectRatio=1;
handles.val_orthogonalView=1;
handles.val_clipNormalizeType=2;
handles.val_outputImageName='';
handles.val_channel1ColorSelector=1;
handles.val_channelsLow=[0,0,0,0];
handles.val_channelsHigh=[1,1,1,1];
handles.val_channelsGaussian=[0,0,0,0];
handles.val_channel2ColorSelector=2;
handles.val_channel3ColorSelector=3;
handles.val_channel4ColorSelector=8;
handles.val_channel1OrigColor=1;
handles.val_channel2OrigColor=2;
handles.val_channel3OrigColor=3;
handles.val_channel4OrigColor=8;
handles.val_binNum=8;
handles.val_dipimage=1;
guidata(hObject,handles);
COLORS(1,:)=[1,0,0];
COLORS(2,:)=[0,1,0];
COLORS(3,:)=[0,0,1];
COLORS(4,:)=[1,0,1];
COLORS(5,:)=[0,1,1];
COLORS(6,:)=[1,1,0];
COLORS(7,:)=[1,1,1];
COLORS(8,:)=[0,0,0];
drawMultipleColorScales([COLORS(handles.val_channel1ColorSelector,:);COLORS(handles.val_channel2ColorSelector,:);...
    COLORS(handles.val_channel3ColorSelector,:);COLORS(handles.val_channel4ColorSelector,:);COLORS(handles.val_channel1OrigColor,:);...
    COLORS(handles.val_channel2OrigColor,:);COLORS(handles.val_channel3OrigColor,:);COLORS(handles.val_channel4OrigColor,:)],...
    [handles.channel1ColorScale,handles.channel2ColorScale,handles.channel3ColorScale,handles.channel4ColorScale,...
    handles.channel1OrigColorScale,handles.channel2OrigColorScale,handles.channel3OrigColorScale,...
    handles.channel4OrigColorScale]);
TH=timer('TimerFcn',{@timercallback,handles.done},'StartDelay',1);
%uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = confortho_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure



% --- Executes on button press in doitButton.
function doitButton_Callback(hObject, eventdata, handles)
% hObject    handle to doitButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear global UNMIXEDCHANNELS;
clear global SMOOTHEDCHANNELS;
clear global STRETCHEDCHANNELS;
clear global REMIXEDCHANNELS;
clear global FINALIMAGE;

global STARTED;
global TH;
global CLICKED;
global PROCESSEDSOMETHING;
CLICKED=0;
set(handles.done,'String','BUSY');
set(handles.done,'Visible','on');
drawnow;
if handles.val_inputType==2
    sizeProblem=sizeTypeMismatchCheck(handles.val_channel1Name,handles.val_channel2Name,handles.val_channel3Name,handles.val_channel4Name);
else
    sizeProblem=sizeTypeMismatchCheck(handles.val_colorStackName);
end
if sizeProblem==1
    errordlg('Images have to be of the same size and type','Oops');
elseif sizeProblem==2
    errordlg('Overlaid stack has to be an RGB stack','Oops');
elseif sizeProblem==3
    errordlg('Nothing to view','Oops');
else
    [handles.val_dipimage,e_flag]=generateUnmixedStack(handles);
    guidata(hObject,handles);
    if e_flag~=1
        STARTED=1;
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        PROCESSEDSOMETHING=1;
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    else
        stop(TH);
        set(handles.done,'String','ERROR');
        start(TH);
    end
end
guidata(hObject,handles);

function generateSmoothedStack(h)
% smooth the whole unmixed stack
global SMOOTHEDCHANNELS;
global UNMIXEDCHANNELS;
for i=1:4
    if h.val_channelsGaussian(i)~=0
        gf=fspecial('gaussian',6*h.val_channelsGaussian(i),h.val_channelsGaussian(i));
        SMOOTHEDCHANNELS{i}=imfilter(UNMIXEDCHANNELS{i},gf);
    else
        SMOOTHEDCHANNELS{i}=UNMIXEDCHANNELS{i};
    end
end



function contrastStretch(h)
% contrast stretch the current slices (hor,vert,sag) only
global SMOOTHEDCHANNELS;
global STRETCHEDCHANNELS;
global CURRENT_X;
global CURRENT_Y;
global CURRENT_Z;
stackMin=zeros(4,1);
stackMax=zeros(4,1);
newMin=zeros(4,1);
newMax=zeros(4,1);
for j=1:4
    stackMin(j)=min(min(min(SMOOTHEDCHANNELS{j})));
    stackMax(j)=max(max(max(SMOOTHEDCHANNELS{j})));
    newMin(j)=h.val_channelsLow(j)*(stackMax(j)-stackMin(j))+stackMin(j);
    newMax(j)=h.val_channelsHigh(j)*(stackMax(j)-stackMin(j))+stackMin(j);
end
for j=1:4
    if ndims(SMOOTHEDCHANNELS{j})==2
        tempstack=SMOOTHEDCHANNELS{j}(:,:);
    else
        tempstack=squeeze(SMOOTHEDCHANNELS{j}(:,:,CURRENT_Z));
    end
    if newMax(j)-newMin(j)
        tempstack=stackMin(j)+(tempstack-newMin(j))/(newMax(j)-newMin(j))*(stackMax(j)-stackMin(j));
        tempstack(tempstack>stackMax(j))=stackMax(j);
        tempstack(tempstack<stackMin(j))=stackMin(j);
    end
    STRETCHEDCHANNELS{1}{j}=tempstack;
end
for j=1:4
    if size(size(SMOOTHEDCHANNELS{j}),2)<3
        tempstack=SMOOTHEDCHANNELS{j}(:,CURRENT_X);
    else
        tempstack=squeeze(SMOOTHEDCHANNELS{j}(CURRENT_X,:,:));
    end
    if newMax(j)-newMin(j)
        tempstack=stackMin(j)+(tempstack-newMin(j))/(newMax(j)-newMin(j))*(stackMax(j)-stackMin(j));
        tempstack(tempstack>stackMax(j))=stackMax(j);
        tempstack(tempstack<stackMin(j))=stackMin(j);
    end
    STRETCHEDCHANNELS{2}{j}=tempstack;
end
for j=1:4
    if size(size(SMOOTHEDCHANNELS{j}),2)<3
        tempstack=squeeze(SMOOTHEDCHANNELS{j}(:,CURRENT_Y));
    else
        tempstack=squeeze(SMOOTHEDCHANNELS{j}(:,CURRENT_Y,:));
    end
    if newMax(j)-newMin(j)
        tempstack=stackMin(j)+(tempstack-newMin(j))/(newMax(j)-newMin(j))*(stackMax(j)-stackMin(j));
        tempstack(tempstack>stackMax(j))=stackMax(j);
        tempstack(tempstack<stackMin(j))=stackMin(j);
    end
    STRETCHEDCHANNELS{3}{j}=tempstack;
end



function fault=sizeTypeMismatchCheck(varargin)
global CURRENT_X;
global CURRENT_Y;
global CURRENT_Z;
if nargin==1 % overlaid stack
    try
        q=evalin('base',varargin{1});
        ty=whos('q');
        if strcmp(ty.class,'dip_image_array')
            universalSize=size(q,1);
        else
            universalSize=size(q,2);
        end
        if universalSize~=3
            fault=2;
        else
            fault=0;
            im=q{1};
            s=size(im);
            CURRENT_X=floor(s(1)/2)+1;
            if size(s,2)<3
                CURRENT_Z=1;
            else
                CURRENT_Z=floor(s(3)/2)+1;
            end
            if size(s,2)<2
                CURRENT_Y=1;
            else
                CURRENT_Y=floor(s(2)/2)+1;
            end
            if strcmp(ty.class,'dip_image_array')
                tempForExchange=CURRENT_X;
                CURRENT_X=CURRENT_Y;
                CURRENT_Y=tempForExchange;
            end
            t=whos('im');
            t=t.class;
            for i=2:3
                im=q{i};
                sc=size(im);
                tc=whos('im');
                tc=tc.class;
                if ~strcmp(tc,t)
                    fault=1;
                end
                if size(s,2)~=size(sc,2) || sum(sc==s)~=size(s,2)
                    fault=1;
                end
            end
        end
    catch
        fault=3;
    end
else % separate channels
    status=zeros(4,1);
    pictureSize=cell(4,1);
    pictureType=cell(4,1);
    for i=1:4
        try
            q=evalin('base',varargin{i});
            pictureSize{i}=size(q);
            temp=whos('q');
            pictureType{i}=temp.class;
            status(i)=1;
        catch
        end
    end
    fault=0;
    first=0;
    for i=1:4
        if status(i)==1
            if first==0
                CURRENT_X=floor(pictureSize{i}(1)/2)+1;
                if size(pictureSize{i},2)<3
                    CURRENT_Z=1;
                else
                    CURRENT_Z=floor(pictureSize{i}(3)/2)+1;
                end
                if size(pictureSize{i},2)<2
                    CURRENT_Y=1;
                else
                    CURRENT_Y=floor(pictureSize{i}(2)/2)+1;
                end
                if strcmp(pictureType{i},'dip_image')
                    tempForExchange=CURRENT_X;
                    CURRENT_X=CURRENT_Y;
                    CURRENT_Y=tempForExchange;
                end
                first=1;
                s=pictureSize{i};
                t=pictureType{i};
            else
                sc=pictureSize{i};
                tc=pictureType{i};
                if ~strcmp(tc,t)
                    fault=1;
                end
                if size(sc,2)~=size(s,2) || sum(sc==s)~=size(s,2)
                    fault=1;
                end
            end
        end
    end
end

function generateRemixedStack(convMatrix)
global STRETCHEDCHANNELS;
global REMIXEDCHANNELS;
for i=1:3
    REMIXEDCHANNELS{i}=colorConvert(STRETCHEDCHANNELS{i},convMatrix,0);
end



function timercallback(src,eventdata,d)
set(d,'Visible','off');


function createView(h)
global REMIXEDCHANNELS;
global FINALIMAGE;
global COLORS;
global CURRENT_X;
global CURRENT_Y;
global CURRENT_Z;
global LH;
global OUTPUTWINDOWHANDLE;
global UNMIXEDCHANNELS;
convMat=[COLORS(h.val_channel1ColorSelector,:);COLORS(h.val_channel2ColorSelector,:);...
    COLORS(h.val_channel3ColorSelector,:);COLORS(h.val_channel4ColorSelector,:)];
generateRemixedStack(convMat);
globalMaximum=0;
for i=1:4
    if max(max(max(UNMIXEDCHANNELS{i})))>globalMaximum
        globalMaximum=max(max(max(UNMIXEDCHANNELS{i})));
    end
end
if globalMaximum>2^16-1
    correctionFactor=globalMaximum;
elseif globalMaximum>2^12-1
    correctionFactor=2^16-1;
elseif globalMaximum>2^8-1
    correctionFactor=2^12-1;
else
    correctionFactor=2^8-1;
end
for i=1:3
    for j=1:3
        REMIXEDCHANNELS{i}{j}=REMIXEDCHANNELS{i}{j}/correctionFactor*255;
    end
end
% clipping
if h.val_clipNormalizeType==2
    for i=1:3
        for j=1:3
            tempColorSlice=REMIXEDCHANNELS{i}{j};
            tempColorSlice(tempColorSlice>255)=255;
            REMIXEDCHANNELS{i}{j}=tempColorSlice;
        end
    end
end
% end of clipping
% create orthogonal view
if h.val_orthogonalView && size(REMIXEDCHANNELS{2}{1},2)>1
    if h.val_aspectRatio~=1
        for i=2:3
            [xmesh1,ymesh1]=meshgrid(1:size(REMIXEDCHANNELS{i}{1},2),1:size(REMIXEDCHANNELS{i}{1},1));
            [xmesh2,ymesh2]=meshgrid(1:1/h.val_aspectRatio:size(REMIXEDCHANNELS{i}{1},2),1:size(REMIXEDCHANNELS{i}{1},1));
            for j=1:3
                REMIXEDCHANNELS{i}{j}=interp2(xmesh1,ymesh1,REMIXEDCHANNELS{i}{j},xmesh2,ymesh2);
            end
        end
    end
    h1=size(REMIXEDCHANNELS{1}{1},1);
    h2=size(REMIXEDCHANNELS{2}{1},2);
    w1=size(REMIXEDCHANNELS{1}{1},2);
    w2=size(REMIXEDCHANNELS{2}{1},2);

    finalDouble=cell(3,1);
    for i=1:3
        finalDouble{i}=zeros(h1+1+h2,w1+1+w2);
        finalDouble{i}(1:h1,1:w1)=REMIXEDCHANNELS{1}{i};
        finalDouble{i}(h1+2:end,1:w1)=REMIXEDCHANNELS{2}{i}';
        finalDouble{i}(1:h1,w1+2:end)=REMIXEDCHANNELS{3}{i};
    end
else
    finalDouble=REMIXEDCHANNELS{1};
end
% end of othogonal view
% data export
if h.val_dipimage==1
    FINALIMAGE=joinchannels('rgb',finalDouble{1},finalDouble{2},finalDouble{3})
    OUTPUTWINDOWHANDLE=gcf;
else
    FINALIMAGE=zeros(size(finalDouble{1},1),size(finalDouble{1},2),3);
    for i=1:3
        FINALIMAGE(:,:,i)=finalDouble{i}/255;
    end
    OUTPUTWINDOWHANDLE=1001;
    figure(OUTPUTWINDOWHANDLE);
    imshow(FINALIMAGE);
end
if h.val_orthogonalView && size(REMIXEDCHANNELS{2}{1},2)>1
    line([w1+1,w1+1],[1,h1+h2+1],'Color','w')
    line([1,w1+w1+1],[h1+1,h1+1],'Color','w')
    LH(1)=line([1,w1],[CURRENT_X,CURRENT_X],'Color','w','LineStyle','--','ButtonDownFcn',@line1ButtonDown);
    LH(2)=line([CURRENT_Y,CURRENT_Y],[1,h1],'Color','w','LineStyle','--','ButtonDownFcn',@line2ButtonDown);
    LH(3)=line([w1+1+CURRENT_Z*h.val_aspectRatio,w1+1+CURRENT_Z*h.val_aspectRatio],[1,h1],'Color','w','LineStyle','--','ButtonDownFcn',@line3ButtonDown);
    LH(4)=line([1,w1],[h1+1+CURRENT_Z*h.val_aspectRatio,h1+1+CURRENT_Z*h.val_aspectRatio],'Color','w','LineStyle','--','ButtonDownFcn',@line4ButtonDown);
    
    dipimagewindowhandle=get(get(LH(1),'Parent'),'Parent');
    set(dipimagewindowhandle,'WindowButtonDownFcn','')
        
    set(gcf,'WindowButtonUpFcn',{@windowButtonUpCallback,w1,h1,w2,h2,h});
    set(gcf,'WindowButtonMotionFcn',{@windowMotionCallback,w1,h1,w2,h2});
end


function windowButtonUpCallback(src,evt,width1,height1,width2,height2,hand)
global CLICKED;
global LH;
global CURRENT_X;
global CURRENT_Y;
global CURRENT_Z;
if CLICKED
    p1=get(gca,'CurrentPoint');
    delete(LH(CLICKED));
    switch CLICKED
        case 1
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    CURRENT_X=floor(p1(1,2))+1;
                case 2
                    CURRENT_X=height1-1;
                case 0
                    CURRENT_X=1;
            end
        case 2
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    CURRENT_Y=floor(p1(1,1))+1;
                case 2
                    CURRENT_Y=width1-1;
                case 0
                    CURRENT_Y=1;
            end
        case 3
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    CURRENT_Z=floor((p1(1,1)-width1)/hand.val_aspectRatio)+1;
                case 2
                    CURRENT_Z=floor(width2/hand.val_aspectRatio);
                case 0
                    CURRENT_Z=1;
            end
        case 4
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    CURRENT_Z=floor((p1(1,2)-height1)/hand.val_aspectRatio)+1;
                case 2
                    CURRENT_Z=floor(height2/hand.val_aspectRatio);
                case 0
                    CURRENT_Z=1;
            end
    end
CLICKED=0;
contrastStretch(hand);
createView(hand);
end




function windowMotionCallback(src,evt,width1,height1,width2,height2)
global CLICKED;
global LH;
if CLICKED
    p1=get(gca,'CurrentPoint');
    delete(LH(CLICKED));
    switch CLICKED
        case 1
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    LH(1)=line([1,width1],[p1(1,2),p1(1,2)],'Color','w','LineStyle','--');
                case 2
                    LH(1)=line([1,width1],[height1-1,height1-1],'Color','w','LineStyle','--');
                case 0
                    LH(1)=line([1,width1],[0,0],'Color','w','LineStyle','--');
            end
        case 2
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    LH(2)=line([p1(1,1),p1(1,1)],[1,height1],'Color','w','LineStyle','--');
                case 2
                    LH(2)=line([width1-1,width1-1],[1,height1],'Color','w','LineStyle','--');
                case 0
                    LH(2)=line([0,0],[1,height1],'Color','w','LineStyle','--');
            end
        case 3
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    LH(3)=line([p1(1,1),p1(1,1)],[1,height1],'Color','w','LineStyle','--');
                case 2
                    LH(3)=line([width1+width2-1,width1+width2-1],[1,height1],'Color','w','LineStyle','--');
                case 0
                    LH(3)=line([width1,width1],[1,height1],'Color','w','LineStyle','--');
            end
        case 4
            switch insideBoundary(CLICKED,width1,height1,width2,height2,p1)
                case 1
                    LH(4)=line([1,width1],[p1(1,2),p1(1,2)],'Color','w','LineStyle','--');
                case 2
                    LH(4)=line([1,width1],[height1+height2-1,height1+height2-1],'Color','w','LineStyle','--');
                case 0
                    LH(4)=line([1,width1],[height1,height1],'Color','w','LineStyle','--');
            end
    end
end

function inside=insideBoundary(whichLine,w1,h1,w2,h2,pos)
% inside=1, if inside
% inside=0, if smaller
% inside=2, if larger
switch whichLine
    case 1
        if pos(1,2)<=h1-1 && pos(1,2)>=0
            inside=1;
        else
            if pos(1,2)<0
                inside=0;
            else
                inside=2;
            end
        end
    case 2
        if pos(1,1)<=w1-1 && pos(1,1)>=0
            inside=1;
        else
            if pos(1,1)<0
                inside=0;
            else
                inside=2;
            end
        end
    case 3
        if pos(1,1)<w1+w2 && pos(1,1)>=w1
            inside=1;
        else
            if pos(1,1)<w1
                inside=0;
            else
                inside=2;
            end
        end
    case 4
        if pos(1,2)<h1+h2 && pos(1,2)>=h1
            inside=1;
        else
            if pos(1,2)<h1
                inside=0;
            else
                inside=2;
            end
        end
end


function line1ButtonDown(src,evt)
global CLICKED;
CLICKED=1;


function line2ButtonDown(src,evt)
global CLICKED;
CLICKED=2;

function line3ButtonDown(src,evt)
global CLICKED;
CLICKED=3;

function line4ButtonDown(src,evt)
global CLICKED;
CLICKED=4;


function exportToBase(baseVariableName,localVariableName)
% This function exports the output image to the 'base' environment,
% and displays it in a window which has the name of the variable, 100% size
% and linear stretch turned on.
h=dipfig('-get',baseVariableName);
if h==0
    windowhandlelist=get(0,'Children');
    h=windowhandlelist(end)+1;
end
assignin('base',baseVariableName,localVariableName);
figure(h);
diptruesize(100);
commandInBase=['dipshow(',num2str(h),',',baseVariableName,',',char(39),'lin',char(39),')'];
evalin('base',commandInBase);
s=get(0,'ScreenSize');
if strcmp(class(localVariableName),'dip_image')==1
    sImage=size(localVariableName);
else
    sImage=size(localVariableName{1});
end
if sImage(1)<115
    sImage(1)=115;
end
set(h,'Position',[s(3)-sImage(1)-5,s(4)-sImage(2)-50,sImage(1),sImage(2)]);



function [it,errorflag]=generateUnmixedStack(h)
global COLORS;
global UNMIXEDCHANNELS;
if h.val_inputType==1 % overlaid stack
    objectList=get(h.overlaidPanel,'Children');
    objectList=findobj(objectList,'Style','popupmenu');
    objectList1(1)=findobj(objectList,'Tag','channel1OrigColor');
    objectList1(2)=findobj(objectList,'Tag','channel2OrigColor');
    objectList1(3)=findobj(objectList,'Tag','channel3OrigColor');
    objectList1(4)=findobj(objectList,'Tag','channel4OrigColor');
    flag=0;
    for i=1:3
        for j=i+1:4
            if get(objectList1(i),'value')==get(objectList1(j),'value')
                flag=1;
            end
        end
    end
    if flag==1
        errordlg('None of the original color channels should be identical','Oops');
        errorflag=1;
        it=h.val_dipimage;
        UNMIXEDCHANNELS={[],[],[],[]};
    else
        try
            inputImage=evalin('base',h.val_colorStackName);
            varType=whos('inputImage');
            convMat=[COLORS(h.val_channel1OrigColor,:);COLORS(h.val_channel2OrigColor,:);...
                COLORS(h.val_channel3OrigColor,:);COLORS(h.val_channel4OrigColor,:)];
            if strcmp(varType.class,'dip_image_array')
                it=1;
                if size(inputImage,1)~=3
                    errordlg('Size of dipimage array has to be 3','Oops');
                    errorflag=1;
                else
                    UNMIXEDCHANNELS=colorConvert(inputImage,convMat,1);
                    errorflag=0;
                end
            elseif strcmp(varType.class,'cell')
                it=0;
                if size(inputImage,2)~=3
                    errordlg('Size of cell array has to be 3','Oops');
                    errorflag=1;
                else
                    UNMIXEDCHANNELS=colorConvert(inputImage,convMat,1);
                    errorflag=0;
                end
            else
                it=h.val_dipimage;
                errorflag=1;
                errordlg('Unsupported input image. Supported types: dipimage array, cell array','Oops');
            end
        catch ME
            if strcmp(ME.identifier,'MATLAB:nomem')
                errordlg('Not enough memory','Oops');
            else
                errordlg('Nothing to view2','Oops');
            end
            UNMIXEDCHANNELS={[],[],[],[]};
            errorflag=1;
            it=h.val_dipimage;
        end
    end
else % separate stacks
    itype='';
    foundImage=zeros(4);
    objectList=get(h.separatePanel,'Children');
    objectList=findobj(objectList,'style','edit');
    objectList1(1)=findobj(objectList,'Tag','channel1Name');
    objectList1(2)=findobj(objectList,'Tag','channel2Name');
    objectList1(3)=findobj(objectList,'Tag','channel3Name');
    objectList1(4)=findobj(objectList,'Tag','channel4Name');
    for i=1:4
        try
            temp=evalin('base',get(objectList1(i),'String'));
            itype=whos('temp');
            s=size(temp);
            foundImage(i)=1;
        catch
        end
    end
    if isempty(itype)
        errordlg('Nothing to view','Oops');
        UNMIXEDCHANNELS={[],[],[],[]};
        it=h.val_dipimage;
        errorflag=1;
    else
        errorflag=0;
        if strcmp(itype.class,'dip_image')
            it=1;
        else
            it=0;
        end
        for i=1:4
            if foundImage(i)==1
                UNMIXEDCHANNELS{i}=evalin('base',get(objectList1(i),'String'));
                if it==1
                    UNMIXEDCHANNELS{i}=double(UNMIXEDCHANNELS{i});
                end
            else
                if it==1
                    UNMIXEDCHANNELS{i}=dip_image(zeros(s));
                else
                    UNMIXEDCHANNELS{i}=zeros(s);
                end
            end
        end
    end
end


function imageOut=colorConvert(imageIn,colorConversionMatrix,inverse)
it=whos('imageIn');
universalSize=size(imageIn,1); % the number of color channels in the input
if size(imageIn,2)>universalSize
    universalSize=size(imageIn,2);
end
if inverse
    xSize=size(colorConversionMatrix,1); % number of columns in the output
else
    xSize=size(colorConversionMatrix,2);
end
imageOut=cell(xSize,1);
imageTemp=cell(universalSize,1);
for i=1:universalSize
    imageTemp{i}=double(imageIn{i});
end
clear('imageIn');
if sum(sum(eye(size(colorConversionMatrix))==colorConversionMatrix))==size(colorConversionMatrix,1)*size(colorConversionMatrix,2) % if identity matrix
    if inverse
        for i=1:3
            imageOut{i}=imageTemp{i};
        end
        imageOut{4}=zeros(size(imageTemp{3}));
    else
        for i=1:3
            imageOut{i}=imageTemp{i};
        end
    end
else
    numDim=size(size(imageTemp{1}),2);
    stackDim=zeros(3,1); % size of the input image (x,y,z)
    for i=1:numDim
        stackDim(i)=size(imageTemp{1},i);
    end
    if numDim==1
        stackDim(2)=1;
        stackDim(3)=1;
    elseif numDim==2
        stackDim(3)=1;
    end
    sliceSize=stackDim(1)*stackDim(2);
    tempina=zeros(sliceSize,3); % slice-by-slice due to memory problems
    for i=1:stackDim(3)
        for j=1:universalSize
            if numDim==3
                tempina(:,j)=reshape(imageTemp{j}(:,:,i),sliceSize,1);
            elseif numDim==2
                tempina(:,j)=reshape(imageTemp{j},sliceSize,1);
            else
                tempina(:,j)=imageTemp{j};
            end
        end
        if inverse
            tempina2=tempina/colorConversionMatrix;
        else
            tempina2=tempina*colorConversionMatrix;
        end
        for j=1:size(tempina2,2)
            imageOut{j}(:,:,i)=reshape(tempina2(:,j),stackDim(1),stackDim(2));
        end
    end
end




% --- Executes on button press in quitButton.
function quitButton_Callback(hObject, eventdata, handles)
% hObject    handle to quitButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global EXITPRESSED;
global FINALIMAGE;
global REMIXEDCHANNELS;
global CURRENT_X;
global CURRENT_Y;
global CURRENT_Z;
global OUTPUTWINDOWHANDLE;
global PROCESSEDSOMETHING;
global TH;
EXITPRESSED=1;
if OUTPUTWINDOWHANDLE~=0
    try
        set(OUTPUTWINDOWHANDLE,'WindowButtonMotionFcn','');
        set(OUTPUTWINDOWHANDLE,'WindowButtonUpFcn','');
        objectList=get(OUTPUTWINDOWHANDLE,'Children');
        for i=1:size(objectList,1)
            if strcmp(get(objectList(i),'Type'),'axes')
                ah=i;
            end
        end
        objectList2=get(objectList(ah),'Children');
        for i=1:size(objectList2,1)
            if strcmp(get(objectList2(i),'Type'),'line')
                set(objectList2(i),'ButtonDownFcn','');
            end
        end
    end
end


if ~isempty(handles.val_outputImageName) && PROCESSEDSOMETHING
    h1=size(REMIXEDCHANNELS{1}{1},1);
    h2=size(REMIXEDCHANNELS{2}{1},2);
    w1=size(REMIXEDCHANNELS{1}{1},2);
    w2=size(REMIXEDCHANNELS{2}{1},2);
    if handles.val_orthogonalView==1 && size(REMIXEDCHANNELS{2}{1},2)>1
        if handles.val_dipimage==1
            for i=1:3
                finalDouble{i}=drawHorVertDashedLine(FINALIMAGE{i},'v',w1+1,1,h1+h2-1,h1+h2-1,255);
                finalDouble{i}=drawHorVertDashedLine(finalDouble{i},'h',1,h1+1,w1+w2-1,w1+w2-1,255);
                finalDouble{i}=drawHorVertDashedLine(finalDouble{i},'h',1,CURRENT_X,w1,10,255);
                finalDouble{i}=drawHorVertDashedLine(finalDouble{i},'v',CURRENT_Y,1,h1,10,255);
                finalDouble{i}=drawHorVertDashedLine(finalDouble{i},'v',w1+1+CURRENT_Z*handles.val_aspectRatio,1,h1,10,255);
                finalDouble{i}=drawHorVertDashedLine(finalDouble{i},'h',1,h1+1+CURRENT_Z*handles.val_aspectRatio,w1,10,255);
            end
        else
            for i=1:3
                finalDouble(:,:,i)=drawHorVertDashedLine(FINALIMAGE(:,:,i),'h',1,w1+1,h1+h2-1,h1+h2-1,1);
                finalDouble(:,:,i)=drawHorVertDashedLine(finalDouble(:,:,i),'v',h1+1,1,w1+w2-1,w1+w2-1,1);
                finalDouble(:,:,i)=drawHorVertDashedLine(finalDouble(:,:,i),'v',CURRENT_X,1,w1,10,1);
                finalDouble(:,:,i)=drawHorVertDashedLine(finalDouble(:,:,i),'h',1,CURRENT_Y,h1,10,1);
                finalDouble(:,:,i)=drawHorVertDashedLine(finalDouble(:,:,i),'h',1,w1+1+CURRENT_Z*handles.val_aspectRatio,h1,10,1);
                finalDouble(:,:,i)=drawHorVertDashedLine(finalDouble(:,:,i),'v',h1+1+CURRENT_Z*handles.val_aspectRatio,1,w1,10,1);
            end
        end
    else
        if handles.val_dipimage==1
            for i=1:3
                finalDouble{i}=FINALIMAGE{i};
            end
        else
            for i=1:3
                finalDouble(:,:,i)=FINALIMAGE(:,:,i);
            end
        end
    end
    if handles.val_dipimage==1
        finalImage=joinchannels('rgb',finalDouble{1},finalDouble{2},finalDouble{3});
    end
    try
        if handles.val_dipimage==1
            exportToBase(handles.val_outputImageName,finalImage);
        else
            figure(1001);
            imshow(finalDouble)
            assignin('base',handles.val_outputImageName,finalDouble);
        end
        OUTPUTWINDOWHANDLE=0;
    end
end
if PROCESSEDSOMETHING
    reportText=['CONFORTHO REPORT',char(10)];
    if handles.val_inputType==1
        reportText=[reportText,'Type of input: overlaid color stack',char(10)];
        reportText=[reportText,'Color stack: ',handles.val_colorStackName,char(10)];
        reportText=[reportText,'Original colors: channel 1: ',number2color(handles.val_channel1OrigColor),', channel2: ',...
            number2color(handles.val_channel2OrigColor),', channel3: ',number2color(handles.val_channel3OrigColor),', channel4: ',...
            number2color(handles.val_channel4OrigColor),char(10)];
    else
        reportText=[reportText,'Type of input: separate color stacks',char(10)];
        reportText=[reportText,'Channel1: ',handles.val_channel1Name,', channel2: ',handles.val_channel2Name,', channel3: ',...
            handles.val_channel3Name,', channel4: ',handles.val_channel4Name,char(10)];
    end
    reportText=[reportText,'Aspect ratio: ',num2str(handles.val_aspectRatio),', orthogonal view: '];
    if handles.val_orthogonalView==1
        reportText=[reportText,'yes'];
    else
        reportText=[reportText,'no'];
    end
    reportText=[reportText,', Clip to 255: '];
    if handles.val_clipNormalizeType==2
        reportText=[reportText,'yes'];
    else
        reportText=[reportText,'no'];
    end
    reportText=[reportText,', output image: ',handles.val_outputImageName,char(10)];
    for i=1:4
        reportText=[reportText,'Output channel',num2str(i),': color scale: '];
        switch i
            case 1
                reportText=[reportText,number2color(handles.val_channel1ColorSelector)];
                if handles.val_channel1ColorSelector~=8
                    reportText=[reportText,', low: ',num2str(handles.val_channelsLow(i)),', high: ',num2str(handles.val_channelsHigh(i)),...
                        ', sigma: ',num2str(handles.val_channelsGaussian(i)),char(10)];
                end
            case 2
                reportText=[reportText,number2color(handles.val_channel2ColorSelector)];
                if handles.val_channel2ColorSelector~=8
                    reportText=[reportText,', low: ',num2str(handles.val_channelsLow(i)),', high: ',num2str(handles.val_channelsHigh(i)),...
                        ', sigma: ',num2str(handles.val_channelsGaussian(i)),char(10)];
                end
            case 3
                reportText=[reportText,number2color(handles.val_channel3ColorSelector)];
                if handles.val_channel3ColorSelector~=8
                    reportText=[reportText,', low: ',num2str(handles.val_channelsLow(i)),', high: ',num2str(handles.val_channelsHigh(i)),...
                        ', sigma: ',num2str(handles.val_channelsGaussian(i)),char(10)];
                end
            case 4
                reportText=[reportText,number2color(handles.val_channel4ColorSelector)];
                if handles.val_channel4ColorSelector~=8
                    reportText=[reportText,', low: ',num2str(handles.val_channelsLow(i)),', high: ',num2str(handles.val_channelsHigh(i)),...
                        ', sigma: ',num2str(handles.val_channelsGaussian(i)),char(10)];
                end
        end
    end
    disp(reportText);
end
clear global UNMIXEDCHANNELS;
clear global SMOOTHEDCHANNELS;
clear global STRETCHEDCHANNELS;
clear global REMIXEDCHANNELS;
clear global FINALIMAGE;
delete(TH);
delete(get(hObject,'parent'));


function color=number2color(number)
switch number
    case 1
        color='red';
    case 2
        color='green';
    case 3
        color='blue';
    case 4
        color='magenta';
    case 5
        color='cyan';
    case 6
        color='yellow';
    case 7
        color='grey';
    case 8
        color='empty';
end


function imout=drawHorVertDashedLine(imin,direction,x,y,length,dashSize,pixelValue)
imout=imin;
x=floor(x);
y=floor(y);
if strcmp('h',direction)
    scale=[x:dashSize:x+length];
    if scale(end)~=x+length
        scale(end+1)=x+length;
    end
    visible=1;
    for i=1:size(scale,2)-1
        if visible==1
            imout(scale(i):scale(i+1),y)=pixelValue;
            visible=0;
        else
            visible=1;
        end
    end
end
if strcmp('v',direction)
    scale=[y:dashSize:y+length];
    if scale(end)~=y+length
        scale(end+1)=y+length;
    end
    visible=1;
    for i=1:size(scale,2)-1
        if visible==1
            imout(x,scale(i):scale(i+1))=pixelValue;
            visible=0;
        else
            visible=1;
        end
    end
end


function colorStackName_Callback(hObject, eventdata, handles)
% hObject    handle to colorStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of colorStackName as text
%        str2double(get(hObject,'String')) returns contents of colorStackName as a double
global STARTED;
STARTED=0;
tempName=get(hObject,'String');
try
    if str2num(tempName)~=0
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_colorStackName);
    else
        tempNameEval=evalin('base',tempName);
        handles.val_colorStackName=tempName;
        guidata(hObject,handles);
    end
catch ME
    errorstatus=ME.identifier;
    if strcmp(errorstatus,'MATLAB:unassignedOutputs') || strcmp(errorstatus,'MATLAB:m_incomplete_statement')
        handles.val_colorStackName=tempName;
        guidata(hObject,handles);
    else
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_colorStackName);
    end
end



% --- Executes during object creation, after setting all properties.
function colorStackName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to colorStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function redStackName_Callback(hObject, eventdata, handles)
% hObject    handle to redStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of redStackName as text
%        str2double(get(hObject,'String')) returns contents of redStackName as a double


% --- Executes during object creation, after setting all properties.
function redStackName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to redStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function greenStackName_Callback(hObject, eventdata, handles)
% hObject    handle to greenStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of greenStackName as text
%        str2double(get(hObject,'String')) returns contents of greenStackName as a double


% --- Executes during object creation, after setting all properties.
function greenStackName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to greenStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function blueStackName_Callback(hObject, eventdata, handles)
% hObject    handle to blueStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of blueStackName as text
%        str2double(get(hObject,'String')) returns contents of blueStackName as a double


% --- Executes during object creation, after setting all properties.
function blueStackName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to blueStackName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function aspectRatio_Callback(hObject, eventdata, handles)
% hObject    handle to aspectRatio (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of aspectRatio as text
%        str2double(get(hObject,'String')) returns contents of aspectRatio as a double
global STARTED;
global TH;
tempValue=str2double(get(hObject,'String'));
if tempValue<=0
    errordlg('Aspect ratio cannot be smaller than or equal to zero','Oops');
    set(hObject,'String',num2str(handles.val_aspectRatio));
else
handles.val_aspectRatio=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
end



% --- Executes during object creation, after setting all properties.
function aspectRatio_CreateFcn(hObject, eventdata, handles)
% hObject    handle to aspectRatio (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function outputImageName_Callback(hObject, eventdata, handles)
% hObject    handle to outputImageName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of outputImageName as text
%        str2double(get(hObject,'String')) returns contents of outputImageName as a double
handles.val_outputImageName=get(hObject,'String');
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function outputImageName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to outputImageName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel1ColorSelector.
function channel1ColorSelector_Callback(hObject, eventdata, handles)
% hObject    handle to channel1ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel1ColorSelector contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel1ColorSelector
global COLORS;
global STARTED;
global TH;
errorstatus=0;
if handles.val_inputType==1
    if handles.val_channel1OrigColor==8
        errorstatus=1;
    end
else
    tempName=get(handles.channel1Name,'String');
    try
        tempNameEval=evalin('base',tempName);
    catch ME
        errorstatus2=ME.identifier;
        if strcmp(errorstatus2,'MATLAB:unassignedOutputs') || strcmp(errorstatus2,'MATLAB:m_incomplete_statement')
            errorstatus=1;
        end
    end
end
if ~errorstatus
    axes(handles.channel1ColorScale);
    image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel1ColorScale));
    set(handles.channel1ColorScale,'Visible','off');
    handles.val_channel1ColorSelector=get(hObject,'Value');
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
else
    set(hObject,'Value',8);
    errordlg('The corresponding input channel is empty','Oops');
end




% --- Executes during object creation, after setting all properties.
function channel1ColorSelector_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function channel1Low_Callback(hObject, eventdata, handles)
% hObject    handle to channel1Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue>=handles.val_channelsHigh(1)
    errordlg('Low value cannot be larger than or equal to the high value','Oops');
    set(hObject,'Value',handles.val_channelsHigh(1)-0.01);
    handles.val_channelsLow(1)=handles.val_channelsHigh(1)-0.01;
else
    handles.val_channelsLow(1)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel1Low_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function channel1High_Callback(hObject, eventdata, handles)
% hObject    handle to channel1High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue<=handles.val_channelsLow(1)
    errordlg('High value cannot be smaller than or equal to the low value','Oops');
    set(hObject,'Value',handles.val_channelsLow(1)+0.01);
    handles.val_channelsHigh(1)=handles.val_channelsLow(1)+0.01;
else
    handles.val_channelsHigh(1)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel1High_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function channel1Guassian_Callback(hObject, eventdata, handles)
% hObject    handle to channel1Guassian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel1Guassian as text
%        str2double(get(hObject,'String')) returns contents of channel1Guassian as a double
global STARTED;
global TH;
tempValue=str2double(get(hObject,'String'));
if tempValue<0
    errordlg('The sigma of Gaussian filter cannot be smaller than zero.','Oops');
    set(hObject,'String',num2str(handles.val_channelsGaussian(1)));
else
    handles.val_channelsGaussian(1)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
end




% --- Executes during object creation, after setting all properties.
function channel1Guassian_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1Guassian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




function channel1Name_Callback(hObject, eventdata, handles)
% hObject    handle to channel1Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel1Name as text
%        str2double(get(hObject,'String')) returns contents of channel1Name as a double
global STARTED;
global COLORS;
STARTED=0;
tempName=get(hObject,'String');
try
    if str2num(tempName)~=0
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel1Name);
    else
        tempNameEval=evalin('base',tempName);
        handles.val_channel1Name=tempName;
        guidata(hObject,handles);
    end
catch ME
    errorstatus=ME.identifier;
    if strcmp(errorstatus,'MATLAB:unassignedOutputs') || strcmp(errorstatus,'MATLAB:m_incomplete_statement')
        handles.val_channel1Name=tempName;
        set(handles.channel1ColorSelector,'Value',8);
        handles.val_channel1ColorSelector=8;
        axes(handles.channel1ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel1ColorScale));
        set(handles.channel1ColorScale,'Visible','off');
        guidata(hObject,handles);
    else
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel1Name);
    end
end

% --- Executes during object creation, after setting all properties.
function channel1Name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function channel4Low_Callback(hObject, eventdata, handles)
% hObject    handle to channel4Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue>=handles.val_channelsHigh(4)
    errordlg('Low value cannot be larger than or equal to the high value','Oops');
    set(hObject,'Value',handles.val_channelsHigh(4)-0.01);
    handles.val_channelsLow(4)=handles.val_channelsHigh(4)-0.01;
else
    handles.val_channelsLow(4)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function channel4Low_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function channel4High_Callback(hObject, eventdata, handles)
% hObject    handle to channel4High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue<=handles.val_channelsLow(4)
    errordlg('High value cannot be smaller than or equal to the low value','Oops');
    set(hObject,'Value',handles.val_channelsLow(4)+0.01);
    handles.val_channelsHigh(4)=handles.val_channelsLow(4)+0.01;
else
    handles.val_channelsHigh(4)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);



% --- Executes during object creation, after setting all properties.
function channel4High_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function channel4Gaussian_Callback(hObject, eventdata, handles)
% hObject    handle to channel4Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel4Gaussian as text
%        str2double(get(hObject,'String')) returns contents of channel4Gaussian as a double
global STARTED;
global TH;
tempValue=str2double(get(hObject,'String'));
if tempValue<0
    errordlg('The sigma of Gaussian filter cannot be smaller than zero.','Oops');
    set(hObject,'String',num2str(handles.val_channelsGaussian(4)));
else
    handles.val_channelsGaussian(4)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
end




% --- Executes during object creation, after setting all properties.
function channel4Gaussian_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel4ColorSelector.
function channel4ColorSelector_Callback(hObject, eventdata, handles)
% hObject    handle to channel4ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel4ColorSelector contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel4ColorSelector
global COLORS;
global STARTED;
global TH;
errorstatus=0;
if handles.val_inputType==1
    if handles.val_channel4OrigColor==8
        errorstatus=1;
    end
else
    tempName=get(handles.channel4Name,'String');
    try
        tempNameEval=evalin('base',tempName);
    catch ME
        errorstatus2=ME.identifier;
        if strcmp(errorstatus2,'MATLAB:unassignedOutputs') || strcmp(errorstatus2,'MATLAB:m_incomplete_statement')
            errorstatus=1;
        end
    end
end
if ~errorstatus
    axes(handles.channel4ColorScale);
    image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel4ColorScale));
    set(handles.channel4ColorScale,'Visible','off');
    handles.val_channel4ColorSelector=get(hObject,'Value');
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
else
    set(hObject,'Value',8);
    errordlg('The corresponding input channel is empty','Oops');
end


% --- Executes during object creation, after setting all properties.
function channel4ColorSelector_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function channel3Low_Callback(hObject, eventdata, handles)
% hObject    handle to channel3Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue>=handles.val_channelsHigh(3)
    errordlg('Low value cannot be larger than or equal to the high value','Oops');
    set(hObject,'Value',handles.val_channelsHigh(3)-0.01);
    handles.val_channelsLow(3)=handles.val_channelsHigh(3)-0.01;
else
    handles.val_channelsLow(3)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel3Low_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function channel3High_Callback(hObject, eventdata, handles)
% hObject    handle to channel3High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue<=handles.val_channelsLow(3)
    errordlg('High value cannot be smaller than or equal to the low value','Oops');
    set(hObject,'Value',handles.val_channelsLow(3)+0.01);
    handles.val_channelsHigh(3)=handles.val_channelsLow(3)+0.01;
else
    handles.val_channelsHigh(3)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);



% --- Executes during object creation, after setting all properties.
function channel3High_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function channel3Gaussian_Callback(hObject, eventdata, handles)
% hObject    handle to channel3Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel3Gaussian as text
%        str2double(get(hObject,'String')) returns contents of channel3Gaussian as a double
global STARTED;
global TH;
tempValue=str2double(get(hObject,'String'));
if tempValue<0
    errordlg('The sigma of Gaussian filter cannot be smaller than zero.','Oops');
    set(hObject,'String',num2str(handles.val_channelsGaussian(3)));
else
    handles.val_channelsGaussian(3)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
end




% --- Executes during object creation, after setting all properties.
function channel3Gaussian_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel3ColorSelector.
function channel3ColorSelector_Callback(hObject, eventdata, handles)
% hObject    handle to channel3ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel3ColorSelector contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel3ColorSelector
global COLORS;
global STARTED;
global TH;
errorstatus=0;
if handles.val_inputType==1
    if handles.val_channel3OrigColor==8
        errorstatus=1;
    end
else
    tempName=get(handles.channel3Name,'String');
    try
        tempNameEval=evalin('base',tempName);
    catch ME
        errorstatus2=ME.identifier;
        if strcmp(errorstatus2,'MATLAB:unassignedOutputs') || strcmp(errorstatus2,'MATLAB:m_incomplete_statement')
            errorstatus=1;
        end
    end
end
if ~errorstatus
    axes(handles.channel3ColorScale);
    image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel3ColorScale));
    set(handles.channel3ColorScale,'Visible','off');
    handles.val_channel3ColorSelector=get(hObject,'Value');
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
else
    set(hObject,'Value',8);
    errordlg('The corresponding input channel is empty','Oops');
end




% --- Executes during object creation, after setting all properties.
function channel3ColorSelector_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function channel2Low_Callback(hObject, eventdata, handles)
% hObject    handle to channel2Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue>=handles.val_channelsHigh(2)
    errordlg('Low value cannot be larger than or equal to the high value','Oops');
    set(hObject,'Value',handles.val_channelsHigh(2)-0.01);
    handles.val_channelsLow(2)=handles.val_channelsHigh(2)-0.01;
else
    handles.val_channelsLow(2)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel2Low_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2Low (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function channel2High_Callback(hObject, eventdata, handles)
% hObject    handle to channel2High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global STARTED;
global TH;
tempValue=get(hObject,'Value');
if tempValue<=handles.val_channelsLow(2)
    errordlg('High value cannot be smaller than or equal to the low value','Oops');
    set(hObject,'Value',handles.val_channelsLow(2)+0.01);
    handles.val_channelsHigh(2)=handles.val_channelsLow(2)+0.01;
else
    handles.val_channelsHigh(2)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel2High_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2High (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function channel2Gaussian_Callback(hObject, eventdata, handles)
% hObject    handle to channel2Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel2Gaussian as text
%        str2double(get(hObject,'String')) returns contents of channel2Gaussian as a double
global STARTED;
global TH;
tempValue=str2double(get(hObject,'String'));
if tempValue<0
    errordlg('The sigma of Gaussian filter cannot be smaller than zero.','Oops');
    set(hObject,'String',num2str(handles.val_channelsGaussian(2)));
else
    handles.val_channelsGaussian(2)=tempValue;
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
end




% --- Executes during object creation, after setting all properties.
function channel2Gaussian_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2Gaussian (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel2ColorSelector.
function channel2ColorSelector_Callback(hObject, eventdata, handles)
% hObject    handle to channel2ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel2ColorSelector contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel2ColorSelector
global COLORS;
global STARTED;
global TH;
errorstatus=0;
if handles.val_inputType==1
    if handles.val_channel2OrigColor==8
        errorstatus=1;
    end
else
    tempName=get(handles.channel2Name,'String');
    try
        tempNameEval=evalin('base',tempName);
    catch ME
        errorstatus2=ME.identifier;
        if strcmp(errorstatus2,'MATLAB:unassignedOutputs') || strcmp(errorstatus2,'MATLAB:m_incomplete_statement')
            errorstatus=1;
        end
    end
end
if ~errorstatus
    axes(handles.channel2ColorScale);
    image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel2ColorScale));
    set(handles.channel2ColorScale,'Visible','off');
    handles.val_channel2ColorSelector=get(hObject,'Value');
    if STARTED==1
        set(handles.done,'String','BUSY');
        set(handles.done,'Visible','on');
        drawnow;
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    end
    guidata(hObject,handles);
else
    set(hObject,'Value',8);
    errordlg('The corresponding input channel is empty','Oops');
end




% --- Executes during object creation, after setting all properties.
function channel2ColorSelector_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2ColorSelector (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function channel2Name_Callback(hObject, eventdata, handles)
% hObject    handle to channel2Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel2Name as text
%        str2double(get(hObject,'String')) returns contents of channel2Name as a double
global STARTED;
global COLORS;
STARTED=0;
tempName=get(hObject,'String');
try
    if str2num(tempName)~=0
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel2Name);
    else
        tempNameEval=evalin('base',tempName);
        handles.val_channel2Name=tempName;
        guidata(hObject,handles);
    end
catch ME
    errorstatus=ME.identifier;
    if strcmp(errorstatus,'MATLAB:unassignedOutputs') || strcmp(errorstatus,'MATLAB:m_incomplete_statement')
        handles.val_channel2Name=tempName;
        set(handles.channel2ColorSelector,'Value',8);
        handles.val_channel2ColorSelector=8;
        axes(handles.channel2ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel2ColorScale));
        set(handles.channel2ColorScale,'Visible','off');
        guidata(hObject,handles);
    else
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel2Name);
    end
end


% --- Executes during object creation, after setting all properties.
function channel2Name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function channel3Name_Callback(hObject, eventdata, handles)
% hObject    handle to channel3Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel3Name as text
%        str2double(get(hObject,'String')) returns contents of channel3Name as a double
global STARTED;
global COLORS;
STARTED=0;
tempName=get(hObject,'String');
try
    if str2num(tempName)~=0
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel3Name);
    else
        tempNameEval=evalin('base',tempName);
        handles.val_channel3Name=tempName;
        guidata(hObject,handles);
    end
catch ME
    errorstatus=ME.identifier;
    if strcmp(errorstatus,'MATLAB:unassignedOutputs') || strcmp(errorstatus,'MATLAB:m_incomplete_statement')
        handles.val_channel3Name=tempName;
        handles.val_channel3Name=tempName;
        set(handles.channel3ColorSelector,'Value',8);
        handles.val_channel3ColorSelector=8;
        axes(handles.channel3ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel3ColorScale));
        set(handles.channel3ColorScale,'Visible','off');
        guidata(hObject,handles);
    else
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel3Name);
    end
end


% --- Executes during object creation, after setting all properties.
function channel3Name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function channel4Name_Callback(hObject, eventdata, handles)
% hObject    handle to channel4Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of channel4Name as text
%        str2double(get(hObject,'String')) returns contents of channel4Name as a double
global STARTED;
global COLORS;
STARTED=0;
tempName=get(hObject,'String');
try
    if str2num(tempName)~=0
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel4Name);
    else
        tempNameEval=evalin('base',tempName);
        handles.val_channel4Name=tempName;
        guidata(hObject,handles);
    end
catch ME
    errorstatus=ME.identifier;
    if strcmp(errorstatus,'MATLAB:unassignedOutputs') || strcmp(errorstatus,'MATLAB:m_incomplete_statement')
        handles.val_channel4Name=tempName;
        handles.val_channel4Name=tempName;
        set(handles.channel4ColorSelector,'Value',8);
        handles.val_channel4ColorSelector=8;
        axes(handles.channel4ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel4ColorScale));
        set(handles.channel4ColorScale,'Visible','off');
        guidata(hObject,handles);
    else
        errordlg(['Couldn',char(39),'t evaluate variable.'],'Oops');
        set(hObject,'String',handles.val_channel4Name);
    end
end


% --- Executes during object creation, after setting all properties.
function channel4Name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4Name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel1OrigColor.
function channel1OrigColor_Callback(hObject, eventdata, handles)
% hObject    handle to channel1OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel1OrigColor contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel1OrigColor
global COLORS;
global STARTED;
global TH;
axes(handles.channel1OrigColorScale);
image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel1OrigColorScale));
set(handles.channel1OrigColorScale,'Visible','off');
handles.val_channel1OrigColor=get(hObject,'Value');
if get(hObject,'Value')==8
        set(handles.channel1ColorSelector,'Value',8);
        handles.val_channel1ColorSelector=8;
        axes(handles.channel1ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel1ColorScale));
        set(handles.channel1ColorScale,'Visible','off');
end
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    [handles.val_dipimage,e_flag]=generateUnmixedStack(handles);
    guidata(hObject,handles);
    if e_flag~=1
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    else
        stop(TH);
        set(handles.done,'String','ERROR');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel1OrigColor_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel1OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel2OrigColor.
function channel2OrigColor_Callback(hObject, eventdata, handles)
% hObject    handle to channel2OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel2OrigColor contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel2OrigColor
global COLORS;
global STARTED;
global TH;
axes(handles.channel2OrigColorScale);
image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel2OrigColorScale));
set(handles.channel2OrigColorScale,'Visible','off');
handles.val_channel2OrigColor=get(hObject,'Value');
if get(hObject,'Value')==8
        set(handles.channel2ColorSelector,'Value',8);
        handles.val_channel2ColorSelector=8;
        axes(handles.channel2ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel2ColorScale));
        set(handles.channel2ColorScale,'Visible','off');
end
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    [handles.val_dipimage,e_flag]=generateUnmixedStack(handles);
    guidata(hObject,handles);
    if e_flag~=1
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    else
        stop(TH);
        set(handles.done,'String','ERROR');
        start(TH);
    end
end
guidata(hObject,handles);



% --- Executes during object creation, after setting all properties.
function channel2OrigColor_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel2OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel3OrigColor.
function channel3OrigColor_Callback(hObject, eventdata, handles)
% hObject    handle to channel3OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel3OrigColor contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel3OrigColor
global COLORS;
global STARTED;
global TH;
axes(handles.channel3OrigColorScale);
image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel3OrigColorScale));
set(handles.channel3OrigColorScale,'Visible','off');
handles.val_channel3OrigColor=get(hObject,'Value');
if get(hObject,'Value')==8
        set(handles.channel3ColorSelector,'Value',8);
        handles.val_channel3ColorSelector=8;
        axes(handles.channel3ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel3ColorScale));
        set(handles.channel3ColorScale,'Visible','off');
end
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    [handles.val_dipimage,e_flag]=generateUnmixedStack(handles);
    guidata(hObject,handles);
    if e_flag~=1
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    else
        stop(TH);
        set(handles.done,'String','ERROR');
        start(TH);
    end
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function channel3OrigColor_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel3OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in channel4OrigColor.
function channel4OrigColor_Callback(hObject, eventdata, handles)
% hObject    handle to channel4OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns channel4OrigColor contents as cell array
%        contents{get(hObject,'Value')} returns selected item from channel4OrigColor
global COLORS;
global STARTED;
global TH;
axes(handles.channel4OrigColorScale);
image(drawColorScale(COLORS(get(hObject,'Value'),:),handles.channel4OrigColorScale));
set(handles.channel4OrigColorScale,'Visible','off');
handles.val_channel4OrigColor=get(hObject,'Value');
if get(hObject,'Value')==8
        set(handles.channel4ColorSelector,'Value',8);
        handles.val_channel4ColorSelector=8;
        axes(handles.channel4ColorScale);
        image(drawColorScale(COLORS(8,:),handles.channel4ColorScale));
        set(handles.channel4ColorScale,'Visible','off');
end
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    [handles.val_dipimage,e_flag]=generateUnmixedStack(handles);
    guidata(hObject,handles);
    if e_flag~=1
        generateSmoothedStack(handles);
        contrastStretch(handles);
        createView(handles);
        stop(TH);
        set(handles.done,'String','DONE');
        start(TH);
    else
        stop(TH);
        set(handles.done,'String','ERROR');
        start(TH);
    end
end
guidata(hObject,handles);



% --- Executes during object creation, after setting all properties.
function channel4OrigColor_CreateFcn(hObject, eventdata, handles)
% hObject    handle to channel4OrigColor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


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

% Hint: get(hObject,'Value') returns toggle state of orthogonalView
handles.val_orthogonalView=get(hObject,'Value');
global STARTED;
global TH;
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    createView(handles);
    stop(TH);
    set(handles.done,'String','DONE');
    start(TH);
end
guidata(hObject,handles);


function rainbow=drawColorScale(color,scaleHandle)
s=get(scaleHandle,'Position');
s=s(3:4);
x=linspace(0,1,s(1))';
rainbow=permute(repmat(x*color,[1,1,s(2)]),[3,1,2]);


function drawMultipleColorScales(colors,handles)
for i=1:size(handles,2)
    axes(handles(i));
    image(drawColorScale(colors(i,:),handles(i)));
    set(handles(i),'Visible','off');
end


% --- Executes on selection change in clipNormalizeType.
function clipNormalizeType_Callback(hObject, eventdata, handles)
% hObject    handle to clipNormalizeType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns clipNormalizeType contents as cell array
%        contents{get(hObject,'Value')} returns selected item from clipNormalizeType
handles.val_clipNormalizeType=get(hObject,'Value');
global STARTED;
global TH;
if STARTED==1
    set(handles.done,'String','BUSY');
    set(handles.done,'Visible','on');
    drawnow;
    createView(handles);
    stop(TH);
    set(handles.done,'String','DONE');
    start(TH);
end
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function clipNormalizeType_CreateFcn(hObject, eventdata, handles)
% hObject    handle to clipNormalizeType (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in helpButton.
function helpButton_Callback(hObject, eventdata, handles)
% hObject    handle to helpButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pathstr=fileparts(which('confortho.m'));
web(['file:///',pathstr,filesep,'help',filesep,'confortho_help.html']);


% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global STARTED;
global COLORS;
STARTED=0;
if strcmp(get(eventdata.NewValue,'Tag'),'overlaidButton')
    set(handles.overlaidPanel,'Visible','on');
    set(handles.separatePanel,'Visible','off');
    handles.val_inputType=1;
    objectList=get(handles.overlaidPanel,'Children');
    objectList=findobj(objectList,'Style','popupmenu');
    objectList1(1)=findobj(objectList,'Tag','channel1OrigColor');
    objectList1(2)=findobj(objectList,'Tag','channel2OrigColor');
    objectList1(3)=findobj(objectList,'Tag','channel3OrigColor');
    objectList1(4)=findobj(objectList,'Tag','channel4OrigColor');
    objectList=get(handles.figure1,'Children');
    objectList=findobj(objectList,'Type','uipanel');
    objectList2(1)=findobj(objectList,'Title','Channel 1');
    objectList2(2)=findobj(objectList,'Title','Channel 2');
    objectList2(3)=findobj(objectList,'Title','Channel 3');
    objectList2(4)=findobj(objectList,'Title','Channel 4');
    for i=1:size(objectList2,2)
        objectList3(i)=findobj(objectList2(i),'Style','popupmenu');
        objectList4(i)=findobj(objectList2(i),'XScale','linear');
    end
    for i=1:size(objectList1,2)
        if get(objectList1(i),'value')==8
            set(objectList3(i),'value',8);
            switch i
                case 1 
                    handles.val_channel1ColorSelector=8;
                case 2 
                    handles.val_channel2ColorSelector=8;
                case 3 
                    handles.val_channel3ColorSelector=8;
                case 4 
                    handles.val_channel4ColorSelector=8;
            end
            axes(objectList4(i));
            image(drawColorScale(COLORS(8,:),objectList4(i)));
            set(objectList4(i),'Visible','off');
        end
    end
else % 'separateButton'
    set(handles.overlaidPanel,'Visible','off');
    set(handles.separatePanel,'Visible','on');
    handles.val_inputType=2;
    objectList=get(handles.separatePanel,'Children');
    objectList=findobj(objectList,'style','edit');
    objectList1(1)=findobj(objectList,'Tag','channel1Name');
    objectList1(2)=findobj(objectList,'Tag','channel2Name');
    objectList1(3)=findobj(objectList,'Tag','channel3Name');
    objectList1(4)=findobj(objectList,'Tag','channel4Name');
    objectList=get(handles.figure1,'Children');
    objectList=findobj(objectList,'Type','uipanel');
    objectList2(1)=findobj(objectList,'Title','Channel 1');
    objectList2(2)=findobj(objectList,'Title','Channel 2');
    objectList2(3)=findobj(objectList,'Title','Channel 3');
    objectList2(4)=findobj(objectList,'Title','Channel 4');
    for i=1:size(objectList2,2)
        objectList3(i)=findobj(objectList2(i),'Style','popupmenu');
        objectList4(i)=findobj(objectList2(i),'XScale','linear');
    end
    for i=1:size(objectList1,2)
        try
            im=get(objectList1(i),'String');
            im=evalin('base',im);
        catch
            set(objectList3(i),'value',8);
            switch i
                case 1 
                    handles.val_channel1ColorSelector=8;
                case 2 
                    handles.val_channel2ColorSelector=8;
                case 3 
                    handles.val_channel3ColorSelector=8;
                case 4 
                    handles.val_channel4ColorSelector=8;
            end
            axes(objectList4(i));
            image(drawColorScale(COLORS(8,:),objectList4(i)));
            set(objectList4(i),'Visible','off');
        end
    end
end
guidata(hObject,handles);


% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
currentValueOfUserData=get(handles.peterHandle,'userdata');
cp=get(hObject,'CurrentPoint');
phPosition=get(handles.peterHandle,'position');
if cp(1)>phPosition(1) && cp(1)<phPosition(1)+phPosition(3) && cp(2)>phPosition(2) && cp(2)<phPosition(2)+phPosition(4)
    set(hObject,'pointer','hand');
    if currentValueOfUserData==0
        set(handles.peterHandle,'String','Email: peter.v.nagy@gmail.com');
        set(handles.peterHandle,'userdata',2);
        set(handles.peterHandle,'ButtonDownFcn',{@peternagy_callback,'mailto:peter.v.nagy@gmail.com'});
    elseif currentValueOfUserData==1
        set(handles.peterHandle,'String','http://peternagy.webs.com');
        set(handles.peterHandle,'userdata',3);
        set(handles.peterHandle,'ButtonDownFcn',{@peternagy_callback,'http://peternagy.webs.com'});
    end
else
    set(hObject,'pointer','arrow');
    set(handles.peterHandle,'string','Written by Peter Nagy');
    set(handles.peterHandle,'ButtonDownFcn','');
    if currentValueOfUserData>1
        set(handles.peterHandle,'userdata',3-currentValueOfUserData);
    end
end

function peternagy_callback(src,evtdata,link)
web(link,'-browser');


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
global EXITPRESSED;
global OUTPUTWINDOWHANDLE;
global TH;
clear global UNMIXEDCHANNELS;
clear global SMOOTHEDCHANNELS;
clear global STRETCHEDCHANNELS;
clear global REMIXEDCHANNELS;
clear global FINALIMAGE;
delete(TH);
EXITPRESSED=1;
if OUTPUTWINDOWHANDLE~=0
    try
        set(OUTPUTWINDOWHANDLE,'WindowButtonMotionFcn','');
        set(OUTPUTWINDOWHANDLE,'WindowButtonUpFcn','');
        objectList=get(OUTPUTWINDOWHANDLE,'Children');
        for i=1:size(objectList,1)
            if strcmp(get(objectList(i),'Type'),'axes')
                ah=i;
            end
        end
        objectList2=get(objectList(ah),'Children');
        for i=1:size(objectList2,1)
            if strcmp(get(objectList2(i),'Type'),'line')
                set(objectList2(i),'ButtonDownFcn','');
            end
        end
    end
end
delete(hObject);

Contact us