Bonjour,
Je travaille sur les images DICOM et j'aimerais afficher une série d'image DICOM dans une interface graphique en Java.
Quelqu'un saurait-il m'indiquer comment faire ?
Merci d'avance pour votre aide.
Bonjour,
Je travaille sur les images DICOM et j'aimerais afficher une série d'image DICOM dans une interface graphique en Java.
Quelqu'un saurait-il m'indiquer comment faire ?
Merci d'avance pour votre aide.
Bonsoir
As tu travaillé sur quelque chose ?
Pour trouver plus facilement de l'aide, il serait plus pratique que tu nous fournisses un début de code et expliquer exactement où tu bloques![]()
Je débute avec un code en Java qui affiche un image jpg.
J'ai fais un fenêtre avec le code suivant :
J'ai fais ensuite un code qui permet de donner le chemin 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
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 public class Fenetre extends JFrame implements ActionListener { //les attributs de la classe private JPanel container = new JPanel(); private Thread t; private JMenuBar menuBar = new JMenuBar(); private JMenu fichier = new JMenu("Fichier"), edition = new JMenu("Edition"); private JMenuItem ouverture = new JMenuItem("ouvrire une image"), quitter = new JMenuItem("Quitter"), editionItem = new JMenuItem("saveAS"); private image pan; String path; // la constructeure public Fenetre() { this.setTitle("notre interface"); this.setSize(600, 600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); container.setBackground(Color.blue); container.setLayout(new BorderLayout()); this.initMenu(); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //this.setContentPane(new image()); this.setVisible(true); } private void initMenu() { //Menu animation fichier.add(ouverture); fichier.addSeparator(); //Pour quitter l'application quitter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event){ System.exit(0); } }); fichier.add(quitter); //Menu forme ouverture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //try{ JFileChooser dialogue=new JFileChooser(new File("D:")); //PrintWriter sortie; File file; if (dialogue.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { file=dialogue.getSelectedFile(); //sortie=new PrintWriter(new FileWriter(file.getPath(),true)); //sortie.close(); path=file.getPath(); System.out.println(path); pan=new image(path); } //}catch(IOException e){}; }}); fichier.add(fichier); this.setJMenuBar(menuBar); //Menu À propos edition.add(editionItem); //Ajout des menus dans la barre de menus menuBar.add(fichier); menuBar.add(edition); //Ajout de la barre de menus sur la fenêtre this.setJMenuBar(menuBar); } }
Ensuite j'ai fais un appel de ma fenêtre dans la classe main :
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 public class image extends JPanel { String path; Graphics gra; Point p=new Point(1,1); image (String path) { this.path=path; this.paintComponent(gra); } public void paintComponent(Graphics g){ try { Image img = ImageIO.read(new File(path)); g.drawImage(img,1,1,this); System.out.println(path); //Pour une image de fond //g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); } catch (IOException e) { e.printStackTrace(); } } }mais je n'arrive pas à afficher mon 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 public class main { public static void main(String[]args){ Fenetre fen=new Fenetre(); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (InstantiationException e) { } catch (ClassNotFoundException e) { } catch (UnsupportedLookAndFeelException e) { } catch (IllegalAccessException e) {} Fenetre fene = new Fenetre(); } }
Merci à vous.
Voici ton code quelque peu modifié pour afficher ton image:
La classe Main
La classe 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
18
19 import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class Main { public static void main(String[]args){ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(InstantiationException e) {} catch(ClassNotFoundException e) {} catch(UnsupportedLookAndFeelException e) {} catch(IllegalAccessException e) {} Fenetre fene = new Fenetre(); } }
La classe Fenetre
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 public class image extends JPanel { //par convention, les noms de classes commencent //toujours par une majuscule String path= "MB.jpg"; //Graphics gra; je ne vois pas son utilité Point p=new Point(1,1); public image() { this.path="MB.jpg"; //initialise ton panel avec une image //je te laisse le soin de choisir l'image //et de mettre le chemin à la place de "MB.jpg" //this.paintComponent(gra); gra non initialisé, tu obtiens une exception, a enlever } public void paintComponent(Graphics g) { try { Image img = ImageIO.read(new File(path)); g.drawImage(img, 0, 0, null); //Pour une image de fond //g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); } catch(IOException e) {} } }
Voila, j'ai travaillé à partir de ton code, c'est commenté, si tu ne comprends pas quelque chose n'hésite pas à revenir
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 public class Fenetre extends JFrame { //les attributs de la classe private JPanel container = new JPanel(); private Thread t; private JMenuBar menuBar = new JMenuBar(); private JMenu fichier = new JMenu("Fichier"), edition = new JMenu("Edition"); private JMenuItem ouverture = new JMenuItem("ouvrire une image"), quitter = new JMenuItem("Quitter"), editionItem = new JMenuItem("saveAS"); private image pan= new image(); String path; // le constructeur public Fenetre() { this.setTitle("notre interface"); this.setSize(600, 600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.initMenu(); this.setContentPane(pan); //ajoute ton objet image this.setVisible(true); } private void initMenu() { //Menu animation ouverture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //try{ JFileChooser dialogue=new JFileChooser(new File("D:")); //PrintWriter sortie; File file; if(dialogue.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { file=dialogue.getSelectedFile(); //sortie=new PrintWriter(new FileWriter(file.getPath(),true)); //sortie.close(); path=file.getAbsolutePath(); //obtenir le chemin complet (absolue) de l'image System.out.println(path); pan.path= path; //modifie le path de image pan.repaint(); //redessine le composant } //}catch(IOException e){}; } }); fichier.add(ouverture); fichier.addSeparator(); //Pour quitter l'application quitter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event){ System.exit(0); } }); fichier.add(quitter); //Menu forme fichier.add(fichier); //Menu À propos edition.add(editionItem); //Ajout des menus dans la barre de menus menuBar.add(fichier); menuBar.add(edition); //Ajout de la barre de menus sur la fenêtre this.setJMenuBar(menuBar); } }
EDIT: pour this.path="MB.jpg"; n'oublie pas de modifier avec ton image et de la copier à la racine de ton projet, avant de tester ce code, sinon tu auras une exception !
Bonjour,
J'aimerais afficher le nombre des images dans une série d'image DICOM et le nombre des examens dans une série d'examens, mais je ne connais pas le champ qui permet de visualiser combien des images dans une série.
Quelqu'un saurait-il m'indiquer comment faire ?
Merci d'avance
Navrée je n'ai pas vraiment compris ton problème.
Aussi, quand tu as un souci il vaut mieux poster le code dans lequel tu bloques et surtout n'oubli pas d'utiliser les balises CODE (à savoir le # là où tu rédiges tes messages)
Mon problème est que je ne connais pas le champs qui permet de visualiser combien d'image DICOM dans une série d'images DICOM...
Bonjour,
Je souhaite lire un fichier DICOM et en même temps, j'aimerais calculer le nombre de fichiers qu'il contient, puis l'afficher.
Voici mon code :
Merci d'avance pour votre aide.
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 import java.io.File; public class DiskFileExplorer { private String initialpath = ""; private Boolean recursivePath = false; public int filecount = 0; //public int dircount = 0; /* * Constructeur * @param path chemin du répertoire * @param subFolder analyse des sous dossiers */ public DiskFileExplorer(String path, Boolean subFolder) { super(); this.initialpath = path; this.recursivePath = subFolder; } public void list() { this.listDirectory(this.initialpath); } private void listDirectory(String dir) { File file = new File(dir); File[] files = file.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory() == true) { // System.out.println("Dossier" + files[i].getAbsolutePath()); // this.dircount++; } else { System.out.println("Fichier" + files[i].getName()); this.filecount++; } if (files[i].isDirectory() == true && this.recursivePath == true) { this.listDirectory(files[i].getAbsolutePath()); } } } } /* * Exemple : lister les fichiers dans tous les sous-dossiers * @param args */ public static void main(String[] args) { String pathToExplore = "C:\\Users\\dell\\Desktop\\projet\\WRIX\\WRIX\\WRIX\\WRIST RIGHT\\SCOUT 3-PLANE RT. - 2"; DiskFileExplorer diskFileExplorer = new DiskFileExplorer(pathToExplore, true); Long start = System.currentTimeMillis(); diskFileExplorer.list(); System.out.println("----------"); System.out.println("Analyse de " + pathToExplore + " en " + (System.currentTimeMillis() - start) + " mses"); // System.out.println(diskFileExplorer.dircount + " dossiers"); System.out.println(diskFileExplorer.filecount + " fichiers"); } }
Bonjour
J'ai testé ton code, il marche bien je ne vois pas où est le problème ?
Bonsoir,
J’ai deux classes qui permettent de lire une image DICOM et de lire les informations de l'entête de cette image.
A partir d'elles j'aimerais calculer le nombre d'images dans une série d'image (fichier.dcm) mais je ne sais pas quel est le champ exacte à partir les champs qui existent dans l’entête qui permet de faire cette calcule .
merci d'avance.
code de la classe lecture image:
code de la classe lecture_entete:
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 public class lecture_image extends lecture_entete { int w, h , highBit, n ; // highBit is for littleEndian boolean signed ; final static boolean DEBUG = false ; boolean ignoreNegValues ; int bitsStored, bitsAllocated ; int samplesPerPixel ; int numberOfFrames ; byte[] pixData; String filename ; lecture_entete tete; private File file; public lecture_image( lecture_entete tete )throws java.io.IOException { // called by :ImageScan this.tete = tete ; h = tete.getRows() ; w = tete.getColumns() ; highBit = tete.getHighBit() ; bitsStored = tete.getBitStored() ; bitsAllocated =tete.getBitAllocated(); n = (bitsAllocated/8) ;// = 1 or 2 signed = (tete.getPixelRepresentation() == 1) ; this.pixData = tete.getPixels();// It throws the exception . ignoreNegValues = true ;// How do you know when ? samplesPerPixel = tete.getSamplesPerPixel() ; numberOfFrames = tete.getNumberOfFrames() ; System.out.println("Number of Frames " + numberOfFrames) ; }// endofConstructor public lecture_image(byte[] array )throws java.io.IOException { this(new lecture_entete ()); } public lecture_image(File file) throws IOException { this.setFile(file) ; h = tete.getRows() ; w = tete.getColumns() ; highBit = tete.getHighBit() ; bitsStored = tete.getBitStored() ; bitsAllocated =tete.getBitAllocated(); n = (bitsAllocated/8) ;// = 1 or 2 signed = (tete.getPixelRepresentation() == 1) ; this.pixData = tete.getPixels();// It throws the exception . ignoreNegValues = true ;// How do you know when ? samplesPerPixel = tete.getSamplesPerPixel() ; numberOfFrames = tete.getNumberOfFrames() ; System.out.println("Number of Frames " + numberOfFrames) ; } public File getFile() { return file; } public void setFile(File file) { this.file = file; }
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473 public class lecture_entete { byte[] data ; int index ; private int dataLength; private int bytesFromTagToValue ;// depends on the VR public static final int MAX_HEADER_SIZE = 10000 ; private int maxHeaderSize ; public static final String ImplicitVRLittleEndian = "1.2.840.10008.1.2" ; public static final String ExplicitVRLittleEndian = "1.2.840.10008.1.2.1" ; public static final String ExplicitVRBigEndian = "1.2.840.10008.1.2.2" ; public static final String JPEGCompression = "1.2.840.10008.1.2.4." ; public static final String RLECompression = "1.2.840.10008.1.2.5" ; public static final int _ImplicitVRLittleEndian = 0 ; // if the VR is explicit : the tag is > 0 public static final int _ExplicitVRLittleEndian = 1 ; public static final int _ExplicitVRBigEndian = 2 ; public static final int _ImplicitVRBigEndian = -2 ; //this one should not exists ! public static final int _JPEGCompression = 10 ; public static final int _RLECompression = 20 ; public static final int _notUnderstood = -1000 ; private boolean oneSamplePerPixel = true ; private boolean oneFramePerFile = true ; private int errorDetector = -1 ; private String VRString = "default implicitVR little endian"; private String transfertSyntaxUID = "" ;// 0x0002,0x0010 private String imageType = "unknown" ;// 0x0008,0x0008 private String examendate = "unknown" ;// 0x0008,0x0030 private String modality = "unknown" ;// 0x0008,0x0060 private String manufacturer = "unknown" ;// 0x0008,0x0070 private String institution = "unknown" ;// 0x0008,0x0080 private String physician = "unknown" ;// 0x0008,0x0090 private String patientName = "unknown" ;// 0x0010,0x0010 private String patientID = "unknown" ;// 0x0010,0x0020 private String patientBirthdate= "unknown" ;// 0x0010,0x0030 private String sex = "unknown" ;// 0x0010,0x0040 private int numberOfFrames = 1; // 0x0028,0x0008 //IS : integer string private int samplesPerPixel = 1; // 0x0028,0x0002 private int h = -1; // 0x0028,0x0010 private int w = -1; // 0x0028, 0x0011 private int bitsAllocated = -1; // 0x0028, 0x0100 private int bitsStored = -1; // 0x0028, 0x0101 private int highBit = -1; // 0x0028, 0x0102 private int signed = -1; // 0x0028, 0x0103(pixelRepresentation ) private int size = -1; // 0x7Fe0, 0x0010 private int VR = _ImplicitVRLittleEndian; //=0, default value representation public void lecture_entete ( byte [] dicomArray ) { this.data = dicomArray ; dataLength = data.length ; index =0; initHeaderSize() ;// Just read the begining of this file getVR();// Look for the VR getEssentialData() ; } protected void initHeaderSize(){ maxHeaderSize = MAX_HEADER_SIZE * 1 ;// increase the speed on non Dicom Files. if(maxHeaderSize > dataLength) maxHeaderSize = dataLength ; } protected void getVR(){ transfertSyntaxUID = getaString (0x0002,0x0010, index); if(!transfertSyntaxUID.equals("Unknown") ){ transfertSyntaxUID = transfertSyntaxUID.trim() ; if(transfertSyntaxUID.equals(ImplicitVRLittleEndian)) VR =_ImplicitVRLittleEndian ; else if(transfertSyntaxUID.equals(ExplicitVRLittleEndian)) VR =_ExplicitVRLittleEndian ; else if(transfertSyntaxUID.equals(ExplicitVRBigEndian)) VR =_ExplicitVRBigEndian ; else if(transfertSyntaxUID.startsWith(JPEGCompression)) VR =_JPEGCompression ; else if(transfertSyntaxUID.startsWith(RLECompression)) VR =_RLECompression ; else VR = _notUnderstood ; switch (VR){ case _ImplicitVRLittleEndian : VRString = "ImplicitVRLittleEndian";break; case _ExplicitVRLittleEndian : VRString = "ExplicitVRLittleEndian";break; case _ExplicitVRBigEndian : VRString = "ExplicitVRBigEndian";break; case _JPEGCompression : VRString = "JPEGCompression";break; case _RLECompression : VRString = "RLECompression" ;break; case _notUnderstood : VRString = "not understood" ;break; default : VRString =" Something curious happened !" ; }// end of switch }else if(transfertSyntaxUID.equals("Unknown")){ //end if !Unknown transfertSyntaxUID = "Transfer syntax UID tag not found"; VRString = "Default VR implicit little endian"; }//end else }//endOfgetVR protected void getEssentialData(){ imageType = getaString (0x0008,0x0008,index); examendate = getaString (0x0008,0x0020,index); modality = getaString (0x0008,0x0060,index); manufacturer = getaString (0x0008,0x0070,index); institution = getaString (0x0008,0x0080,index); physician = getaString (0x0008,0x0090,index); patientName = getaString (0x0010,0x0010,index); patientID = getaString (0x0010,0x0020,index); patientBirthdate= getaString(0x0010,0x0030,index); sex = getaString (0x0010,0x0040,index); //Sample per pixel and number of frame h = getAnInt(0x0028, 0x0010, index ) ;// heigth w = getAnInt(0x0028, 0x0011, index ) ; // width bitsAllocated = getAnInt(0x0028, 0x0100, index ) ; bitsStored = getAnInt(0x0028, 0x0101, index ) ; highBit = getAnInt(0x0028, 0x0102, index ) ; signed = getAnInt(0x0028, 0x0103, index ) ;//(pixelRepresentation ) //-----------------debugging info:----------------------------- System.out.println( "TransfertSyntaxUID : " + transfertSyntaxUID ) ; System.out.println( "Value representation : " + VRString ) ; System.out.println( "ImageType " + imageType ) ; System.out.println( " h ::: " + h ) ; System.out.println( " w ::: " + w ) ; System.out.println( " bitsAllocated ::: " + bitsAllocated ) ; System.out.println( " bitsStored ::: " + bitsStored ) ; System.out.println( " highBit ::: " + highBit ) ; System.out.println( " signed ::: " + signed ) ; int pos = lookForMessagePosition( 0x7Fe0, 0x0010, index); if( pos != -1 ) size = readMessageLength(pos+4) ; //We should include the case where value length is undef 0xFFFFFFFF System.out.println( "\nValueLength for 0x7FEO,0010 tag " + size ) ; int HeaderSize = pos ; // We call header all the information before the pixels System.out.println( "\nHeaderSize : " + HeaderSize ) ; int tSize = samplesPerPixel * w*h*bitsAllocated/8 ;// theoritical Size int figuredSize = HeaderSize + 8 + tSize ; errorDetector = dataLength - figuredSize ; System.out.println( "Data Length - Theoriticaly_figuredSize : "+ errorDetector ) ; if(errorDetector == 4 ){ size = readMessageLength(pos+8) ; // try explicit VRString errorDetector = dataLength - size ; } if( errorDetector != 0){ //see what's wrong : //1 more than one sample per pixel : samplesPerPixel = getAnInt(0x0028, 0x0002) ;// not mandatory ? if(samplesPerPixel <0 || samplesPerPixel> 3 ){ samplesPerPixel = 1 ;// default value System.out.println( " SamplesPerPixel ::: " + samplesPerPixel ) ; } else if (samplesPerPixel == 1) oneSamplePerPixel = true ; // else oneSamplePerPixel = false ; //2 more than one Frame : try{numberOfFrames = Integer.parseInt(getaString(0x0028,0x0008)) ; } catch(NumberFormatException nFE){ numberOfFrames = 1 ;} if (numberOfFrames > 1 ) oneFramePerFile = false ; tSize = numberOfFrames * tSize * samplesPerPixel; figuredSize = HeaderSize + 8 + tSize ; errorDetector = dataLength - figuredSize ; //3 other cases : if (VR == _JPEGCompression) System.out.println( "_JPEGCompression , can't read that file" ) ; if (VR == _RLECompression) System.out.println( " RLECompression , can't read that file" ) ; System.out.println( "Byte difference between figured sized and size tag: " + errorDetector +"\n Frame per file " + numberOfFrames +"\n samplesPerPixel " + samplesPerPixel) ; } }// ENDOF getEssentialData() private int lookForMessagePosition(int groupElement, int dataElement ){ return lookForMessagePosition(groupElement, dataElement, 0 ); } private int lookForMessagePosition(int groupElement, int dataElement, int j ){ int LenMax = data.length -3; // -3 because we don't want to have an arrayOutOfBounds exception boolean found = false ; byte testByte1 = (byte) (groupElement & 0xff); byte testByte2 = (byte) ((groupElement & 0xff00)>>8); byte testByte3 = (byte) (dataElement & 0xff); byte testByte4 = (byte) ((dataElement & 0xff00)>> 8); System.out.println(" Looking for :"+ Integer.toHexString(testByte1) +Integer.toHexString(testByte2)+", " +Integer.toHexString(testByte3) +Integer.toHexString(testByte4)); for ( ; j< LenMax || found ; j++){ if( ( data[j] == testByte1 ) && (data[j+1] == testByte2) && (data[j+2]== testByte3) && (data[j+3]== testByte4)){ found = true ; return j ; }//endif } return -1 ; }//endOfmethod lookForMessagePosition private int readMessageLength(int i){ int i0 = (int) (data[i ] &0xff); int i1 = (int) (data[i + 1 ] &0xff); int i2 = (int) (data[i + 2 ] &0xff); int i3 = (int) (data[i + 3 ] &0xff); return i3<<24| i2<<16 |i1<< 8|i0 ; } private int readVRMessageLength(int tagPos){ if(VR == _ImplicitVRLittleEndian ){ bytesFromTagToValue = 8 ; return readInt32(tagPos + 4 ) ; } // case explicit VR with of OB OW SQ or UN String VRTypeOf = new String(new byte[]{data[tagPos+4],data[tagPos+5]}); System.out.println ("VR type of : "+ VRTypeOf ); if( VRTypeOf.equals("OB")| VRTypeOf.equals("OW")| VRTypeOf.equals("SQ")| VRTypeOf.equals("UN")){ bytesFromTagToValue = 12; return readInt32(tagPos + 8 ); } // case explicit VR with value other than OB OW SQ or UN else{ bytesFromTagToValue = 8 ; return readInt16(tagPos + 6 ) ; } } private int readInt32(int i) { //= return readMessageLength(i);//same method ! int i0 = (int) (data[i ] &0xff); int i1 = (int) (data[i + 1 ] &0xff); int i2 = (int) (data[i + 2 ] &0xff); int i3 = (int) (data[i + 3 ] &0xff); return i3<<24| i2<<16 |i1<< 8|i0 ; } private int readInt16( int i ){ int i1 = data[i+1]&0xff ; int i0 = data[i]&0xff ; int anInt = i1<<8|i0 ; //case BE swap bytes : if (anInt < -1){ anInt= (int)(data[i]*256)&0xff + data[i+1]&0xff ; System.out.println("Byte swapped at readInt16 :" + anInt) ; } return anInt ; } public int getAnInt(int groupElement, int dataElement){ return getAnInt( groupElement, dataElement, 0); }//endofMethod private int getAnInt(int groupElement, int dataElement, int j){ int pos = lookForMessagePosition( groupElement, dataElement, j); if(pos < maxHeaderSize && pos != -1 ){ index = pos ; if (readVRMessageLength(pos) == 2 ) return readInt16( pos + bytesFromTagToValue ); else if(readVRMessageLength(pos) == 4 ) return readInt32(pos + bytesFromTagToValue ); else return -1; // case undef FFFF for later! }//end if else return -1 ; } public int getSize() { return dataLength;} public int getNumberOfFrames(){ return numberOfFrames ;} public int getSamplesPerPixels() { return samplesPerPixel ;} public int getPixelDataSize(){ if (errorDetector == 0 )return size ; else return -1 ; } /*The height : */ public int getRows() {return h ;} /* The width :*/ public int getColumns(){ return w;} /* The bits Allocated per pixel of image */ public int getBitAllocated(){return bitsAllocated;} /* the bits stored per pixel of image */ public int getBitStored(){return bitsStored;} /* Other values : */ public int getHighBit(){return highBit;} public int getSamplesPerPixel(){return samplesPerPixel;} public int getPixelRepresentation(){return signed;} public String getPatientName() {return patientName; } public String getPatientBirthdate() { return patientBirthdate; } public String getManufacturer() {return manufacturer ; } public String getPatientID() {return patientID ; } public String getImageType() { return imageType; } public String getexamendate() { return examendate; } public String getModality() { return modality; } /* Retrieves a String when you knows the tags */ public String getaString(int groupNumber, int elementNumber){ return getaString( groupNumber, elementNumber, 0) ; } private String getaString(int groupNumber, int elementNumber, int j ){ int pos = lookForMessagePosition(groupNumber,elementNumber,j); //debug( "Position = " + pos+ " of " + tools.Tools.toHex(groupNumber ) +" "+ tools.Tools.toHex(elementNumber) ); if(pos < MAX_HEADER_SIZE && pos != -1 ){ int length = readMessageLength(pos+4); if (length >256)length = readInt16( pos + 6 ); if (length > 64 || length < 0 ) length = 64 ; if (length > (dataLength - pos-8)) length = dataLength -pos -9 ; index = pos ; pos += 8; char[] result = new char[length ]; for (int i = 0; i < length ;i++) result[i] = (char)data[pos++]; return new String( result ); } else return "Unknown" ; } public int getFileDataLength(){ int pos = lookForMessagePosition( 0x7Fe0, 0x0010); if ( pos != -1) return readMessageLength(pos+4) ; else return -1 ; } /* * * This method return the pixels of the Dicom image ( yes !) provided it is not compressed and this is a known * Dicom format, else it return null (please check for a null condition or an index array out of bounds exception). * */ public byte[] getPixels() throws IOException{ if (VR == _JPEGCompression ) throw new IOException("DICOM JPEG compression not yet supported ") ; int w = getRows() ; if ( w == -1){ throw new IOException("Format not recognized") ; //return null ; } int h = getColumns(); if( h == -1) throw new IOException("Format not recognized") ; int ba = getBitAllocated(); if( ba%8 == 0) { ba = ba/8 ;} else ba = (ba+8)/8 ; int fileLength = w * h * ba ; int offset = dataLength - fileLength ; ///!!! bizarre this is for elscint !!! // should be this one : //int pos = lookForMessagePosition( 0x7Fe0, 0x0010) + 8; // if(VR == _ExplicitVRLittleEndian || VR == _ExplicitVRBigEndian ) // offset += 4 ; byte[] pixData = new byte[ fileLength ]; java.lang.System.arraycopy (data, offset, pixData,0, fileLength ); return pixData ; } public byte[] getPixels(int number) throws IOException{ if( number > numberOfFrames ) throw new IOException( "Doesn't have such a frame ! ") ; if (VR == _JPEGCompression ) throw new IOException("DICOM JPEG compression not yet supported ") ; int w = getRows() ; if ( w == -1){ throw new IOException("Format not recognized") ; //return null ; } int h = getColumns(); if( h == -1) throw new IOException("Format not recognized") ; int ba = getBitAllocated(); if( ba%8 == 0) { ba = ba/8 ;} else ba = (ba+8)/8 ; int fileLength = w * h * ba ; int offset = dataLength - (fileLength * number); ///!!! bizarre this is for elscint !!! // should be this one : //int pos = lookForMessagePosition( 0x7Fe0, 0x0010) + 8; byte[] pixData = new byte[ fileLength ]; java.lang.System.arraycopy (data, offset, pixData,0, fileLength ); return pixData ; } public String[] getInfo(){ String [] info = new String[16]; info[0] = "Patient 's name : " + getPatientName(); info[1] = "Patient 's ID : " + getPatientID(); info[2] = "Patient 's birthdate : " + getPatientBirthdate(); info[3] = "Patient 's sex : " + sex; info[4] = "Study Date : " + getexamendate(); info[5] = "Modality : " + getModality(); info[6] = "Manufacturer : " + getManufacturer(); info[7] = "Number of frames : " + getNumberOfFrames(); info[8] = "Width : " + getColumns(); info[9] = "Height : " + getRows(); info[10] = "Bits allocated : " + getBitAllocated(); info[11] = "Bits stored : " + getBitStored(); info[12] = "Sample per pixels : " + getSamplesPerPixel(); info[13] = "Physician : " + physician; info[14] = "Institution : " + institution; info[15] = "Transfert syntax UID : " + transfertSyntaxUID ; return info ; } public Hashtable getMedicalInfos() { Hashtable table = new Hashtable(8); table.put("patient.name",getPatientName()); table.put("patient.id",getPatientID()); table.put("patient.birthdate",getPatientBirthdate()); table.put("sex",sex); table.put("study.date",getexamendate()); table.put("physician",physician); table.put("institution",institution); table.put("transfert.syntax.uid",transfertSyntaxUID); return table; } protected final static String author(){ return ("Serge Derhy") ; } }
Bonsoir
est ce que tu crées une instance de lecture_image
pour chaque image que tu dois lire ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part lecture_image lect_img= new lecture_image(...);
est censé faire quoi ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part tete.getNumberOfFrames()
(Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)
N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
salut,
numberOfFrames c'est un attribut de la classe lecture_entete.
Et tete.getNumberOfFrames() sert à retourner cet attribut puisque la classe lecture_image hérite de la classe lecture_entete.
salut,
J'ai une interface et je veux l'ajouter un JList d'image. Je veux arriver à afficher la liste d'image à gauche et quand je clique sur l'une de ces images , elle s'affiche à coté d'elle.
voici mon code:
mais malheureusement j'arrive pas à afficher la liste d'image quand je sélectionne un fichier.Je ne sais pas quelle est la problème exactement.
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 import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.*; import java.io.*; import java.util.Vector; import javax.imageio.*; import javax.swing.event.*; public class Choix2 extends JFrame { private JMenuBar menuBar = new JMenuBar(); private JMenu fichier = new JMenu("Fichier"),edition = new JMenu("Edition"); private JMenuItem ouverture = new JMenuItem("ouvrire une image"),quitter = new JMenuItem("Quitter"),editionItem = new JMenuItem("saveAS"); private String base = "C:/Users/dell/Desktop/."; private ListePhotos photos = new ListePhotos(); private Photo photo = new Photo(); //Constructeur public Choix2() { super("Visionneuse"); this.initMenu(); //this.setContentPane(photos); add(new JScrollPane(photos), BorderLayout.WEST); add(new JScrollPane(photo),BorderLayout.EAST); setSize(600, 600); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } private void initMenu() { //Menu animation fichier.add(ouverture); fichier.addSeparator(); //Pour quitter l'application quitter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event){ System.exit(0); } }); fichier.add(quitter); //Menu forme ouverture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //try{ JFileChooser dialogue=new JFileChooser(); dialogue.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES) ; int retour = dialogue.showOpenDialog(Choix2.this); if(retour == JFileChooser.APPROVE_OPTION) { File fichier = dialogue.getSelectedFile(); String Path=dialogue.getCurrentDirectory().getName(); } System.out.println(base); photos.path= base; //modifie le path de image photos.repaint(); //}catch(IOException e){}; }); fichier.add(fichier); this.setJMenuBar(menuBar); //Menu À propos edition.add(editionItem); //Ajout des menus dans la barre de menus menuBar.add(fichier); menuBar.add(edition); //Ajout de la barre de menus sur la fenêtre this.setJMenuBar(menuBar); } //la classe ListePhotos private class ListePhotos extends JList implements ListSelectionListener { protected String path; private Vector<String> noms = new Vector<String>(); private final int largeur = 170; //Constructeur de la classe ListePhotos public ListePhotos() { setBackground(Color.black); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setCellRenderer(new Rendu()); setFixedCellWidth(largeur+20); setFixedCellHeight(largeur*3/4+30); setLayoutOrientation(JList.VERTICAL); setVisibleRowCount(1); addListSelectionListener(this); change(); } public void change() { setTitle(base); File[] fichiers = new File(base).listFiles(new Filtre()); noms.clear(); for (File fichier : fichiers) { noms.add(fichier.getName()); } setListData(noms); setSelectedIndex(0); Choix2.this.validate(); } public void valueChanged(ListSelectionEvent e) { String nom = (String)getSelectedValue(); if (nom != null) { try { photo.change(new ImageIcon(base+'/'+nom).getImage()); } catch (IOException e1) { e1.printStackTrace(); } } } private class Filtre implements FilenameFilter { public boolean accept(File rep, String nom) { return nom.matches(".+jpg"); } } //La classe Rendu private class Rendu extends JComponent implements ListCellRenderer { private Image photo = null; public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { photo = new ImageIcon(base+'/'+(String)value).getImage(); return this; } @Override protected void paintComponent(Graphics g) { if (photo != null) { int hauteur = (int)(largeur * photo.getHeight(null) / (double)photo.getWidth(null)); g.drawImage(photo, 10, 3, largeur, hauteur, null); } } } } //La classe Photo private class Photo extends JComponent { private Image photo = null; Point p=new Point(1,1); Graphics g; String path; public void change(Image photo) throws IOException { this.path=base; this.paintComponent(g); Image img = ImageIO.read(new File(path)); g.drawImage(img,1,1,(ImageObserver) this); System.out.println(path); repaint(); } @Override protected void paintComponent(Graphics g) { if (photo != null) { int largeur = getWidth(); int hauteur = (int)(largeur * photo.getHeight(null) / (double)photo.getWidth(null)); g.drawImage(photo, 0, 0, largeur, hauteur, null); } } } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(InstantiationException e) {} catch(ClassNotFoundException e) {} catch(UnsupportedLookAndFeelException e) {} catch(IllegalAccessException e) {} new Choix2(); } }
J'ai très besoin de vos aides.
Merci d'avance.
Partager