bonjour,
j'ai crée une interface graphiqu et qui affiche 280 images dicom sur un axe 1 puis je doit demander à l'utilisateur de sélectionner une image bien précise et cette image va être afficher sur un axe 2 le problème que je trouve pas l'image demandé sur l'axe 2 mais uniquement la 1ère image de la liste des images.
D'autre part je désir faire une segmentation manuelle de l'image sélectionné ,et puis afficher juste la prtie segmenté. j'ai crée un programme mais ça marche pas trop bien , j'ai réussi à faire le countouring mais j'arrive pas à afficher que la partie segmenté.
je vous donne mon code au dessous espérant que vous pourriez m'aide .
je vous remercie d'avance
1ère partie affichage des images sur l'axe 1
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
function Openimage_Callback(hObject, eventdata, handles)
% hObject    handle to Openimage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile('*.dcm','select dcm file');
 handles.gvar.path=PathName;
 path2=strcat(PathName,'Image 001');
  maxNumberOfImages = 280;
  I= dicomread(path2);
  info=dicominfo(path2);
  a=info.PatientName.FamilyName;
  b=info.PatientID;
  c=info.PatientBirthDate;
  d=info.StudyID;
  e=info.StudyDate;
  f=info.SliceLocation;
  g=info.InstanceNumber;
 
   set(handles.edit1,'string',num2str(a));
    set(handles.edit2,'string',num2str(b));
      set(handles.edit3,'string',num2str(c));
        set(handles.edit4,'string',num2str(d));
          set(handles.edit5,'string',num2str(e));
            set(handles.edit6,'string',num2str(f));
              set(handles.edit7,'string',num2str(g));
 
 axes(handles.axes1); 
 handles.axes1 = I;
 imshow(I,'DisplayRange',[]);
 guidata(hObject,handles)
 
 
 
function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (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 edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (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 edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 button press in Next.
%function Next_Callback(hObject, eventdata, handles)
% Create a slider to display the images
% slider = uicontrol('Style', 'slider',...
%     'Parent', f, 'String', 'Image No.',...
%     'Callback', @slider_callback, ...
%     'Position', [100 115 350 20]);
% set([f,Img1,Img2,hloadimages,hSelectFolder,htext,slider],'Units','normalized');
% 
% % Obtain directory or folder containing images 
%     myFolder = path2;
sliderMin = 1;
sliderMax = 280; % this is variable
sliderStep = [1, 1/(sliderMax - sliderMin)]; % major and minor steps of 1
 
set(handles.slider1, 'Min', 0);
set(handles.slider1, 'Max', 280);
set(handles.slider1, 'SliderStep', sliderStep);
set(handles.slider1, 'Value', 1); % set to beginning of sequence
%% Beginning of slider callback function
% --- Executes on slider movement.
 
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (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
    currentSlice = get(hObject, 'Value');
%     if(currentSlice <= 9 )
%     path2=strcat(handles.gvar.path,'Image 00',num2str(currentSlice))
%     
%     elseif (currentSlice >9 ) && (currentSlice <= 99 )
%     path2=strcat(handles.gvar.path,'Image 0',num2str(currentSlice))
%     
%     elseif (currentSlice >9 ) && (currentSlice > 99 )
%     path2=strcat(handles.gvar.path,'Image ',num2str(currentSlice));
%     end  
 path2 = fullfile(handles.gvar.path, sprintf('Image %03d', currentSlice));
 I= dicomread(path2);
  info=dicominfo(path2);
  a=info.PatientName.FamilyName;
  b=info.PatientID;
  c=info.PatientBirthDate;
  d=info.StudyID;
  e=info.StudyDate;
  f=info.SliceLocation;
  g=info.InstanceNumber;
 
   set(handles.edit1,'string',num2str(a));
    set(handles.edit2,'string',num2str(b));
      set(handles.edit3,'string',num2str(c));
        set(handles.edit4,'string',num2str(d));
          set(handles.edit5,'string',num2str(e));
            set(handles.edit6,'string',num2str(f));
              set(handles.edit7,'string',num2str(g));
 
 
 handles.axes1 = I;
 imshow(I,'DisplayRange',[]);
 
%     imagesc(imageArray(:,:,currentSlice), [1000 1150]);
%     colormap(gray); axis image; impixelinfo;
%     disp(['Slider moved to ' num2str(currentSlice)]);
 
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (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
2ème partie : sélection de l'image
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
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% [filename, pathname] = uigetfile('*.dcm', 'Open DICOM Image');% Open only DICOM image
% if isequal(filename, 0) || isequal(pathname, 0)   
%     disp('Image input canceled.');  
% else
% [h,MAP]=dicomread(fullfile(pathname, filename));
% info = dicominfo(fullfile(pathname, filename));
 
B = get(hObject, 'Value');
 c = fullfile(handles.gvar.path, sprintf('Image %03d', B));
A= dicomread(c);
 
axes(handles.axes4)
 imshow(A,'DisplayRange',[]);
3ème partie : Segmentation manuelle
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
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand();
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
xy = hFH.getPosition;
% Now make it smaller so we can show more images.
%subplot(2, 3, 1);
%axes(handles.axes1);
%imshow(a,'DisplayRange',[]);
%imshow(I,'DisplayRange',[]);
%axis on;
labeledImage = bwlabel(binaryImage);
measurements = regionprops(binaryImage, a, ...
    'area', 'Centroid', 'WeightedCentroid', 'Perimeter');
area = measurements.Area
centroid = measurements.Centroid
centerOfMass = measurements.WeightedCentroid
perimeter = measurements.Perimeter
% Calculate the area, in pixels, that they drew.
numberOfPixels1 = sum(binaryImage(:))
% Another way to calculate it that takes fractional pixels into account.
numberOfPixels2 = bwarea(binaryImage)
% Get coordinates of the boundary of the freehand drawn region.
structBoundaries = bwboundaries(binaryImage);
xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates.
x = xy(:, 2); % Columns.
y = xy(:, 1); % Rows.
%subplot(2, 3, 1); % Plot over original image.
hold on; % Don't blow away the image.
plot(x, y, 'LineWidth', 2);
drawnow; % Force it to draw immediately.
% Burn line into image by setting it to 255 wherever the mask is true.
burnedImage =grayImage;
burnedImage(binaryImage) = 255;
blackMaskedImage = grayImage;
blackMaskedImage(~binaryImage) = 0;
meanGL = mean(blackMaskedImage(binaryImage));
hold on;
%imshow(centroid(1), centroid(2), 'r+', 'MarkerSize', 30, 'LineWidth', 2);
%imshow(centerOfMass(1), centerOfMass(2), 'g+', 'MarkerSize', 20, 'LineWidth', 2);
insideMasked =grayImage;
insideMasked(binaryImage) = 0;
leftColumn = min(x);
rightColumn = max(x);
topLine = min(y);
bottomLine = max(y);
width = rightColumn - leftColumn + 1;
height = bottomLine - topLine + 1;
croppedImage = imcrop(blackMaskedImage, [leftColumn, topLine, width, height]);
% Display cropped image.
%subplot(2, 4, 6);
%imshow(I,[]);
axes(handles.axes1);
%imshow(a,'DisplayRange',[]);
%axes(handles.axes4)
imshow(croppedImage,'DisplayRange',[]);
axis on;
% title('Cropped Image', 'FontSize', fontSize);
% Put up crosses at the centriod and center of mass
%hold on;
%imshow(centroid(1)-leftColumn, centroid(2)-topLine, 'r+', 'MarkerSize', 30, 'LineWidth', 2);
imshow(centerOfMass(1)-leftColumn, centerOfMass(2)-topLine, 'g+', 'MarkerSize', 20, 'LineWidth', 2);
% Report results.
message = sprintf('Mean value within drawn area = %.3f\nNumber of pixels = %d\nArea in pixels = %.2f\nperimeter = %.2f\nCentroid at (x,y) = (%.1f, %.1f)\nCenter of Mass at (x,y) = (%.1f, %.1f)\nRed crosshairs at centroid.\nGreen crosshairs at center of mass.', ...
meanGL, numberOfPixels1, numberOfPixels2, perimeter, ...
centroid(1), centroid(2), centerOfMass(1), centerOfMass(2));
msgbox(message);