annotate Sphinx/source/faq/matlab.rst @ 34:922f5c7192c6

matlab
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 Jul 2016 14:18:47 +0200
parents
children cb712e9d9187
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 Interfacing with Matlab and Octave
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 ==================================
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 Thanks to the REST API of Orthanc, it is easy to access DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 from Matlab or Octave, as depicted in the following sample image:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 .. image:: ../images/Matlab.png
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 :align: center
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 :width: 470px
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 Both Matlab and Octave have access to HTTP servers thanks to their
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 built-in `urlread() function
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 <http://nl.mathworks.com/help/matlab/ref/urlread.html>`__. Once must
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 simply install a Matlab/Octave library to decode JSON files. The
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 `JSONlab toolkit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 <http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files>`__
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 works perfectly to this end.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 .. highlight:: matlab
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 Using JSONlab, the following code will download and display a DICOM image::
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 SERIES = 'ae164c84-e5bd0366-ba937a6d-65414092-f294d6b6';
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 URL = 'http://orthanc.chu.ulg.ac.be/demo';
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 # Get information about the instances in this DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 instances = loadjson(urlread([ URL '/series/' SERIES '/instances' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # Select one slice from the series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 instance = instances{1,1}.ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 # Decode the slice with Orthanc thanks to the "/matlab" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 slice = eval(urlread([ URL '/instances/' instance '/matlab' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # Compute the maximum value in this slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 max(max(slice))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 # Display the slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 imagesc(slice)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 # Annotate the graph with the patient name and ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 tags = loadjson(urlread([ URL '/instances/' instance '/tags?simplify' ]));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 title([ 'This is a slice from patient ' tags.PatientID ' (' tags.PatientName ')' ])