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