IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques Discussion :

Interface avec image


Sujet :

Interfaces Graphiques

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Juillet 2010
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 23
    Par défaut Interface avec image
    Bonjour,

    Pourquoi lorsque on utilise l'interface graphique de MATLAB pour un traitement d'image, l'exécution des fonctions prend beaucoup plus de temps que prévu?

    Voila un exemple de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
     
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    function varargout = imag(varargin)
    % IMAG M-file for imag.fig
    %      IMAG, by itself, creates a new IMAG or raises the existing
    %      singleton*.
    %
    %      H = IMAG returns the handle to a new IMAG or the handle to
    %      the existing singleton*.
    %
    %      IMAG('CALLBACK',hObject,eventData,handles,...) calls the local
    %      function named CALLBACK in IMAG.M with the given input arguments.
    %
    %      IMAG('Property','Value',...) creates a new IMAG or raises the
    %      existing singleton*.  Starting from the left, property value pairs are
    %      applied to the GUI before imag_OpeningFunction gets called.  An
    %      unrecognized property name or invalid value makes property application
    %      stop.  All inputs are passed to imag_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 imag
     
    % Last Modified by GUIDE v2.5 24-Sep-2010 16:52:39
     
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
                       'gui_Singleton',  gui_Singleton, ...
                       'gui_OpeningFcn', @imag_OpeningFcn, ...
                       'gui_OutputFcn',  @imag_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 imag is made visible.
    function imag_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 imag (see VARARGIN)
     
    % Choose default command line output for imag
    handles.output = hObject;
     
    % Update handles structure
    guidata(hObject, handles);
     
    % UIWAIT makes imag wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
     
     
    % --- Outputs from this function are returned to the command line.
    function varargout = imag_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
    varargout{1} = handles.output;
     
     
    % --- Executes on button press in floatImg.
    function floatImg_Callback(hObject, eventdata, handles)
    % hObject    handle to floatImg (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg;
    [reg.floatFile,reg.floatPath] = uigetfile({'*.jpg';'*.png';'*.tif';'*.tiff'},'Open the Floating Image');
    reg.floatImg=double(imread([reg.floatPath '/' reg.floatFile]));
    axes(handles.axes1);
    reg.floatImgHandle=imshow(reg.floatImg,[0 255]);
    set(reg.floatImgHandle,'HitTest','on');
    grid off;
    zoom off;
     
     
    % --- Executes on button press in refImg.
    function refImg_Callback(hObject, eventdata, handles)
    % hObject    handle to refImg (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg;
    [reg.refFile,reg.refPath] = uigetfile({'*.jpg';'*.png';'*.tif';'*.tiff'},'Open the Reference Image');
    reg.refImg=double(imread([reg.refPath '/' reg.refFile]));
    axes(handles.axes2);
    reg.refImgHandle=imshow(reg.refImg,[0 255]);
    set(reg.refImgHandle,'HitTest','on');
    grid off;
    zoom off;
     
     
    % --- Executes on button press in pushbutton3.
    function pushbutton3_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton3 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg
    A=reg.refImg
    B=reg.floatImg
     
    c=A*B
     
    %%%%%%%%%%%%%%%%%%%%%%
    Si quelqu'un pouvait m'aider sur ca,
    Merci

  2. #2
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Juin 2010
    Messages
    319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 319
    Par défaut
    Bonjour,

    Quel bouton te ralentit (car je suppose que c'est dans les boutons que tu as codés l'ensemble de ton algo) ?

    Par ailleurs, quel est l'intérêt de faire
    si le résultat n'est pas affiché sur l'interface ?

    Remarque : tu n'as pas mis le point-virgule à la fin, donc c'est peut-être à cause de ça que tu trouve MatLab "ralenti", car il affiche le résultat sur ta fenêtre de commande ...

  3. #3
    Membre averti
    Inscrit en
    Juillet 2010
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 23
    Par défaut interface matlab image
    bonjour j' ait essayer avec ;point vergule a la fin mais c'est toujour lent
    est ce que vous avez teter cet exemple sur votre pc
    pour moi lorsque j'utilise cette exemple sans iterface ca prend meme pas quelque seconds alors que en utilisant l'interface ca prend des minutes
    aider moi svp

  4. #4
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Par défaut
    Bonjour,

    tout d'abord, évite d'appeler ta fonction imag, c'est déjà le nom d'une fonction MATLAB.

    Sinon, on ne peut pas tester ton fichier, tu ne nous as pas fourni le fichier imag.fig...

    Mais à priori un tel écart n'est pas normal. Tu fais le calcul sur les mêmes images? Peux-tu nous montrer aussi ton code sans interface?
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  5. #5
    Membre averti
    Inscrit en
    Juillet 2010
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 23
    Par défaut interface matlab image
    bonjour
    en fait voila le programme .m et .fig ainsi que les fonction necessaire
    est ce vous pouver l'executer et tester

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    function varargout = ehjh(varargin)
    % EHJH M-file for ehjh.fig
    %      EHJH, by itself, creates a new EHJH or raises the existing
    %      singleton*.
    %
    %      H = EHJH returns the handle to a new EHJH or the handle to
    %      the existing singleton*.
    %
    %      EHJH('CALLBACK',hObject,eventData,handles,...) calls the local
    %      function named CALLBACK in EHJH.M with the given input arguments.
    %
    %      EHJH('Property','Value',...) creates a new EHJH or raises the
    %      existing singleton*.  Starting from the left, property value pairs are
    %      applied to the GUI before ehjh_OpeningFunction gets called.  An
    %      unrecognized property name or invalid value makes property application
    %      stop.  All inputs are passed to ehjh_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 ehjh
     
    % Last Modified by GUIDE v2.5 26-Sep-2010 19:22:35
    global reg
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
                       'gui_Singleton',  gui_Singleton, ...
                       'gui_OpeningFcn', @ehjh_OpeningFcn, ...
                       'gui_OutputFcn',  @ehjh_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 ehjh is made visible.
    function ehjh_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 ehjh (see VARARGIN)
     
    % Choose default command line output for ehjh
    handles.output = hObject;
     
    % Update handles structure
    guidata(hObject, handles);
     
    % UIWAIT makes ehjh wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
     
     
    % --- Outputs from this function are returned to the command line.
    function varargout = ehjh_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)
    global reg
    % Get default command line output from handles structure
    varargout{1} = handles.output;
     
     
    % --- Executes on button press in pushbutton1.
    function pushbutton1_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg;
     
    [reg.refFile,reg.refPath] = uigetfile({'*.jpg';'*.png';'*.tif';'*.tiff'},'Open the Reference Image');
    reg.refImg=(imread([reg.refPath '/' reg.refFile]));
    axes(handles.axes1);
    reg.refImgHandle=imshow(reg.refImg,[0 255]);
    set(reg.refImgHandle,'HitTest','on');
    grid off;
    zoom off;
     
    % --- Executes on button press in pushbutton2.
    function pushbutton2_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton2 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg;
    [reg.floatFile,reg.floatPath] = uigetfile({'*.jpg';'*.png';'*.tif';'*.tiff'},'Open the Floating Image');
    reg.floatImg=(imread([reg.floatPath '/' reg.floatFile]));
    axes(handles.axes2);
    reg.floatImgHandle=imshow(reg.floatImg,[0 255]);
    set(reg.floatImgHandle,'HitTest','on');
    grid off;
    zoom off;
     
     
    % --- Executes on button press in pushbutton3.
    function pushbutton3_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton3 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    global reg;
    A = reg.refImg;
    B = reg.floatImg;
    NP=16;
    D=3;
    F=0.525;
    CR=0.8;
    itermax=40;
    strategy=2;
     
    objFctHandle= @(x) transforma(x,A,B);
    %-----Check input variables-----------------------------------------------
    if (NP < 5)
       fprintf(1,'Error! NP should be >= 5\n');
    end
    if ((CR < 0) | (CR > 1))
       fprintf(1,'Error! CR should be ex [0,1]\n');
    end
    if (itermax < 0)
       fprintf(1,'Error! itermax should be > 0\n');
    end
     
    %-----Initialize population and some arrays-------------------------------
     
    pop = zeros(NP,D); %initialize pop to gain speed
    lowbound1  = -100;   % Lower bound for parameters (all parameters treated alike)
    highbound1 = 100;   % Upper bound for parameters (all parameters treated alike)
    lowbound2  = -100;    % Lower bound for parameters (all parameters treated alike)
    highbound2 = 100;    % Upper bound for parameters (all parameters treated alike)
    lowbound3 = -100;
    highbound3 = 100;
    %----pop is a matrix of size NPxD. It will be initialized-------------
    %----with random values between highbound and lowbound----------------
     
    for i=1:NP
       pop(i,1) = lowbound1 + rand*(highbound1 - lowbound1);
       pop(i,2) = lowbound2 + rand*(highbound2 - lowbound2);
       pop(i,3) = lowbound3 + rand*(highbound3 - lowbound3);
    end
     
    popold    = zeros(size(pop));     % toggle population
    val       = zeros(1,NP);          % create and reset the "cost array"
    bestmem   = zeros(1,D);           % best population member ever
    bestmemit = zeros(1,D);           % best population member in iteration
    nfeval    = 0;                    % number of function evaluations
     
    %------Evaluate the best member after initialization----------------------
    %------Objective function is the Rosenbrock saddle------------------------
    %------100*(x2-x1^2)^2+(1-x1)^2.------------------------------------------
     
    ibest   = 1;                      % start with first population member
    %   >>>>>>>>>>>eval<<<<<<<<<<<<<<<
    val(1)  = objFctHandle([pop(ibest,1) pop(ibest,2) pop(ibest,3)]);
    bestval = val(1);                 % best objective function value so far
    nfeval  = nfeval + 1;
    for i=2:NP                        % check the remaining members
    %   >>>>>>>>>>>eval<<<<<<<<<<<<<<<
      val(i) = objFctHandle([pop(i,1) pop(i,2) pop(i,3)]);
      nfeval  = nfeval + 1;
      if (val(i) < bestval)           % if member is better
         ibest   = i;                 % save its location
         bestval = val(i);
      end   
    end
    bestmemit = pop(ibest,:);         % best member of current iteration
    bestvalit = bestval;              % best value of current iteration
     
    bestmem = bestmemit;              % best member ever
           % 3D-plot function
     
    %------DE-Minimization---------------------------------------------
    %------popold is the population which has to compete. It is--------
    %------static through one iteration. pop is the newly--------------
    %------emerging population.----------------------------------------
     
    pm1 = zeros(NP,D);              % initialize population matrix 1
    pm2 = zeros(NP,D);              % initialize population matrix 2
    pm3 = zeros(NP,D);              % initialize population matrix 3
    pm4 = zeros(NP,D);              % initialize population matrix 4
    pm5 = zeros(NP,D);              % initialize population matrix 5
    bm  = zeros(NP,D);              % initialize bestmember  matrix
    ui  = zeros(NP,D);              % intermediate population of perturbed vectors
    mui = zeros(NP,D);              % mask for intermediate population
    mpo = zeros(NP,D);              % mask for old population
    rot = (0:1:NP-1);               % rotating index array
    rt  = zeros(NP);                % another rotating index array
    a1  = zeros(NP);                % index array
    a2  = zeros(NP);                % index array
    a3  = zeros(NP);                % index array
    a4  = zeros(NP);                % index array
    a5  = zeros(NP);                % index array
    ind = zeros(4);
     
    iter = 1;
    while ((iter < itermax) & (bestval > -2))
      popold = pop;                   % save the old population
     
      ind = randperm(4);              % index pointer array
     
      a1  = randperm(NP);             % shuffle locations of vectors
      rt = rem(rot+ind(1),NP);        % rotate indices by ind(1) positions
      a2  = a1(rt+1);                 % rotate vector locations
      rt = rem(rot+ind(2),NP);
      a3  = a2(rt+1);                
      rt = rem(rot+ind(3),NP);
      a4  = a3(rt+1);               
      rt = rem(rot+ind(4),NP);
      a5  = a4(rt+1);                
     
      pm1 = popold(a1,:);             % shuffled population 1
      pm2 = popold(a2,:);             % shuffled population 2
      pm3 = popold(a3,:);             % shuffled population 3
      pm4 = popold(a4,:);             % shuffled population 4
      pm5 = popold(a5,:);             % shuffled population 5
     
      for i=1:NP                      % population filled with the best member
        bm(i,:) = bestmemit;          % of the last iteration
      end
     
      mui = rand(NP,D) < CR;          % all random numbers < CR are 1, 0 otherwise
      mpo = mui < 0.5;                % inverse mask to mui
     
      if (strategy == 1)                % DE/best/1
        ui = bm + F*(pm1 - pm2);        % differential variation
        ui = popold.*mpo + ui.*mui;     % binomial crossover
      elseif (strategy == 2)            % DE/rand/1
        ui = pm3 + F*(pm1 - pm2);       % differential variation
        ui = popold.*mpo + ui.*mui;     % binomial crossover
      elseif (strategy == 3)            % DE/rand-to-best/1
        ui = popold + F*(bm-popold) + F*(pm1 - pm2);        
        ui = popold.*mpo + ui.*mui;     % binomial crossover
      elseif (strategy == 4)            % DE/best/2
        ui = bm + F*(pm1 - pm2 + pm3 - pm4);  % differential variation
        ui = popold.*mpo + ui.*mui;           % binomial crossover
      else                              % DE/rand/2
        ui = pm5 + F*(pm1 - pm2 + pm3 - pm4);  % differential variation
        ui = popold.*mpo + ui.*mui;            % binomial crossover
      end
     
    %-----Select which vectors are allowed to enter the new population------------
      for i=1:NP
    %   >>>>>>>>>>>eval<<<<<<<<<<<<<<<100*(x2-x1^2)^2+(1-x1)^2.-
        tempval = objFctHandle([ui(i,1) ui(i,2) ui(i,3)]);   % check cost of competitor
        nfeval  = nfeval + 1;
        if (tempval <= val(i))  % if competitor is better than value in "cost array"
           pop(i,:) = ui(i,:);  % replace old vector with new one (for new iteration)
           val(i)   = tempval;  % save value in "cost array"
     
           %----we update bestval only in case of success to save time-----------
           if (tempval < bestval)     % if competitor better than the best one ever
              bestval = tempval;      % new best value
              bestmem = ui(i,:);      % new best parameter vector ever
           end
        end
      end %---end for imember=1:NP
     
      bestmemit = bestmem;       % freeze the best member of this iteration for the coming 
                                 % iteration. This is needed for some of the strategies.
     
    %----Output section----------------------------------------------------------
     
      if (rem(iter,10) == 0)
         fprintf(1,'Iteration: %d,  Best: %f,  F: %f,  CR: %f,  NP: %d\n',iter,bestval,F,CR,NP);
         for n=1:D
           fprintf(1,'best(%d) = %f\n',n,bestmem(n));
         end
      end
     
     
     
     
      iter = iter + 1;
    end %---end while ((iter < itermax) ...
     
     
     
    return
     
                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    la fonction transforma


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    function m=transforma(x,img1,img2)
     %%%%%%%%%%%%%%%%%%image reference%%%%%%%%%%
     
     
     
    %%%%%%%%%%%%%%%%image registration%%%%%%%%%%%%%%%%%%
     
    Ireg=interpol(img1,[x(1) x(2) x(3)],'BL')
     
     
    m=-corr2(Ireg,img2)
     
     
     
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    la fonction interpol
     
     
    function B = interpol(A, vec, method)
    %
    %
     
     
     
    [h w z] = size(A);
     
    % set defaults
     
        tx = vec(1);
        ty = vec(2);
        ang= vec(3);
        s  = 1;
     
     
    % convert to rad
    phi = ang*pi/180;
     
    % forward transformation matrix
    H = [ s*cos(phi) -s*sin(phi)  tx; ...
          s*sin(phi)  s*cos(phi)  ty; ...
           0           0           1 ];
     
    % x/y-coords for each pixel (center in the middle of the img)
    x  = repmat([1:w],h,1)-w/2;
    y  = (repmat([1:h],w,1)-h/2)';
    xy = [x(:)';y(:)';ones(1,w*h)];
     
    % Transform all the coordinates and normalise
    xsys = inv(H)*xy;                          % inverse mapping!
    xsys = xsys(1:2,:)./[xsys(3,:);xsys(3,:)]; % normalise
    xsys = xsys+repmat([w/2;h/2],1,w*h);       % img coord -> matrix coord
     
    % create the output image
    B = zeros(h,w);
     
    % process each pixel individually
    i=0;
    for x = 1:w
        for y = 1:h
            r = 0;
            i = i+1;
            xs = xsys(1,i); % round because NN
            ys = xsys(2,i); %   "
            switch method
                case 'NN'
                    % select the nearest neighbour by rounding
                    xs = round(xs);
                    ys = round(ys);
                    % check the boundaries
                    if (xs>0) & (xs<=w) & (ys>0) & (ys<=h)
                        r = A(ys,xs);
                    end
                case 'BL'
                    xs_floor = floor(xs);
                    xs_ceil  = xs_floor+1;
                    ys_floor = floor(ys);
                    ys_ceil  = ys_floor+1;
                    if (xs_floor>0) & (xs_ceil<=w) & (ys_floor>0) & (ys_ceil<=h)
                        w1 = (xs-xs_floor);
                        w3 = w1;
                        w2 = (xs_ceil-xs);
                        w4 = w2;
                        t = (ys_ceil-ys);
                        w1 = w1*t;
                        w2 = w2*t;
                        t = (ys-ys_floor);
                        w3 = w3*t;
                        w4 = w4*t;
                        r = A(ys_floor,xs_ceil)*w1+A(ys_floor,xs_floor)*w2+A(ys_ceil,xs_ceil)*w3+A(ys_ceil,xs_floor)*w4;
                    end
     
                    %% slow but somewhat more readable implementation
                    %
                    % xs_floor = floor(xs);
                    % xs_ceil  = xs_floor+1;
                    % ys_floor = floor(ys);
                    % ys_ceil  = ys_floor+1;
                    % if (xs_floor>0) & (xs_ceil<=w) & (ys_floor>0) & (ys_ceil<=h)
                    %     w1 = (xs-xs_floor) * (ys_ceil-ys);
                    %     w2 = (xs_ceil-xs)  * (ys_ceil-ys);
                    %     w3 = (xs-xs_floor) * (ys-ys_floor);
                    %     w4 = (xs_ceil-xs)  * (ys-ys_floor);
                    %     r = A(ys_floor,xs_ceil)*w1+A(ys_floor,xs_floor)*w2+A(ys_ceil,xs_ceil)*w3+A(ys_ceil,xs_floor)*w4;
                    % end
                case 'CCB'
    				% boundaries
    				x2 = floor(xs);
                    y2 = floor(ys);
     
    				% check the boundaries
                    if (x2>1) & (x2+2<=w) & (y2>1) & (y2+2<=h)
                        %
                        xvec = [x2-1 x2 x2+1 x2+2];
                        yvec = [y2-1 y2 y2+1 y2+2];
     
                        % catmull weights
            			weightx = catmull(xvec-xs);
                		weighty = catmull(yvec-ys);
     
                        % Neighbours window
                        win = A(yvec,xvec);
     
                        % interpolation x
                        rx = win(:,1).*weightx(1) + win(:,2).*weightx(2) + win(:,3).*weightx(3) + win(:,4).*weightx(4);
                        % Interpolation y
                        r = rx(1)*weighty(1)+rx(2)*weighty(2)+rx(3)*weighty(3)+rx(4)*weighty(4);
                    end
     
                    %% slower but somewhat more readable implementation
                    %
                    % xs_floor = floor(xs)-1;
                    % xs_ceil  = xs_floor+2;
                    % ys_floor = floor(ys)-1;
                    % ys_ceil  = ys_floor+2;
                    % if (xs_floor>0) & (xs_ceil<=w) & (ys_floor>0) & (ys_ceil<=h)
                    %     I = [0 0 0 0];
                    %     j = 1;
                    %     for v=ys_floor:ys_ceil
                    %         for u=xs_floor:xs_ceil
                    %             I(j) = I(j) + A(v,u)*catmull(xs-u);
                    %         end
                    %         j = j+1;
                    %     end
                    %     for v=ys_floor:ys_ceil
                    %         r = r + I(v-ys_floor+1)*catmull(ys-v);
                    %     end
                    % end
            end
            B(y,x)=r;
     
        end
     
    end
     
     
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%

  6. #6
    Membre averti
    Inscrit en
    Juillet 2010
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 23
    Par défaut matlab interface graphique
    pour le .fig comment le copier ,

Discussions similaires

  1. [votre avis m'interesse] Interface avec un programme Java
    Par LineLe dans le forum Interfaces Graphiques en Java
    Réponses: 29
    Dernier message: 11/12/2004, 11h39
  2. Interfaces avec le même nom
    Par myuils dans le forum Langage
    Réponses: 2
    Dernier message: 09/11/2004, 18h18
  3. Piloter une interface avec des relais
    Par Yepazix dans le forum API, COM et SDKs
    Réponses: 13
    Dernier message: 26/10/2004, 19h46
  4. boîte de dialogue avec image de fond + texte
    Par Eugénie dans le forum MFC
    Réponses: 13
    Dernier message: 31/08/2004, 13h32
  5. Interfaces avec NetBeans
    Par messier79 dans le forum NetBeans
    Réponses: 3
    Dernier message: 26/04/2004, 15h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo