Module: DICOM
- Includes:
- Logging
- Defined in:
- lib/dicom/d_object.rb,
lib/dicom.rb,
lib/dicom/uid.rb,
lib/dicom/item.rb,
lib/dicom/link.rb,
lib/dicom/d_read.rb,
lib/dicom/parent.rb,
lib/dicom/stream.rb,
lib/dicom/d_write.rb,
lib/dicom/element.rb,
lib/dicom/d_client.rb,
lib/dicom/d_server.rb,
lib/dicom/sequence.rb,
lib/dicom/d_library.rb,
lib/dicom/elemental.rb,
lib/dicom/anonymizer.rb,
lib/dicom/image_item.rb,
lib/dicom/audit_trail.rb,
lib/dicom/file_handler.rb,
lib/dicom/general/logging.rb,
lib/dicom/general/methods.rb,
lib/dicom/general/version.rb,
lib/dicom/image_processor.rb,
lib/dicom/elemental_parent.rb,
lib/dicom/general/constants.rb,
lib/dicom/general/variables.rb,
lib/dicom/dictionary_element.rb,
lib/dicom/image_processor_r_magick.rb,
lib/dicom/image_processor_mini_magick.rb
Overview
Copyright 2008-2018 Christoffer Lervag
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Defined Under Namespace
Modules: Elemental, ElementalParent, ImageProcessor, Logging Classes: Anonymizer, AuditTrail, DClient, DLibrary, DObject, DServer, DictionaryElement, Element, FileHandler, ImageItem, Item, Link, Parent, Sequence, Stream, UID
Constant Summary collapse
- ROOT_DIR =
Defines the gem root directory in the file system.
"#{File.dirname(__FILE__)}/dicom"
- LIBRARY =
The library instance (data dictionary) of the DICOM module.
DICOM::DLibrary.new
- VERSION =
The ruby-dicom version string.
'0.9.8'
- UID_ROOT =
Ruby DICOM’s registered DICOM UID root (Implementation Class UID).
"1.2.826.0.1.3680043.8.641"
- NAME =
Ruby DICOM name & version (max 16 characters).
"RUBY-DCM_" + DICOM::VERSION
- ITEM_TAG =
Item tag.
"FFFE,E000"
- ITEM_TAGS =
All Item related tags (includes both types of delimitation items).
["FFFE,E000", "FFFE,E00D", "FFFE,E0DD"]
- ITEM_DELIMITER =
Item delimiter tag.
"FFFE,E00D"
- SEQUENCE_DELIMITER =
Sequence delimiter tag.
"FFFE,E0DD"
- DELIMITER_TAGS =
All delimiter tags.
["FFFE,E00D", "FFFE,E0DD"]
- ITEM_VR =
The VR used for the item elements.
" "
- PIXEL_TAG =
Pixel tag.
"7FE0,0010"
- ENCAPSULATED_PIXEL_NAME =
Name of the pixel tag when holding encapsulated data.
"Encapsulated Pixel Data"
- PIXEL_ITEM_NAME =
Name of encapsulated items.
"Pixel Data Item"
- META_GROUP =
File meta group.
"0002"
- GROUP_LENGTH =
Group length element.
"0000"
- IMPLICIT_LITTLE_ENDIAN =
Implicit, little endian (the default transfer syntax).
"1.2.840.10008.1.2"
- EXPLICIT_LITTLE_ENDIAN =
Explicit, little endian transfer syntax.
"1.2.840.10008.1.2.1"
- EXPLICIT_BIG_ENDIAN =
Explicit, big endian transfer syntax.
"1.2.840.10008.1.2.2"
- VERIFICATION_SOP =
Verification SOP class UID.
"1.2.840.10008.1.1"
- APPLICATION_CONTEXT =
Application context SOP class UID.
"1.2.840.10008.3.1.1.1"
- SUCCESS =
Network transmission successful.
0
- ACCEPTANCE =
Network proposition accepted.
0
- ABSTRACT_SYNTAX_REJECTED =
Presentation context rejected by abstract syntax.
3
- TRANSFER_SYNTAX_REJECTED =
Presentation context rejected by transfer syntax.
4
- C_STORE_RQ =
Some network command element codes:
1
- C_GET_RQ =
(encodes to 0001H as US)
16
- C_FIND_RQ =
(encodes to 0010H as US)
32
- C_MOVE_RQ =
(encodes to 0020H as US)
33
- C_ECHO_RQ =
(encodes to 0021H as US)
48
- C_CANCEL_RQ =
(encodes to 0030 as US)
4095
- C_STORE_RSP =
(encodes to 0FFFH as US)
32769
- C_GET_RSP =
(encodes to 8001H as US)
32784
- C_FIND_RSP =
(encodes to 8010H as US)
32800
- C_MOVE_RSP =
(encodes to 8020H as US)
32801
- C_ECHO_RSP =
(encodes to 8021H as US)
32816
- NO_DATA_SET_PRESENT =
(encodes to 8030H as US)
257
- DATA_SET_PRESENT =
(encodes to 0101H as US)
1
- DEFAULT_MESSAGE_ID =
1
- DATA_MORE_FRAGMENTS =
The network communication flags:
"00"
- COMMAND_MORE_FRAGMENTS =
"01"
- DATA_LAST_FRAGMENT =
"02"
- COMMAND_LAST_FRAGMENT =
"03"
- PDU_ASSOCIATION_REQUEST =
Network communication PDU types:
"01"
- PDU_ASSOCIATION_ACCEPT =
"02"
- PDU_ASSOCIATION_REJECT =
"03"
- PDU_DATA =
"04"
- PDU_RELEASE_REQUEST =
"05"
- PDU_RELEASE_RESPONSE =
"06"
- PDU_ABORT =
"07"
- ITEM_APPLICATION_CONTEXT =
Network communication item types:
"10"
- ITEM_PRESENTATION_CONTEXT_REQUEST =
"20"
- ITEM_PRESENTATION_CONTEXT_RESPONSE =
"21"
- ITEM_ABSTRACT_SYNTAX =
"30"
- ITEM_TRANSFER_SYNTAX =
"40"
- ITEM_USER_INFORMATION =
"50"
- ITEM_MAX_LENGTH =
"51"
- ITEM_IMPLEMENTATION_UID =
"52"
- ITEM_MAX_OPERATIONS_INVOKED =
"53"
- ITEM_ROLE_NEGOTIATION =
"54"
- ITEM_IMPLEMENTATION_VERSION =
"55"
- CPU_ENDIAN =
System (CPU) Endianness.
- TXS_IMPLICIT_LITTLE_ENDIAN =
General
'1.2.840.10008.1.2'
- TXS_EXPLICIT_LITTLE_ENDIAN =
also defined as IMPLICIT_LITTLE_ENDIAN, default transfer syntax
'1.2.840.10008.1.2.1'
- TXS_EXPLICIT_BIG_ENDIAN =
also defined as EXPLICIT_LITTLE_ENDIAN
'1.2.840.10008.1.2.2'
- TXS_JPEG_BASELINE =
TRANSFER SYNTAXES FOR ENCAPSULATION OF ENCODED PIXEL DATA
'1.2.840.10008.1.2.4.50'
- TXS_JPEG_EXTENDED =
'1.2.840.10008.1.2.4.51'
- TXS_JPEG_LOSSLESS_NH =
NH: non-hirarchical
'1.2.840.10008.1.2.4.57'
- TXS_JPEG_LOSSLESS_NH_FOP =
NH: non-hirarchical, FOP: first-order prediction
'1.2.840.10008.1.2.4.70'
- TXS_JPEG_LS_LOSSLESS =
'1.2.840.10008.1.2.4.80'
- TXS_JPEG_LS_NEAR_LOSSLESS =
'1.2.840.10008.1.2.4.81'
- TXS_JPEG_2000_PART1_LOSSLESS =
'1.2.840.10008.1.2.4.90'
- TXS_JPEG_2000_PART1_LOSSLESS_OR_LOSSY =
'1.2.840.10008.1.2.4.91'
- TXS_JPEG_2000_PART2_LOSSLESS =
'1.2.840.10008.1.2.4.92'
- TXS_JPEG_2000_PART2_LOSSLESS_OR_LOSSY =
'1.2.840.10008.1.2.4.93'
- TXS_MPEG2_MP_ML =
'1.2.840.10008.1.2.4.100'
- TXS_MPEG2_MP_HL =
'1.2.840.10008.1.2.4.101'
- TXS_DEFLATED_LITTLE_ENDIAN =
ZIP Compression
'1.2.840.10008.1.2.1.99'
- TXS_JPIP =
'1.2.840.10008.1.2.4.94'
- TXS_JPIP_DEFLATE =
'1.2.840.10008.1.2.4.95'
- TXS_RLE =
'1.2.840.10008.1.2.5'
- PI_MONOCHROME1 =
Photometric Interpretations Taken from DICOM Specification PS 3.3 C.7.6.3.1.2 Photometric Interpretation
'MONOCHROME1'
- PI_MONOCHROME2 =
'MONOCHROME2'
- PI_PALETTE_COLOR =
'PALETTE COLOR'
- PI_RGB =
'RGB'
- PI_YBR_FULL =
'YBR_FULL'
- PI_YBR_FULL_422 =
'YBR_FULL_422 '
- PI_YBR_PARTIAL_422 =
'YBR_PARTIAL_422'
- PI_YBR_PARTIAL_420 =
'YBR_PARTIAL_420'
- PI_YBR_ICT =
'YBR_ICT'
- PI_YBR_RCT =
'YBR_RCT'
- PI_HSV =
Retired Photometric Interpretations, are those needed to be supported?
'HSV'
- PI_ARGB =
'ARGB'
- PI_CMYK =
'CMYK'
- ENCODING_NAME =
The relationship between DICOM Character Set and Encoding name.
{ 'ISO_IR 100' => 'ISO-8859-1', 'ISO_IR 101' => 'ISO-8859-2', 'ISO_IR 109' => 'ISO-8859-3', 'ISO_IR 110' => 'ISO-8859-4', 'ISO_IR 144' => 'ISO-8859-5', 'ISO_IR 127' => 'ISO-8859-6', 'ISO_IR 126' => 'ISO-8859-7', 'ISO_IR 138' => 'ISO-8859-8', 'ISO_IR 148' => 'ISO-8859-9', 'ISO_IR 13' => 'Shift_JIS', 'ISO 2022 IR 13' => 'Shift_JIS', 'ISO 2022 IR 13\\ISO 2022 IR 87' => 'Shift_JIS', 'ISO 2022 IR 87' => 'ISO-2022-JP', 'ISO_IR 166' => 'ISO-8859-11', 'GB18030' => 'GB18030', 'ISO_IR 192' => 'UTF-8' }
- VALUE_CONVERSION =
The type conversion (method) used for the various value representations.
{ 'BY' => :to_i, 'US' => :to_i, 'SS' => :to_i, 'UL' => :to_i, 'SL' => :to_i, 'OB' => :to_i, 'OW' => :to_i, 'OF' => :to_f, 'FL' => :to_f, 'FD' => :to_f, 'AT' => :to_s, 'AE' => :to_s, 'AS' => :to_s, 'CS' => :to_s, 'DA' => :to_s, 'DS' => :to_s, 'DT' => :to_s, 'IS' => :to_s, 'LO' => :to_s, 'LT' => :to_s, 'PN' => :to_s, 'SH' => :to_s, 'ST' => :to_s, 'TM' => :to_s, 'UI' => :to_s, 'UT' => :to_s }
Class Attribute Summary collapse
-
.image_processor ⇒ Object
The ruby-dicom image processor to be used.
-
.key_representation ⇒ Object
The key representation for hashes, json, yaml.
-
.source_app_title ⇒ Object
Source Application Entity Title (gets written to the DICOM header in files where it is undefined).
Class Method Summary collapse
-
.generate_uid(root = UID_ROOT, prefix = 1) ⇒ String
Generates a unique identifier string.
-
.key_use_method_names ⇒ Object
Use method names as key.
-
.key_use_names ⇒ Object
Use names as key.
-
.key_use_tags ⇒ Object
Use tags as key.
-
.load(data) ⇒ Array<DObject>
Loads DICOM data to DObject instances and returns them in an array.
-
.load_files(path) ⇒ Array<String>
Loads DICOM files from a given path (which points to either a directory or a file).
Methods included from Logging
Class Attribute Details
.image_processor ⇒ Object
The ruby-dicom image processor to be used.
10 11 12 |
# File 'lib/dicom/general/variables.rb', line 10 def image_processor @image_processor end |
.key_representation ⇒ Object
The key representation for hashes, json, yaml.
12 13 14 |
# File 'lib/dicom/general/variables.rb', line 12 def key_representation @key_representation end |
.source_app_title ⇒ Object
Source Application Entity Title (gets written to the DICOM header in files where it is undefined).
14 15 16 |
# File 'lib/dicom/general/variables.rb', line 14 def source_app_title @source_app_title end |
Class Method Details
.generate_uid(root = UID_ROOT, prefix = 1) ⇒ String
Generates a unique identifier string. The UID is composed of a DICOM root UID, a type prefix, a datetime part and a random number part.
19 20 21 22 23 24 25 26 |
# File 'lib/dicom/general/methods.rb', line 19 def generate_uid(root=UID_ROOT, prefix=1) # NB! For UIDs, leading zeroes immediately after a dot is not allowed. date = Time.now.strftime("%Y%m%d").to_i.to_s time = Time.now.strftime("%H%M%S").to_i.to_s random = rand(99999) + 1 # (Minimum 1, max. 99999) uid = [root, prefix, date, time, random].join('.') return uid end |
.key_use_method_names ⇒ Object
Use method names as key. Example: :patients_name
93 94 95 |
# File 'lib/dicom/general/methods.rb', line 93 def key_use_method_names @key_representation = :name_as_method end |
.key_use_names ⇒ Object
Use names as key. Example: “Patient’s Name”
87 88 89 |
# File 'lib/dicom/general/methods.rb', line 87 def key_use_names @key_representation = :name end |
.key_use_tags ⇒ Object
Use tags as key. Example: ‘0010,0010’
81 82 83 |
# File 'lib/dicom/general/methods.rb', line 81 def @key_representation = :tag end |
.load(data) ⇒ Array<DObject>
Loads DICOM data to DObject instances and returns them in an array. Invalid DICOM sources (files) are ignored. If no valid DICOM source is given, an empty array is returned.
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 |
# File 'lib/dicom/general/methods.rb', line 35 def load(data) data = Array[data] unless data.respond_to?(:to_ary) ary = Array.new data.each do |element| if element.is_a?(String) begin if File.directory?(element) files = Dir[File.join(element, '**/*')].reject {|f| File.directory?(f) } dcms = files.collect {|f| DObject.read(f)} elsif File.file?(element) dcms = [DObject.read(element)] else dcms = [DObject.parse(element)] end rescue dcms = [DObject.parse(element)] end ary += dcms.keep_if {|dcm| dcm.read?} else # The element was not a string, and the only remaining valid element type is a DICOM object: raise ArgumentError, "Invalid element (#{element.class}) given. Expected string or DObject." unless element.respond_to?(:to_dcm) element.was_dcm_on_input = true ary << element.to_dcm end end ary end |
.load_files(path) ⇒ Array<String>
Loads DICOM files from a given path (which points to either a directory or a file).
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dicom/general/methods.rb', line 68 def load_files(path) files = Array.new if File.directory?(path) files = Dir[File.join(path, '**/*')].reject {|f| File.directory?(f) } else # This path is presumably a file. files << path end files end |