Skip to content

Instantly share code, notes, and snippets.

@nanodocumet
nanodocumet / read-directory-records.php
Created January 20, 2015 20:58
Snippet to read DirectoryRecordSequenceItems from a DICOMDIR file using Nanodicom
<?php
require 'nanodicom.php';
// File to read
$filename = 'DICOMDIR';
$dicom = Nanodicom::factory($filename);
// Parse whole file
$dicom->parse();
// Get the sequence
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
require 'nanodicom.php';
// test file is relative to current directory
$filename = '1.2.826.0.1.3680043.2.1227.180222088.13140515165842.0.dcm';
$dicom = Nanodicom::factory($filename);
$dicom->parse();
@nanodocumet
nanodocumet / nanodicom_read_sequences_improved.php
Created March 24, 2014 19:03
Read sequence items and iterate through them. Uses new read_sequence_items method
<?php
require 'nanodicom.php';
// test file is relative to current directory
$filename = 'test.dcm';
$dicom = Nanodicom::factory($filename);
$dicom->parse(array(array(0x5400, 0x0100)));
$WaveformSequence = $dicom->value(0x5400, 0x0100);
$WaveformSequenceItems = $dicom->read_sequence_items($WaveformSequence);
@nanodocumet
nanodocumet / read_sequences_nanodicom.php
Last active December 25, 2015 20:19
Sample code to read values from sequences. Should be incorporated into core to handle it natively.
<?php
require 'Nanodicom/nanodicom.php';
$filename = 'test.DCM';
$dicom = Nanodicom::factory($filename);
$dicom->parse(array(array(0x0010, 0x0010), array(0x0054, 0x0016)));
// Get the sequence
$seq = $dicom->value(0x0054, 0x0016);
// Get the items (sequences are grouped in items)
@nanodocumet
nanodocumet / remove_tag_dicom_file.php
Created February 23, 2013 19:41
Removing a tag from a DICOM file using Nanodicom
<?php
/*
* Current way to unset (remove) a tag from a DICOM file.
*/
echo "Removing a tag from a DICOM file using Nanodicom";
$filename = "myfile.dcm";
// We need to use dumper
$dicom = Nanodicom::factory($filename, 'dumper');
@nanodocumet
nanodocumet / create_new_elements.php
Created January 10, 2013 07:59
Workaround to add tags to DICOM file. Uses anonymizer to set the new tag at the right order in the dataset. Certainly a bug.
<?php
// 1) Workaround to create new elements for Nanodicom
try
{
$dicom = Nanodicom::factory($filename, 'anonymizer');
// Set Value (Patient Name here)
$dicom->value(0x0010, 0x0010, 'JKD');
//$dicom->value(0x0010, 0x0010, 'JKD'); Others as well
$tags = array(
array(0xF0ED, 0xF0ED, 'id{random}'), // Non-existing tag. Sorry, needs one at least
@nanodocumet
nanodocumet / scratch.php
Created November 27, 2011 22:29
Creating a DICOM file with jpeg lossy 8-bits from scratch
<?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);
@nanodocumet
nanodocumet / test.php
Created May 11, 2011 21:33
Model Testuser
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller {
public function action_index()
{
$user = new Model_Testuser;
$user_fields = array(
'username' => 'test',
@nanodocumet
nanodocumet / nanodicom_db.php
Created May 9, 2011 18:15
Loading values of Nanodicom by array
<?php
try
{
// Load and parse the file
$dicom = Nanodicom::factory($filename);
$dicom->parse();
$mode = 'LO';
// Do the Query
@nanodocumet
nanodocumet / Auth_AutoModeler_ORM.php
Created April 22, 2011 17:37
Auth_AutoModeler_ORM driver
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Automodeler_ORM Auth driver.
*
* @package Auth
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Auth_AutoModeler_ORM extends Auth {