Thursday, June 26, 2014

Reading DICOM files in Python 3

In Python 3, dicom files can be read, analysied and processed using Wand which is Python binding for ImageMagic. The example below shows how to get medical and image date embedded in DICOM and also how to disply the image itself.

Python 3.4 and Pillow 2.4 with JPEG2000 (openjpeg 2) support in Ubuntu 14.04

Pillow support for JPEG2000 comes from openjpeg 2 library. Unfortunatly, Ubuntu's libopenjpeg2 package is not version 2 of the openjpeg library, but actually version 1.3 which wont work with Pillow.

Installing Pillow 2.4 (pip install -I pillow) simply results in "OPENJPEG (JPEG2000) support not available".

Thus, it is needed to compile the openjpeg library 2.0 from source. For this, first lets download the openjpeg 2.0.1:wget http://downloads.sourceforge.net/project/openjpeg.mirror/2.0.1/openjpeg-2.0.1.tar.gz

tar xzvf openjpeg-2.0.1.tar.gz
cd openjpeg-2.0.1/
cmake .
make
sudo make install


Please note that we install version of openjpeg 2.0, rather than newer 2.1. Pillow wont recognize openjpeg 2.1 either.

Assuming everything went fine, we can reinstall Pillow:pip install -I pillow
If openjpeg 2.0.1 was detected successfully, we should get the following info "OPENJPEG (JPEG2000) support available" among others.

Wednesday, June 18, 2014

DICOM (dcm) files wont upload to Wordpress

Uploading DICOM files (*.dcm) files into Wordpress, may not work. For example using Visual Form Builder plugin for file upload, wont upload DICOM's. This is because wordpress and/or file upload plugins use wp_get_mime_types() function from wp-includes/functions.php to check mime type of the file being upload. Unfortunatly, dicom is not there. Thus it need to be added. To do this, just add 'dcm' => 'application/dicom', into wp_get_mime_types(). For example, as shown below:

Thursday, June 12, 2014

Xubuntu: Take screenshot of current window only

Pressing Prt Sc button on the keyboard takes screenshot of the entire desktop. To take the screenshot of the selected/current window only, we can use Alt + Prt Sc

Tuesday, June 10, 2014

ImageMagick: get size and resolution (DPI) of images

To get size and resolution in DPI of many images at once using ImageMagick, we can use this command:identify -format "%w x %h %x x %y\n" *.tiff This result for example in:576 x 432 72 PixelsPerInch x 72 PixelsPerInch 576 x 432 72 PixelsPerInch x 72 PixelsPerInch 576 x 432 72 PixelsPerInch x 72 PixelsPerInch 576 x 432 72 PixelsPerInch x 72 PixelsPerInch 576 x 432 72 PixelsPerInch x 72 PixelsPerInch 576 x 432 72 PixelsPerInch x 72 PixelsPerInch

Friday, June 06, 2014

Python 3.4: Check if module installed

To check whether a given module is install in Python 3.4, we can use PathFinder.find_spec class method. For example, to check if pyperclip moduel is installed / available we can use the following code: