Created
November 27, 2011 22:29
-
-
Save nanodocumet/1398306 to your computer and use it in GitHub Desktop.
Creating a DICOM file with jpeg lossy 8-bits from scratch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Script to create a DICOM file from scratch (adds a lossy 8-bit grayscale jpeg) | |
* Use with CAUTION!!! Might not create a valid DICOM file!! | |
* Some tags might be missing, and others might need valid values | |
* Assumes jpeg file and nanodicom toolkit is in local relative path | |
*/ | |
ini_set('display_errors', 'On'); | |
error_reporting(E_ALL | E_STRICT); | |
require 'nanodicom.php'; | |
// Pixeler tool has the method to add the jpeg image | |
$dicom = Nanodicom::factory('', 'pixeler', 'blob'); | |
// Set some values here (Needs to be done by Group and Element | |
// Group, Element, New value | |
// MetaElementGroupLength (this one needs to be first!) | |
$dicom->value(0x0002, 0x0000, 0); | |
// Patient ID | |
$dicom->value(0x0010, 0x0020, 'ID12345'); | |
// MediaStorageSOPClassUID. "Ultrasound Image Storage" | |
$dicom->value(0x0002, 0x0002, '1.2.840.10008.5.1.4.1.1.6.1'); | |
// MediaStorageSOPInstanceUID. Using a dummy one | |
$dicom->value(0x0002, 0x0003, '1.2.3.4.5'); | |
// Patient Name | |
$dicom->value(0x0010, 0x0010, 'Patient^Name'); | |
// Study date | |
$dicom->value(0x0008, 0x0020, date('Ymd')); | |
// ImplementationClassUID. Using a dummy one | |
$dicom->value(0x0002, 0x0012, '1.2.3.4.5'); | |
// Modality | |
$dicom->value(0x0008, 0x0060, 'SC'); | |
// Add jpeg | |
// pass the location of a jpeg file, in this case is a grayscale image. | |
$dicom->add_lossy_jpeg8('test.jpg'); | |
// Save the file | |
$dicom->write_file('test.dcm'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment