annotate Sphinx/source/faq/matlab.rst @ 374:f5bbdabb04d9

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 05 Apr 2020 10:25:51 +0200
parents 011b01ccf52d
children 1316bc62b5d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
86e92d0cc53e information about images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 103
diff changeset
1 .. _matlab:
86e92d0cc53e information about images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 103
diff changeset
2
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 Interfacing with Matlab and Octave
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 ==================================
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 Thanks to the REST API of Orthanc, it is easy to access DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 from Matlab or Octave, as depicted in the following sample image:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 .. image:: ../images/Matlab.png
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 :align: center
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 :width: 470px
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 Both Matlab and Octave have access to HTTP servers thanks to their
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 built-in `urlread() function
358
011b01ccf52d fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 168
diff changeset
15 <https://nl.mathworks.com/help/matlab/ref/urlread.html>`__. Once must
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 simply install a Matlab/Octave library to decode JSON files. The
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
17 `JSONLab toolkit <https://github.com/fangq/jsonlab>`__ works perfectly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
18 to this end.
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 .. highlight:: matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 Using JSONlab, the following code will download and display a DICOM image::
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 SERIES = 'ae164c84-e5bd0366-ba937a6d-65414092-f294d6b6';
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
25 URL = 'http://demo.orthanc-server.com/';
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # Get information about the instances in this DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 instances = loadjson(urlread([ URL '/series/' SERIES '/instances' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 # Select one slice from the series
102
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
31 instance = instances{1}.ID
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # Decode the slice with Orthanc thanks to the "/matlab" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 slice = eval(urlread([ URL '/instances/' instance '/matlab' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 # Compute the maximum value in this slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 max(max(slice))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 # Display the slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 imagesc(slice)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 # Annotate the graph with the patient name and ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 tags = loadjson(urlread([ URL '/instances/' instance '/tags?simplify' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 title([ 'This is a slice from patient ' tags.PatientID ' (' tags.PatientName ')' ])
103
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
45
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
46
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
47 Opening the raw DICOM file
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
48 --------------------------
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
49
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
50 Here is another sample Matlab/Octave script explaining how to download
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
51 the raw DICOM file corresponding to one given instance stored in
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
52 Orthanc, then decode this DICOM file using Matlab/Octave::
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
53
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
54 SERIES = 'ae164c84-e5bd0366-ba937a6d-65414092-f294d6b6';
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
55 URL = 'http://demo.orthanc-server.com/';
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
56
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
57 # Get information about the instances in this DICOM series
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
58 instances = loadjson(urlread([ URL '/series/' SERIES '/instances' ]));
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
59
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
60 # Select one slice from the series
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
61 instance = instances{1}.ID
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
62
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
63 # Download the raw DICOM file and store it as a file named "instance.dcm"
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
64 urlwrite([ URL '/instances/' instance '/file' ], 'instance.dcm');
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
65
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
66 if exist('OCTAVE_VERSION', 'builtin') ~= 0
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
67 # If running Octave instead of Matlab, load the "dicom" package from Octave Forge
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
68 pkg load image
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
69 pkg load dicom
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
70 endif
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
71
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
72 # Decode the downloaded DICOM file
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
73 im = dicomread('instance.dcm');
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
74 imagesc(im)
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
75
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
76 .. highlight:: bash
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
77
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
78 **Note:** If running Octave, you will have to manually install the
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
79 `dicom package from Octave Forge
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
80 <https://octave.sourceforge.io/dicom/index.html>`__. Download the
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
81 source code of the package, make sure the ``libgdcm2-dev`` and
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
82 ``octave-image`` packages are installed (for Ubuntu 16.04), then type
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
83 the following command to install the ``dicom`` package::
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
84
af1e13dac7e6 raw dicom in matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
85 $ octave --no-gui --eval "pkg install ./dicom-0.2.0.tar.gz"