Bonjour,
J'ai un programme qui traite plusieurs images, en faisant une boucle for de 1 a n.
Pour chaque image, je crée un bouton que j'appelle flaw n.

Dans ma fonction callback, je fait aussi un petit traitement sur chacune des images.
Je ne sais pas comment faire pour faire correspondre tel bouton a telle image.

Je vous met mon code parce que c'est dur d'expliquer

Voici la fonction callback que je met au début du 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
function pushbutton (~, eventData, Is)
 
 
for i=1:n
 
    [x,y]=find(I2);
 
    I2(sub2ind(size(I2),x,y));
    m = zeros(size(I,1),size(I,2));
    m(x-10:x+10,y-10:y+10) = 1;
    seg = chenvese(I,m,1,0.1,'chan');
    seg2=imresize(seg,[441,690]);
    seg3= im2uint8(seg2);
    seg4=I;
    for i=1:441
        for j=1:690
            seg4=seg3;
        end
    end
    seg5 = cat(3,seg4,seg4,seg4);
    Is= (seg5/255).*I;
    % %center and zoom
    % x=x(1,1);
    % y=y(1,1);
    % Is = Is(x-100:x+100,y-100:y+100,:);
    % Is = imresize(Is,[441,690]);
    Is=imshow(Is);
    handles(1)=figure('units','pixels',...
        'position',[250 250 500 500],...
        'color',[0.925 0.913 0.687],...
        'numbertitle','off',...
        'name',['[GUI] flaw',num2str(n)],...
        'menubar','none',...
        'tag','Is');
    set(handles(1));
end
 
end
Voici le programme sans la fonction callback et allégé de certains détails pas important.
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
function [Is,x,y,I2]= proj2222(filename)
close all
figmain = figure
set( figmain , 'position' , [ 10, 10 ,4500 ,4500 ])
text1 = uicontrol( figmain , 'style' , 'text' , 'position' , [10,1000,170,30] ,...
    'string' , 'Hello' , 'fontsize' , 15 )
 
 
 
rep = 'C:\Thomas';
ext = '*.jpg';
 
chemin = fullfile(rep,ext);
 
list = dir(chemin);
 
n=numel(list);
 
for n = 1:numel(list)
 
    I = imread(fullfile(rep, list(n).name), ext(3:end));
 
    %position  of pushbutton
    if n<=20
        pos = [10 1000-(45*n) 60 30 ];
    elseif n>=21 && n<=40
        pos = [360 1000-(45*(n-20)) 60 30 ];
    elseif n>=41 && n<=60
        pos = [710 1000-(45*(n-40)) 60 30 ];
    elseif n>=61 && n<=80
        pos = [1060 1000-(45*(n-60)) 60 30 ];
    elseif n>=81
        pos = [1410 1000-(45*(n-80)) 60 30 ];
    end
 
    %unable button if no flaw
    if length(x)<1 || length(y)<1
 
        bpnf = uicontrol ( figmain , 'style' , 'push' , 'position' , pos,...
            'string' , 'no flaw' , 'callback' , 'plot(T,X)' );
        set(bpnf , 'enable' , 'off' )
 
        %ceate able pushbuton if there is flaw
    else
 
 
        %find the position and size of the flaw following x and y
        x( x>500 ) = []
        SizeX=x(1,1)-x(length(x),1);
        Posx=(x((length(x)/2),1)-20)*Sx/400;
 
        y( y>700 ) = []
        SizeY=y(1,1)-y(length(y),1);
        Posy=(y((length(y)/2),1)-21)*Sy1/638;
        Posy=Posy-(Sy1-Sy2);
 
 
        %Define position and print associate the text with the flaw size/position
        if n<=20
            pos2 = [100 1015-(45*n) 95 15 ];
        elseif n>=21 && n<=40
            pos2 = [450 1015-(45*(n-20)) 95 15 ];
        elseif n>=41 && n<=60
            pos2 = [800 1015-(45*(n-40)) 95 15 ];
        elseif n>=61 && n<=80
            pos2 = [1150 1015-(45*(n-60)) 95 15 ];
        elseif n>=81
            pos2 = [1500 1015-(45*(n-80)) 95 15 ];
        end
        if n<=20
            pos3 = [100 1000-(45*n) 95 15 ];
        elseif n>=21 && n<=40
            pos3 = [450 1000-(45*(n-20)) 95 15 ];
        elseif n>=41 && n<=60
            pos3 = [800 1000-(45*(n-40)) 95 15 ];
        elseif n>=61 && n<=80
            pos3 = [1150 1000-(45*(n-60)) 95 15 ];
        elseif n>=81
            pos3 = [1500 1000-(45*(n-80)) 95 15 ];
        end
        if n<=20
            pos4 = [200 1015-(45*n) 95 15 ];
        elseif n>=21 && n<=40
            pos4 = [550 1015-(45*(n-20)) 95 15 ];
        elseif n>=41 && n<=60
            pos4 = [900 1015-(45*(n-40)) 95 15 ];
        elseif n>=61 && n<=80
            pos4 = [1250 1015-(45*(n-60)) 95 15 ];
        elseif n>=81
            pos4 = [1600 1015-(45*(n-80)) 95 15 ];
        end
        if n<=20
            pos5 = [200 1000-(45*n) 95 15 ];
        elseif n>=21 && n<=40
            pos5 = [550 1000-(45*(n-20)) 95 15 ];
        elseif n>=41 && n<=60
            pos5 = [900 1000-(45*(n-40)) 95 15 ];
        elseif n>=61 && n<=80
            pos5 = [1250 1000-(45*(n-60)) 95 15 ];
        elseif n>=81
            pos5 = [1600 1000-(45*(n-80)) 95 15 ];
        end
        textn = uicontrol( figmain ,'style' , 'text' ,'position' , pos2 ,...
            'string' , ['Posx=',num2str(Posx),'mm'])
        text2n = uicontrol( figmain ,'style' , 'text' ,'position' , pos3 ,...
            'string' , ['Posy=',num2str(Posy),'mm'])
 
        text3n = uicontrol( figmain ,'style' , 'text' ,'position' , pos4 ,...
            'string' , ['sizeX=',num2str(SizeX),'mm'])
 
        text4n = uicontrol( figmain ,'style' , 'text' ,'position' , pos5 ,...
            'string' , ['sizeY=',num2str(SizeY),'mm'])
 
 
 
 
 
 
        handle.bpn=num2str(n);
        bpn = uicontrol ( figmain ,...
            'style' , 'push' ,...
            'position' , pos,...
            'string' , ['flaw',num2str(n)] ,...
            'callback' , @pushbutton );
 
        handle.bpn=num2str(n);
 
 
    end
end
 
 
 
 
 
 
end
Donc en fait ce que je cherche a faire, c'est détecter des défauts. Si il y en a je crée un bouton utilisable sinon je bloque le bouton.

Dans la fonction callback, je veux que en appuyant sur le bouton, il sélectionne la bonne image et lui applique un algorithme de segmentation trouver sur MathWorks pour afficher seulement le défaut.