Mercurial > hg > orthanc-book
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 |
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 | 3 Interfacing with Matlab and Octave |
4 ================================== | |
5 | |
6 Thanks to the REST API of Orthanc, it is easy to access DICOM images | |
7 from Matlab or Octave, as depicted in the following sample image: | |
8 | |
9 .. image:: ../images/Matlab.png | |
10 :align: center | |
11 :width: 470px | |
12 | |
13 Both Matlab and Octave have access to HTTP servers thanks to their | |
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 | 16 simply install a Matlab/Octave library to decode JSON files. The |
66 | 17 `JSONLab toolkit <https://github.com/fangq/jsonlab>`__ works perfectly |
18 to this end. | |
34 | 19 |
20 .. highlight:: matlab | |
21 | |
22 Using JSONlab, the following code will download and display a DICOM image:: | |
23 | |
24 SERIES = 'ae164c84-e5bd0366-ba937a6d-65414092-f294d6b6'; | |
66 | 25 URL = 'http://demo.orthanc-server.com/'; |
34 | 26 |
27 # Get information about the instances in this DICOM series | |
28 instances = loadjson(urlread([ URL '/series/' SERIES '/instances' ])); | |
29 | |
30 # Select one slice from the series | |
102 | 31 instance = instances{1}.ID |
34 | 32 |
33 # Decode the slice with Orthanc thanks to the "/matlab" URI | |
34 slice = eval(urlread([ URL '/instances/' instance '/matlab' ])); | |
35 | |
36 # Compute the maximum value in this slice | |
37 max(max(slice)) | |
38 | |
39 # Display the slice | |
40 imagesc(slice) | |
41 | |
42 # Annotate the graph with the patient name and ID | |
43 tags = loadjson(urlread([ URL '/instances/' instance '/tags?simplify' ])); | |
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" |