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

MATLAB Discussion :

probleme avec code matlab


Sujet :

MATLAB

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut probleme avec code matlab
    bonjour,

    Dans le cadre d'un projet d’étude sur la reconnaissance facial je rencontre de nombreux problèmes sur la programmation. Tout d'abords je reçois ce message d'erreur : Undefined function 'imshow' for input arguments of type 'char' que je ne réussis pas a résoudre. De plus j'ai quelque problème dans la compréhension du code. j'ai la version R2013a de matlab.
    Est ce que vous pouvez m'aider ?

    lien du code : http://www.pages.drexel.edu/~sis26/Eigencode.htm

    voici mon code pour l'instant:
    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
    clear all
    close all
    clc
    % number of images on your training set.
    M=8;
     
    % Chosen std and mean.
    % It can be any number that it is close to the std and mean of most of the images.
    um=100;
    ustd=80;
     
    % read and show image
    S=['1.jpg'];    % img matrix
    figure(1);
    for i=1:M
    str=strcat(int2str(i),'.jpg');    % concatenates two strings that form the name of the image
    eval('img=imread(str);');
    subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
    imshow('1.jpg')
    if i==3
    title('tipe','403*403',18)
    end
    drawnow;
    [irow, icol]=(403*403);    % get the number of rows (N1) and columns (N2)
    temp=reshape('1.jpg',irow*icol,1);    % creates a (N1*N2)x1 vector
    S=[S temp];    % S is a N1*N2xM matrix after finishing the sequence
    end
     
     
    % Here we change the mean and std of all images. We normalize all images.
    % This is done to reduce the error due to lighting conditions and background.
    for i=1:size(S,2)
    temp=double(S(:,i));
    m=mean(temp);
    st=std(temp);
    S(:,i)=(temp-m)*ustd/st+um;
    end
     
    % show normalized images
    figure(2);
    for i=1:M
    str=strcat(int2str(i),'Koala.jpg');
    img=reshape(S(:,i),icol,irow);
    img=img';
    eval('imwrite(img,str)');
    subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
    imshow(img)
    drawnow;
    if i==3
    title('Normalized Training Set','fontsize',18)
    end
    end
     
     
    % mean image
    m=mean(S,2);  % obtains the mean of each row instead of each column
    tmimg=uint8(m); % converts to unsigned 8-bit integer. Values range from 0 to 255
    img=reshape(tmimg,icol,irow); % takes the N1*N2x1 vector and creates a N1xN2 matrix
    img=img';
    figure(3);
    imshow(img);
    title('Mean Image','fontsize',18)
     
    % Change image for manipulation
    dbx=['2.jpg'];    % A matrix
    for i=1:M
    temp=double(S(:,i));
    dbx=[dbx temp];
    end
     
    %Covariance matrix C=A'A, L=AA'
    A=dbx';
    L=A*A';
    % vv are the eigenvector for L
    % dd are the eigenvalue for both L=dbx'*dbx and C=dbx*dbx';
    [vv dd]=eig(L);
    % Sort and eliminate those whose eigenvalue is zero
    v=[];
    d=[];
    for i=1:size(vv,2)
    if(dd(i,i)>1e-4)
    v=[v vv(:,i)];
    d=[d dd(i,i)];
    end
    end
     
    %sort, will return an ascending sequence
    [B index]=sort(d);
    ind=zeros(size(index));
    dtemp=zeros(size(index));
    vtemp=zeros(size(v));
    len=length(index);
    for i=1:len
    dtemp(i)=B(len+1-i);
    ind(i)=len+1-index(i);
    vtemp(:,ind(i))=v(:,i);
    end
    d=dtemp;
    v=vtemp;
     
     
    %Normalization of eigenvectors
    for i=1:size(v,2) %access each column
    kk=v(:,i);
    temp=sqrt(sum(kk.^2));
    v(:,i)=v(:,i)./temp;
    end
     
    %Eigenvectors of C matrix
    u=[];
    for i=1:size(v,2)
    temp=sqrt(d(i));
    u=[u (dbx*v(:,i))./temp];
    end
     
    %Normalization of eigenvectors
    for i=1:size(u,2)
    kk=u(:,i);
    temp=sqrt(sum(kk.^2));
    u(:,i)=u(:,i)./temp;
    end
     
     
    % show eigenfaces
    figure(4);
    for i=1:size(u,2)
    img=reshape(u(:,i),icol,irow);
    img=img';
    img=histeq(img,255);
    subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
    imshow(img)
    drawnow;
    if i==3
    title('Eigenfaces','fontsize',18)
    end
    end
     
     
    % Find the weight of each face in the training set
    omega = [];
    for h=1:size(dbx,2)
    WW=[];
    for i=1:size(u,2)
    t = u(:,i)';
    WeightOfImage = dot(t,dbx(:,h)');
    WW = [WW; WeightOfImage];
    end
    omega = [omega WW];
    end
     
     
    % Acquire new image
    % Note: the input image must have a bmp or jpg extension.
    % It should have the same size as the ones in your training set.
    % It should be placed on your desktop 
    InputImage = input('Please enter the name of the image and its extension \n','s');
    InputImage = imread(strcat('D:\Documents and Settings\sis26\Desktop\',InputImage));
    figure(5)
    subplot(1,2,1)
    imshow(InputImage); colormap('gray');title('Input image','fontsize',18)
    InImage=reshape(double(InputImage)',irow*icol,1);
    temp=InImage;
    me=mean(temp);
    st=std(temp);
    temp=(temp-me)*ustd/st+um;
    NormImage = temp;
    Difference = temp-m;
     
    p = [];
    aa=size(u,2);
    for i = 1:aa
    pare = dot(NormImage,u(:,i));
    p = [p; pare];
    end
    ReshapedImage = m + u(:,1:aa)*p; %m is the mean image, u is the eigenvector
    ReshapedImage = reshape(ReshapedImage,icol,irow);
    ReshapedImage = ReshapedImage';
    %show the reconstructed image.
    subplot(1,2,2)
    imagesc(ReshapedImage); colormap('gray');
    title('Reconstructed image','fontsize',18)
     
    InImWeight = [];
    for i=1:size(u,2)
    t = u(:,i)';
    WeightOfInputImage = dot(t,Difference');
    InImWeight = [InImWeight; WeightOfInputImage];
    end
     
    ll = 1:M;
    figure(68)
    subplot(1,2,1)
    stem(ll,InImWeight)
    title('Weight of Input Face','fontsize',14)
     
    % Find Euclidean distance
    e=[];
    for i=1:size(omega,2)
    q = omega(:,i);
    DiffWeight = InImWeight-q;
    mag = norm(DiffWeight);
    e = [e mag];
    end
     
    kk = 1:size(e,2);
    subplot(1,2,2)
    stem(kk,e)
    title('Eucledian distance of input image','fontsize',14)
     
    MaximumValue=max(e)  % maximum eucledian distance
    MinimumValue=min(e)    % minimum eucledian distance

  2. #2
    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
    Points : 7 614
    Points
    7 614
    Par défaut
    Bonjour,

    la fonction imshow appartient à la toolbox Image Processing. Si tu n'as pas cette toolbox installée sur ton ordinateur, tu ne peux pas utiliser cette fonction.
    Comment connaitre la liste des Toolbox installées sur un ordinateur ?
    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.

  3. #3
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    effectivement je ne pense pas avoir cette fonction .
    Comment faire pour l'avoir ? est ce qu'on peut faire autrement ?
    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
    -------------------------------------------------------------------------------------------------------
    MATLAB Version: 8.1.0.604 (R2013a)
    MATLAB License Number: 840916
    Operating System: Microsoft Windows 7 Version 6.1 (Build 7600)
    Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
    -------------------------------------------------------------------------------------------------------
    MATLAB                                                Version 8.1        (R2013a)
    Simulink                                              Version 8.1        (R2013a)
    Control System Toolbox                                Version 9.5        (R2013a)
    Data Acquisition Toolbox                              Version 3.3        (R2013a)
    SimElectronics                                        Version 2.3        (R2013a)
    SimMechanics                                          Version 4.2        (R2013a)
    SimPowerSystems                                       Version 5.8        (R2013a)
    Simscape                                              Version 3.9        (R2013a)
    Simulink Control Design                               Version 3.7        (R2013a)
    Stateflow                                             Version 8.1        (R2013a)

  4. #4
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 163
    Points
    53 163
    Par défaut
    Le code dont tu t'inspires n'est pas très propre ni très robuste...
    Je chercherais une autre source à ta place.

    Sinon pour répondre à ta question, tu peux utiliser les fonctions image ou imagesc en fonction du type de couleur à afficher.
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

Discussions similaires

  1. Probleme avec Code::Blocks
    Par numerodix dans le forum Code::Blocks
    Réponses: 2
    Dernier message: 11/07/2008, 15h24
  2. probleme avec code::blocks !!
    Par kamnouz dans le forum Code::Blocks
    Réponses: 15
    Dernier message: 30/12/2007, 17h10
  3. Probleme avec code pour fond musical
    Par Yanout dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 05/09/2007, 17h12
  4. probleme avec code::blocks et sdl
    Par notour dans le forum SDL
    Réponses: 2
    Dernier message: 17/05/2007, 11h14
  5. [FPDF] Probleme avec code barre et fdpdf
    Par serwol dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 02/10/2006, 11h13

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