Mac OSX Wireless Networks

Last update : September 17, 2015

AdHoc Wi-Fi Networks

Sometimes it’s useful to create a WLAN (wireless network) between two or more Wi-Fi-enabled computers without using an Wi-Fi router. These computer-to-computer networks are usually referred to as AdHoc wireless networks.

create

Create an ad-hoc Wi-Fi network on Mac OSX

On a Mac OSX (Yosemite 10.10.5) it’s easy to set up such a network. Choose Create Network from the Wi-Fi status icon in the menu bar. Enter a name (in my case : radiologic-open) for the new network and select the channel (default channel = 11). You will notice that there is no password protection to secure the network. A WEP (Wired Equivalent Encryption) algorithm was however available in previous versions of the OSX system. WEP was Wi-Fi’s first encryption standard and was almost intentionally designed to be weak due to issues related to the US export policies about encryption. WEP was deprecated in 2003 and replaced by WPA2 (Wi-Fi Protected Access) by the Wi-Fi Alliance.

In Yosemite, Apple killed WEP once for all, without replacing it by another protection method in AdHoc mode.

open

Chose name and channel for the AdHoc network

If the icon isn’t in the menu bar, choose Apple menu > System Preferences, then click Network (réseau). Click Wi-Fi and select the Show Wi-Fi status in menu bar checkbox.

Mac OSX

Mac OSX System Preferences

The Wi-Fi status menu shows the established connection with the radiologic-open network. The menu allows an easy logout and reconnection to another Wi-Fi network. An automatic logout occurs when the Mac screen is powered off.

Radoio

Wi-Fi status menu shows the AdHoc network active

Infrastructure Wi-Fi networks

There exist a second possibility to set up a Wi-Fi network on Mac OSX. The computer is configured as a software Wi-Fi base station. This allows to share an Internet connection and offers a password protection, but it has another inconvenience. You need a working wired Ethernet connection between your Mac and a hub, even if the hub is not connected to the Internet. The next picture shows my test setup: my MacBookAir is connected via a Ethernet-Thunderbolt interface to an ancient 10 Mbit/s Ethernet hub.

Thunderbolt-Ethernet

MacBookAir connected with Thunderbolt-Ethernet interface to hub

First you need to configure the Ethernet-Thunderbold interface. Go to Network in System Preferences and select the automatic configuration. The interface gets a self-assigned IP address in the range 169.254.x.x.

network

Ethernet-Thunderbolt automatic configuration

In the next step go to the Sharing Preference Pane in the System Preferences. Select Ethernet-Thunderbold as source port and Wi-Fi as destination port. Select Wi-Fi options to enter a name (in my case : radiologic-secure) of the network, to select a channel and to define a password (minimum 8 characters; numbers are not recognized on BlackBerry and Android).

Internet Sharing Wi-Fi network configuration

Internet Sharing Wi-Fi network configuration

Finally check the Internet sharing checkbox and confirm the settings to activate the connection.

Share

Activate the Internet sharing

The resulting pane is shown below.

rads

Activated Internet sharing pane

The Wi-Fi status is updated automatically. To log out, desactivate the Wi-Fi connection in the corresponding menu. An automatic logout occurs when the Mac screen is powered off.

Radio

Wi-Fi status menu showing Internet sharing

The following table shows which of my devices are capable to connect to the Mac OSX AdHoc and Infrastructure networks.

Device Wi-Fi AdHoc Wi-Fi infrastructure
iPad OK OK
iPhone OK OK
BlackBerry  network not shown network joined, but
no access to host
Samsung Tablet (Android 4.2.2) network not in range network joined, but
no access to host
Laptop Vista no connection network joined, but
no access to host
Desktop Windows 8.1 network not shown OK
Laptop Debian no connection OK

Wi-Fi Diagnostic

To detect the reasons why some devices don’t connect to the Mac OSX Wi-Fi AdHoc or Infrastructure networks, you can use a WLAN analyser. Mac OS X Yosemite has an in-built Wi-Fi scanner to help you find the best Wi-Fi channel. When you hold down the option key ⌥ (next to the CTRL key) and select the Wi-Fi icon in the menu bar, a secret dropdown menu opens.

secret

Secret Wi-Fi dropdown menu in Mac OSX Yosemite

Open Wireless Diagnostics and click it. After you have gotten to the page and have opened up the Wireless Diagnostics window, go to the top left of your menu bar and click on Window where you find several options: Informations, history, scan, performance, detection, …  Some results are shown below.

Mac OSX Wi-Fi Analyser

Mac OSX Wi-Fi Analyser

Another WLAN tool is available on Windows computers. When you enter the command

netsh wlan show networks mode=bssid

in the command window, you will get the following results :

Wi-Fi

Microsoft Wi-Fi Analyser

A third WLAN tool is integrated in my Wi-Fi router FritzBox 7390. Various wireless networks in my neighborhood are shown, but nor the channels used by the Mac OSX nor the names of these networks are listed. I don’t know why ?

funkkanale

Wi-Fi channels used in proximity of the Fritzbox

There are also several external software tools for Wi-Fi-analysis available, for example Acrylic Wi-Fi Free or Acrylic Wi-Fi Professional. The main window (Access points,  Signal strength) of Acrylic is shown hereafter :

Acrlylic Wi-Fi Analyser

Acrlylic Wi-Fi Analyser

Some additional windows (stations, packet viewer, 2,4 GHz APs channels, detailed info) are shown below :

Various Acrylic results

Various Acrylic results

Wi-Fi Assessment

Several methodologies are available dealing with safety aspects of wireless networks, for example :

Links

The following list shows links to websites providing additional informations about Wi-Fi networks, related to Mac OSX.

DICOM image viewers

Last update : May 30, 2016

Referring to my recent post about the DICOM standard, this contribution presents an overview about an important entity in the medical imaging workflow : DICOM image viewers. The list is not exhaustive; I did the following segmentation to present my personal selection of current DICOM image viewers :

  1. Reference viewer
  2. Reference toolkits
  3. Open source viewers
  4. Free proprietary viewers
  5. Licensed commercial viewers
  6. Mobile viewer apps
  7. Other viewers

1. Reference DICOM Viewer

Today one project is generally considered as a reference for DICOM applications : OsiriX.

OsiriX

The OsiriX project started in November 2003. The first version was developed by Antoine Rosset, a radiologist from Geneva, Switzerland, working now at the La Tour Hospital  in Geneva. He received a grant from the Swiss National Fund to spend one year in UCLA, Los Angeles, with Prof. Osman Ratib, to explore and learn about medical digital imaging. In October 2004, Antoine Rosset went back to the Geneva University Hospital in Switzerland, to continue his career as a radiologist, where he published an OsiriX reference article in June 2004 in the Journal of Digital Imaging. Joris Heuberger, a mathematician from Geneva, joined the project in March 2005 on a voluntary fellowship of 6 months in UCLA, Los Angeles. In June 2005, OsiriX received two prestigious Apple Design Awards : Best Use of Open Source and Best Mac OS X Scientific Computing Solution. Osman Ratib, Professor of Radiology in UCLA, returned to Geneva at the end of 2005 as the chairman of the Nuclear Medicine service.

In March 2009, Antoine Rosset, Joris Heuberger and Osman Ratib created the OsiriX Foundation to promote open-source in medicine. In February 2010, Antoine Rosset and Joris Heuberger created the company Pixmeo to promote and distribute the OsiriX MD version, certified for medical imaging. This version complies with the European Directive 93/42/EEC concerning medical devices. The price for a single licence is 678 EUR. The free lite version can be downloaded from the OsiriX website, the source code is available at Github.

OsiriX runs on Mac OSX and is released under the version 3 of the GNU Lesser General Public License. The current version is 7.0 and was released on December 7, 2015. Osirix can also be configured as a PACS server. The power of OsiriX can be extended with plugins.

OsririX Lite

OsririX Lite

An Osirix HD version for the iPad is available at the AppStore for 49,99 EUR.

2. Reference DICOM toolkits

DICOM toolkits are more than simple viewers; they are a complete set of tools, code samples, examples, documentation, tutorials etc to develop great healthcare applications.

DCMTK

DCMTK is a collection of libraries and applications implementing large parts the DICOM standard. It includes software for examining, constructing and converting DICOM image files, handling offline media, sending and receiving images over a network connection, as well as demonstrative image storage and worklist servers. DCMTK is is written in a mixture of ANSI C and C++. It comes in complete source code and is made available as open source software.

DCMTK is an ancestor of DICOM applications. In 1993, before the official release of the standard, a DICOM prototype implementation was created by OFFIS, the University of Oldenburg and the CERIUM (Centre Européen d’Imagerie à Usage Médical) research centre in Rennes (France) on behalf of the European Committee for Standardization (CEN/TC251/WG4).

The current version of DCMTK is 3.6.1, released in June 2015. The related snapshot is available at the dicom.offis.de website. DICOMscope is the related free DICOM viewer which can display uncompressed, monochrome DICOM images from all modalities and which supports monitor calibration according to DICOM part 14 as well as presentation states. DICOMScope 3.6.0 for Windows, implemented in a mixture of Java and C++, was released in 2003. DICOMscope can’t be installed on newer Windows systems (Vista, Windows 7, Windows 8.1), an error 105 (setup.lid missing) is issued.

DICOMscope

DICOMscope version 3.5.1 (archive image)

Some DCMTK modules, especially those that are not part of the free toolkit, are covered by a separate license which can be found in the COPYRIGHT file in the corresponding module directory. These tools can be evaluated during a period of four months, any further use of the software requires a full licence agreement, free of charge.

The following sub-packages are part of DCMTK :

  • config: configuration utilities for dcmtk
  • dcmdata: a data encoding/decoding library and utility apps
  • dcmimage: adds support for color images to dcmimgle
  • dcmimgle: an image processing library and utility apps
  • dcmjpeg: a compression/decompression library and utility apps
  • dcmjpls: a compression/decompression library and utility apps
  • dcmnet: a networking library and utility apps
  • dcmpstat: a presentation state library and utility apps
  • dcmrt: a radiation therapy library and utility apps
  • dcmsign: a digital signature library and utility apps
  • dcmsr: a structured report library and utility apps
  • dcmtls: security extensions for the network library
  • dcmwlm: a modality worklist database server
  • dcmqrdb: an image database server
  • oflog: a logging library based on log4cplus
  • ofstd: a library of general purpose classes

Each sub-package (module) contains a collection of sub-modules (functions). For example, the networking library dcmnet contains the following command line tools :

  • dcmrecv: Simple DICOM storage SCP (receiver)
  • dcmsend: Simple DICOM storage SCU (sender)
  • echoscu: DICOM verification (C-ECHO) SCU
  • findscu: DICOM query (C-FIND) SCU
  • getscu: DICOM retrieve (C-GET) SCU
  • movescu: DICOM retrieve (C-MOVE) SCU
  • storescp: DICOM storage (C-STORE) SCP
  • storescu: DICOM storage (C-STORE) SCU
  • termscu: DICOM termination SCU

dcm4che

dcm4che2 is a collection of open source applications and utilities for the healthcare enterprise developed in the Java programming language. dcm4chee2 is a DICOM Clinical Data Manager system.

dcm4che2 contains a number of useful sample applications that may be used in conjunction with dcm4chee, with another archive application, or to operate on DICOM objects in a standalone fashion. A list of the dcm4che2 utilities is shown hereafter :

  • dcm2txt- Convert a DICOM object to text
  • dcm2xml- Convert a DICOM object to XML
  • dcmdir- Manipulate a DICOM dir
  • dcmecho – Initiate a C-ECHO command as an SCU
  • cmgpwl – Query a General Purpose Worklist SCP
  • dcmmwl – Query a Modality Worklist SCP
  • dcmof – Simulate an Order Filler application
  • dcmqr – Perform C-FIND, C-GET and C-MOVE operations as an SCU
  • dcmrcv – DICOM receiver (C-STORE SCP)
  • dcmsnd – Perform C-STORE operations as an SCU
  • dcmups – Unified Worklist and Procedure Step SCU
  • dcmwado – Initiate DICOM WADO requests
  • jpg2dcm – Convert a JPEG image to DICOM
  • logger – Log files to a Syslog destination
  • mkelmdic – Create the serialized dcm4che2 DICOM Dictionary
  • mkuiddic – Create the dcm4che2 UID dictionary
  • mkvrmap – Create the dcm4che2 VR Mappings
  • pdf2dcm – Convert a PDF document to DICOM
  • rgb2ybr – Convert pixel data from YBR to RGB format
  • txt2dcmsr – Convert text to a DICOM Structured Report
  • xml2dcm – Convert XML to DICOM

The dcm4che history states that back around the year 2000, Gunter Zeilinger wrote the popular JDicom utility suite using commercial Java DICOM Toolkit (JDT). After this experience, he decided to develop his own toolkit and to name it after Che Guevara.
dcm4che and dcm4chee are licensed under an MPL/GPL/LGPL triple license, similar to Mozilla.

The dcm4che DICOM viewer is called Weasis. The current version is 2.0.4, released on June 23, 2015.

WEASIS version 2.0.4

WEASIS version 2.0.4

Grassroots DICOM

Grassroots DiCoM is a C++ library for DICOM medical files. It is accessible from Python, C#, Java and PHP. It supports RAW, JPEG, JPEG 2000, JPEG-LS, RLE and deflated transfer syntax. It comes with a super fast scanner implementation to quickly scan hundreds of DICOM files. It supports SCU network operations (C-ECHO, C-FIND, C-STORE, C-MOVE).

The current version is gdcm-2.6.3, released on January 27, 2016. The GDCM source code is available at Github. A Wiki is available at Sourceforge, a reference to GDCM is available at Wikipedia. The project is developed by Mathieu Malaterre (malat) from Lyon, France.

3. Open Source DICOM Viewers

Most open source DICOM viewer projects are web viewers based on HTML5, CCS3 and Javascript. The big advantage of these viewers is the cross-platform compatibility; they can be used with any modern browser.

DICOM web viewers are presented in a separate contribution. Among them are the following open source projects :

  • Cornerstone
  • DWV
  • Papaya
  • jsDICOM
  • webDICOM
  • dcmjs

There are also some non web open source DICOM viewers :

  • 3DSlicer
  • 3DimViewer

3DSlicer

3D Slicer is a free and open source software package for image analysis and scientific visualization. It’s more than a simple DICOM viewer. This outstanding project started as a masters thesis project between the Surgical Planning Laboratory at the Brigham and Women’s Hospital and the MIT Artificial Intelligence Laboratory in 1998.

3D Slicer is written in C++, Python, Java and Qt and can be compiled for use on multiple computing platforms, including Windows, Linux, and Mac OS X. 3D Slicer needs a powerful computer to run. The current version is 4.5.0-1, released on November 11, 2015. It’s distributed  under a BSD style, free, open source license. More than 50 plug-ins and packages of plug-ins are available.

3D Slicer

3D Slicer

The main developers are now Steve Pieper, Slicer’s principal architect and Ron Kikinis, Principal Investigator for many Slicer-related projects. The names of all contributors are available at the 3D slicer.org website.

3DimViewer

3DimViewer is a lightweight 3D viewer of medical DICOM datasets distributed as open source software. The viewer is multiplatform software written in C++ that runs on Windows, Linux and Mac OSX systems.

3DimViewer is developed by 3Dim Laboratory s.r.o., a company specializing in applications of modern computer graphics in medicine and developing innovative solutions. Founded since 2008, the company focuses on medical image processing, 3D graphics, geometry processing and volumetric data visualization. The company office is located in Brno, Czech Republic, next to many high tech companies inheriting the spirit of South Moravian Innovation Centre.

3DimViewer

3DimViewer version 2.2

The current version of 3DimViewer is 2.2, released on February 6, 2015. Several plugins are available to extend the functions. Binaries are available for download on the 3DimLab website, source code is available at BitBucket.

GDCMviewer

GDCMviewer is the simple tool that show how to use vtkGDCMImageReader. It is basically only just a wrapper around GDCM. The tool is meant for testing integration of GDCM in VTK.

4. Free Proprietary DICOM Viewers

Most free proprietary DICOM viewers are copyrighted by their owner and are available for use, as is, free of charge, for educational and scientific, non-commercial purposes. Some of them are included on DICOM CDs provided by the hospitals to the patients.

Mango

Mango (short for Multi-image Analysis GUI) is a viewer for medical research images, developed by Jack L. Lancaster, Ph.D. and Michael J. Martinez at the University of Texas.

There are several versions of Manga available :

  • Manga Desktop, a Java application running on Windows Mac OSX and Linux
  • iMango, running on iPads and available at the AppStore
  • webMango, running as a Java applet
  • Papaya, running as HTML5 application in all browsers

The software and data derived from Mango software may be used only for research and may not be used for clinical purposes. If Mango software or data derived from Mango software is used in scientific publications, the Research Imaging Institute UTHSCSA must be cited as a reference.

Mango DICOM viewer

Mango DICOM viewer

Orpalis

The Orpalis DICOM Viewer is a free tool for medical staff to view DICOM files. The current version 1.0.1, released on June 20, 2014, should run on any 32- or 64-bit Windows System, but I experienced serious problems on my Windows 8.1 system (thumbnails are not displayed, frequent viewer crashes, …). The ORPALIS DICOM Viewer is based on the GdPicture.NET SDK.

Orpalis DICOM viewer

Orpalis DICOM viewer

MicroDICOM

MicroDicom is an application for primary processing and preservation of medical images in DICOM format, with an intuitive user interface and being free for use and accessible to everyone. MicroDicom runs on Windows, the current version is 0.9.1, released on June 2, 2015.

MicroDicom viewer

MicroDicom viewer

EMV Medical Viewer

The EMV viewer is developed by Escape, which was founded in 1991 and is based in downtown Thessaloniki, Greece. EMV 4 for Windows was released on October 10, 2014, EMV 4.4.1 for Mac OSX was released on July 21, 2015.

You can download and evaluate the software for free, but you need a license for using it in a commercial environment. The price for one license is 245 EUR, for use on up to three computers.

5. Licensed commercial DICOM viewers

Photoshop

Since version 10 (CS3) launched in April 2007, Photoshop provides a comprehensive image measurement and analysis tools with DICOM file support.

Photoshop CS3 with DICOM support

Photoshop CS3 with DICOM support

DICOMIZER

Dicomizer is a Point-Of-Care Imaging and Reporting tool provided by H.R.Z Software Services LTD in Tel-Aviv, Israel. The company is specialized in developing Medical Device, Healthcare IT, DICOM and HL7 solutions and provides medical imaging consultation, development services and professional courses. The company was founded in 2002 (formerly RZ Software Services) by Roni Zaharia, a medical imaging and connectivity expert, who is acting as its CEO. Roni Zaharia is the author of the blog DICOM is easy, providing useful news about medical images and an outstanding DICOM tutorial. Dicomizer works on Windows, the current version is 5.0. The price of a licence is $470 USD, a free evaluation version is available. The annual update costs are  $120 USD. Dicomizer can also be used as an DICOM image generator.

DICOMIZER

DICOMIZER version 4.1

H.R.Z Software Services LTD provides also the following medical toolkits :

  • RZDCX : Fast Strike DICOM Toolkit
  • DSRSVC : extensible DICOM Server (PACS) for OEM
  • HL7Kit Pro : WYSIWYG HL7 Integration Engine for MS SQL Server

MedImaView – PowerDicom

MedImaView is a multi-modality DICOM viewer with an intuitive Windows Graphical User Interface. It’s part of PowerDicom Technologies, an All-in-One application for handling DICOM files developed by DICOM Solutions, an MHGS company. Licenses for PowerDicom (version 4.8.6 released on May 4, 2015) are available in a price-range from 39 EUR to 310 EUR. PowerDicom allows also the generation of DICOM images. A free trial version can be downloaded from the DICOM Solutions website. MedImaView (version 1.8) is free for personal use and students.

MedimaView DICOM viewer

MedimaView DICOM viewer

DICOM PowerTools

DICOM PowerTools are developed by Laurel Bridge who provides imaging workflow solutions and DICOM software products to the medical imaging industry. PowerTools are a suite designed for the testing, troubleshooting, or debugging of applications that use DICOM communications. PowerTools also provides for the viewing, repair, or creation of DICOM data sets and their contents.

The current version is 1.0.34, released on November 24, 2015.

PowerTools File Editor

PowerTools File Editor

RadiAnt

RadiAnt is a DICOM viewer for medical images designed with an intuitive interface and unrivaled performance. It runs on Windows, the latest version is 2.2.8.10726, released on December 11, 2015. The prices for a license range from 72 EUR to 400 EUR. A free evaluation version is available. RadiAnt is not certified as a medical product and is not intended for diagnostic purposes. RadiAnt is developed by Medixant, a small, privately funded company that was first formed by Maciej Frankiewicz in 2011 in Poznan, Poland.

RadiAnt DICOM viewer

RadiAnt DICOM viewer

CODONICS Clarity Viewer

Headquartered in Cleveland, Ohio, Codonics develops, designs, sells and supports leading-edge medical imaging and information management devices used in diagnostic imaging.
Codonics Clarity Viewer features simple image navigation and selection, an intuitive user interface, quick viewer launch and rapid image loading. The Codonics Clarity 3D/Fusion Viewer is extremely useful for viewing diagnostic imaging results. It is a comprehensive PET/CT viewer that is simple to use for single or comparison study review. All basic features of the Codonics Clarity Viewer are also included.

Codonics

Codonics Clarity 3D/Fusion viewer

MatLab Dicom Toolbox

The Image Processing Toolbox of MatLab includes import, export and conversion functions for scientific file formats, amomg them DICOM files. The available functions are dicomanon, dicomdict, dicomdisp, dicominfo, dicomlookup, dicomread, dicomuid, dicomwrite. A tutorial shows how to write data to a DICOM file.

6. Mobile DICOM viewer apps

The mobile DICOM viewers are presented in a separate contribution.

7. Other DICOM viewers

The following list provides links to additional DICOM viewers developed by the industry’s leading medical imaging equipment suppliers and by independant developers :

Links

The following list shows links to websites with additional informations about DICOM viewers :

DICOM TransferSyntaxUID

Referring to my recent post about the DICOM standard, the list of all valid transfer syntaxes is shown below. A DICOM transfer syntax defines how DICOM objects are serialized to transmit them through a network or to save them into a file.

The DICOM transfer syntax is specified by the TransferSyntaxUID located in element number (0002, 0010). There exist 35 different DICOM transfer syntaxes, but 14 have been retired from earlier standard versions and will not be supported in future DICOM releases.

The 21 valid DICOM transfer syntaxes are listed in the following table :

TransferSyntaxUID Transfer Syntax Name Comments
1.2.840.10008.1.2 Implicit VR Endian Default
1.2.840.10008.1.2.1 Explicit VR Little Endian
1.2.840.10008.1.2.1.99 Deflated Explicit VR Big Endian
1.2.840.10008.1.2.2 Explicit VR Big Endian
1.2.840.10008.1.2.4.50 JPEG Baseline (Process 1) Default Lossy JPEG 8-bit
1.2.840.10008.1.2.4.51 JPEG Baseline (Process 2 & 4) Default Lossy JPEG 12-bit
1.2.840.10008.1.2.4.57 JPEG Lossless, Nonhierarchical (Processes 14)
1.2.840.10008.1.2.4.70 JPEG Lossless, Nonhierarchical First- Order Prediction
1.2.840.10008.1.2.4.80 JPEG-LS Lossless
1.2.840.10008.1.2.4.81 JPEG-LS Near-Lossless
1.2.840.10008.1.2.4.90 JPEG 2000 Lossless Only
1.2.840.10008.1.2.4.91 JPEG 2000
1.2.840.10008.1.2.4.92 JPEG 2000 Multicomponent Lossless Only
1.2.840.10008.1.2.4.93 JPEG 2000 Multicomponent
1.2.840.10008.1.2.4.94 JPIP Referenced
1.2.840.10008.1.2.4.95 JPIP Referenced Deflate
1.2.840.10008.1.2.5 RLE Lossless
1.2.840.10008.1.2.6.1 RFC 2557 MIME Encapsulation
1.2.840.10008.1.2.4.100 MPEG2 Main Profile Main Level
1.2.840.10008.1.2.4.102 MPEG-4 AVC/H.264 High Profil Level 4.1
1.2.840.10008.1.2.4.103 MPEG-4 AVC/H.264 BD High Profil Level 4.1

Image Manipulations with Javascript

Introduction

Today most computers, graphic cards and monitors can display 16-bit, 24-bit, 32-bit or even 48-bit color depth. The color quality can be selected in the control center of the graphic (video) card.

ATI Radeon Control Center Window

Example : ATI Radeon Control Center Window

8-bit-color

In 8-bit color graphics each pixel is represented by one byte, the maximum number of colors that can be displayed at any one time is 256. There are two forms of 8-bit color graphics. The most common uses a separate palette of 256 colors, where each of the 256 entries in the palette map is given red, green, and blue values. The other form is where the 8 bits directly describe red, green, and blue values, typically with 3 bits for red, 3 bits for green and 2 bits for blue.

16-bit color

With 16-bit color, also called High color, one of the bits of the two bytes is set aside for an alpha channel and the remaining 15 bits are split between the red, green, and blue components, allowing 32,768 possible colors for each pixel. When all 16 bits are used, one of the components (usually green) gets an extra bit, allowing 64 levels of intensity for that component, and a total of 65.536 available colors.

24-bit color

Using 24-bit color, also called True color, computers and monitors can display as many as 16.777.215 different color combinations.

32-bit color

Like 24-bit color, 32-bit color supports 16.777.215 colors with an additional alpha channel to create more convincing gradients, shadows, and transparencies. With the alpha channel 32-bit color supports 4.294.967.296 color combinations.

48-bit color

Systems displaying a billion or more colors are called Deep Color. In digital images, 48 bits per pixel, or 16 bits per each color channel (red, green and blue), is used for accurate processing. For the human eye, it is almost impossible to see any difference between such an image and a 24-bit image.

CLUT

A colour look-up table (CLUT) is a mechanism used to transform a range of input colours into another range of colours. It can be a hardware device built into an imaging system or a software function built into an image processing application.

HDR

High-dynamic-range imaging (HDR) is a set of techniques used in imaging and photography to reproduce a greater dynamic range of luminosity than is possible with standard digital imaging or photographic techniques. The aim is to present the human eye with a similar range of luminance as that which, through the visual system, is familiar in everyday life.

Pixel Image

PixelImage 8 x 8

PixelImage 8×8

To dive into the Image Manipulations with Javascript, we will use the Pixel Image shown left which has 8 x 8 pixels and a color depth of 1 bit. The bit value 0 is associated to the color white, 1 means black. We see later that in real systems the colors are inverted (1 = white, 0 = black). In the next steps we will look how to display this image in a browser with HTML5 and javascript.

The following table shows the pixel data for the image. I used the MathIsFun website to do the binary to hexadecimal and decimal conversion.

rows column bits hexadecimal decimal
1 01111110 7E 126
2 10000001 81 129
3 10100101 A5 165
4 10000001 81 129
5 10011001 99 153
6 10000001 81 129
7 11100111 E7 231
8 00111100 3C 60

We can now use the following code to draw the pixels on a canvas :

<body>
<canvas id="pixelboard" width="512" height="512"></canvas> 
<script>
var myCanvas = document.getElementById("pixelboard");
var myContext = myCanvas.getContext("2d");
myContext.fillStyle = "silver";
myContext.fillRect(0, 0, myCanvas.width, myCanvas.height);
myContext.fillStyle = "black";
// here are the pixel data for the 8 rows
var pixelData = [126, 129, 165, 129, 153, 129, 231, 60];
for (i = 0; i < pixelData.length; i++ ) {
 var base2 = (pixelData[i]).toString(2);
 var p = 7; 
 // set pixels in canvas from right to left
 for (j = (base2.length-1); j >= 0; j-- ) {
 if (base2[j] == 1) {
 myContext.fillRect(p * 64, i * 64, 64, 64);
 } // end if
 p--;
 } // end base2
} // end pixelData
</script>
</body>

Click this PixelData link to see it working. The image is stored in 8 bytes.

PNG Image

To draw the picture in the original size of 8×8 pixels, we change the canvas size

<canvas id="pixelboard" width="8" height="8"></canvas> 

and the code line in the inner loop as follows

myContext.fillRect(p, i, 1, 1);

Click this PixelData link to see it working.

We can save the small Pixel image in the browser with a right mouse click as canvas.png file. The size of this PNG image file is 108 bytes, 100 bytes more than the size of the image stored in our javascript.Thats a lot of overhead. Sort od design overkill !

Let’s have a look inside this file with an HexEditor (HxD from Maël Hörz).

PNG

Anatomy of a small PNG Image File

We can identify the words PNG, IHDR, IDAT and IEND. The PNG format is specified by the W3C. A lite description is available at the FileFormat.Info website. PNG (pronounced “ping”) is a bitmap file format used to transmit and store bitmapped images. PNG supports the capability of storing up to 16 bits (gray-scale) or 48 bits (truecolor) per pixel, and up to 16 bits of alpha data. It handles the progressive display of image data and the storage of gamma, transparency and textual information, and it uses an efficient and lossless form of data compression.

A PNG format file consists of an 8-byte identification signature followed by chunks of data :

  • Header chunk (IHDR) : the header chunk (13 bytes) contains basic information about the image data and must appear as the first chunk, and there must only be one header chunk in a PNG file.
  • Palette chunk (PLTE) : the palette chunk stores the colormap data associated with the image data. This chunk is present only if the image data uses a color palette and must appear before the image data chunk.
  • Image data chunk (IDAT) : the image data chunk stores the actual image data, and multiple image data chunks may occur in a data stream and must be stored in contiguous order.
  • Image trailer chunk (IEND) : the image trailer chunk must be the final chunk and marks the end of the PNG file or data stream.
  • Optional chunks are called ancillary chunks (examples : background, gamma, histogram, transparency, …) and can be inserted before or after the image data chunks. Ten ancillary chunks have been defined in the first PNG version.

Each chunk has the following structure, each chunk has an overhead of 12 bytes :

  • DataLength (4 bytes)
  • ChunkType (4 bytes)
  • Data (number of bytes specified in DataLength)
  • CRC-32 (4 bytes)

The IHDR chunk specifies the following parameters in the 13 data bytes :

  • ImageWidth in pixels (4 bytes)
  • ImageHeight in pixels (4 bytes)
  • BitDepth (1 byte)
  • ColorType (1 byte)
  • Compression (1 byte)
  • Filter (1 byte)
  • Interlace (1 byte)

An analysis of our PixelData PNG image provides the following results :

  • ImageWidth in pixels :  00 00 00 08 (big-endian) > 8 pixels
  • ImageHeight in pixels : 00 00 00 08 (big-endian) > 8 pixels
  • BitDepth : 08 > 8 bit
  • ColorType : 06 > Truecolour with alpha (RGBA)
  • Compression : 00 > default = deflate
  • Filter : 00 > default = adaptive filtering
  • Interlace : 00 > no
  • ImageDataLength : 00 00 00 31 (big-endian) > 49 bytes

In the HexEditor we see that the 49 bytes of deflated image data are :

18 95 63 38 70 E0 C0 7F 06 06 06 AC 18 2A 07 61 
60 C3 50 85 70 95 28 12 18 0A 08 9A 80 EC 16 9C 
0A 70 9A 80 43 27 04 63 15 44 52 0C 00 67 20 8C 41

The image data is zlib-compressed using the deflate algorithm. zlib is specified in RFC1950, deflate is specified in RFC1951. The process is sufficient complex to not do it manually. We can use the javascript pako.js library to decompress the data block. This library was designed by Vitaly Puzrin and Andrey Tupitsin.

Here comes the code :

<!DOCTYPE HTML>
<html>
<head>
 <meta charset="utf-8">
 <title>Inflate byte block of PNG image pixel data with pako.js</title>
 <script type="text/javascript" src="js/pako.js"></script>
</head>
<body>
<h1>Inflate byte block of PNG image pixel data with pako.js</h1>
<div id="main"></div>
 <script type="text/javascript" >
// enter datastream as array
var hexData = [0x18, 0x95, 0x63, 0x38, 0x70, 0xE0, 0xC0, 0x7F, 0x06, 0x06, 
0x06, 0xAC, 0x18, 0x2A, 0x07, 0x61, 0x60, 0xC3, 0x50, 0x85, 0x70, 0x95, 0x28, 
0x12, 0x18, 0x0A, 0x08, 0x9A, 0x80, 0xEC, 0x16, 0x9C, 0x0A, 0x70, 0x9A, 0x80, 
0x43, 0x27, 0x04, 0x63, 0x15, 0x44, 0x52, 0x0C, 0x00, 0x67, 0x20, 0x8C, 0x41];
 // Pako inflate
 var inflateData = pako.inflate(hexData);
// output inflated data
var output = "<p>The lenght of the inflated data sequence is : " 
+ inflateData.length + "bytes.<br/>"; 
 for (i = 0 ; i < 8; i++) {
 for (j = 0 ; j < 33; j++) {
 console.log((i * 33) + j);
 output+= decimalToHexString(inflateData[(i * 33) + j]) + " ";
 } // end for loop j
 output+= "<br/>";
 } // end for loop i
 output+= "</p>";
 element = document.getElementById("main");
 element.innerHTML = output;
 function decimalToHexString(number)
{ if (number < 0)
 { number = 0xFFFFFFFF + number + 1; }
 return number.toString(16).toUpperCase();
}
</script>
</body>
</html>
Byte sequence in PNG image rows

Byte sequence in PNG image rows

The byte sequence of pixel data stored in  PNG images is shown in the left figure.

In our case we have 8 rows with 8 * 4 bytes (RGBA) plus one null byte, giving a total of 8 * 33 = 264 bytes.

Click the inflate link to see the result of the inflate process. The sequence length is really 264 bytes and the structure of the PNG format is visible in the output.

inflating

inflating PNG image data

The RGB hexadecimal values C0 generate grey (white) pixels, the values 0 generate black pixels. The alpha channel is always transparent (hex FF).

Synthesize a PNG image

To synthesize a minimal PNG image with monochrome PixelData, we modify the original canvas.png data as follows :

1. The signature does not change, the bytes in hexadecimal format are :

89 50 4E 47 0D 0A 1A 0A

2. In the header we set the bit depth to 1 (mono-chrome) and the color type to 0 (gray-scale). We get the following byte sequence in hexadecimal format :

00 00 00 0D 49 48 44 52 00 00 00 08 00 00 00 08 01 00 00 00 00

We have several possibilities to calculate the new CRC32 checksum over the header name and the new data :

CRC32 calculation with desktop and online tool

CRC32 calculation with desktop and online tool

Here comes the code for the javascript CRC32 calculation :

<!DOCTYPE HTML>
<html>
<head>
 <meta charset="utf-8">
 <title>Calculate checksum crc32 with SheetJS/js-crc32 
of canvas.png chunks</title>
 <script type="text/javascript" src="js/SheetJS_crc32.js"></script>
</head>
<body>
<h1>Calculate checksum crc32 with SheetJS/js-crc32 of canvas.png chunks</h1>
<div id="main"></div>
 <script type="text/javascript" >
 // calculate crc32 over chunk name and data
// enter datastream as hexadecimal numbers
var charData = [0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 
0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00];
var myCRC32 = CRC32.buf(charData);
var crc = decimalToHexString(myCRC32);
var output = "<p>Here is the signed 32 bit number of the CRC32 : " 
+ myCRC32 + "<br/>Here is the hexadecimal value of the CRC32 : " 
+ crc + "</p>";
 element = document.getElementById("main");
 element.innerHTML = output;
 function decimalToHexString(number)
{  if (number < 0)
   { number = 0xFFFFFFFF + number + 1 }  
   return number.toString(16).toUpperCase();
} // end function
 </script>
</body>
</html>

Click this CRC32 link to see it working. The checksum to add to the IHDR chunk is EC 74 83 26.

Now we tackle the IDAT chunk. We have 8 rows for the PixelData, starting each with a NullByte (filter), followed by 1 byte in each row for the monochrome pixels. That makes a total of 16 bytes. The data length in hexadecial format is 10. We use 1 for black and 0 for white, giving us the following byte sequence :

00 7E 00 81 00 A5 00 81 00 99 00 81 00 E7 00 3C

This byte sequence is deflated with the Pako.js library with the following script :

<!DOCTYPE HTML>
<html>
<head>
 <meta charset="utf-8">
 <title>Deflate byte block of PNG image pixel data with pako.js</title>
 <script type="text/javascript" src="js/pako.js"></script>
</head>
<body>
<h1>Deflate byte block of PNG image pixel data with pako.js</h1>
<div id="main"></div>
 <script type="text/javascript" >
 // enter datastream as numbers
var charData = [0x00, 0x7E, 0x00, 0x81, 0x00, 0xA5, 0x00, 0x81, 0x00, 0x99, 
0x00, 0x81, 0x00, 0xE7, 0x00, 0x3C];
 // Pako deflate
 var deflateData = pako.deflate(charData);
 var output = "<p>The length of the deflated data sequence is : " 
+ deflateData.length + " bytes.<br/>";
 for (i = 0; i < deflateData.length; i++) {
 output+= decimalToHexString(deflateData[i]) + " ";
 } // end for loop i
 output+= "</p>";
 element = document.getElementById("main");
 element.innerHTML = output;
 function decimalToHexString(number)
{ if (number < 0)
 { number = 0xFFFFFFFF + number + 1; }
 return number.toString(16).toUpperCase();
}
</script>
</body>
</html>

Click this deflate link to see the result. The length of the deflated sequence has 21 bytes (hex : 15) and is longer than the original sequence.That happens with very short image sequences.

deflating

deflating PNG image data

There are possibilities to minify the deflated sequence lenght, but this is not our goal. There are several blogs and posts dealing with smallest possible png images.

The last step is the calculation of the CRC32 checksum, same procedure as above. The following crc32 link shows the 4 byte hexadecimal number : EC 01 89 73.

The final byte sequence for the IDAT chunk is displayed hereafter :

00 00 00 15 49 44 41 54 78 9C 63 A8 63 68 64 58 0A C4 33 81 F8 39 83 0D 00 23 
44 04 63 EC 01 89 73 

3. The IEND chunk remains unchanged and has no associated data :

00 00 00 00 49 45 4E 44 AE 42 60 82

To create and display this synthetic PNG image, we copy all the hexadecimal data in our HexEditor and save it as mysynth.png file. To check that the format is right, we can use the pngcheck tool or  load the image in Photoshop. It works.

png_check

Analayse file mysynth.png with pngcheck.exe

PNG in

Open file mysynth.png in Photoshop

Display the PNG image in the Browser

The typical HTML code to display an image in a web browser is

<img src="url" alt="abcde" width="xxx" height="yyy" />

The src attribute specifies the URI (uniform resource identifier) of the image. The most common form of an URI is an URL (uniform resource locator) that is frequently referred as a web address. URIs identify and URLs locate. Every URL is also an URI, but there are URIs which are not URLs.

The URI syntax consists of a URI scheme name (such as “http”, “ftp”, “mailto” or “file”) followed by a colon character, and then by a scheme-specific part. An example of an URI which is not an URL is a dataURI, for example

data:,Hello%20World

The data URI scheme is a URI scheme that provides a way to include data in-line in web pages as if they were external resources. This technique allows normally separate elements such as images and style sheets to be fetched in a single HTTP request rather than multiple HTTP requests, which can be more efficient.

We will use the dataURI to display our synthesized PNG image in a web browser without saving it to an external source. The data URI scheme is defined in RFC 2397 of IETF. URI’s are character strings, therefore we must convert (encode) the image data to ASCII text. The most common conversion is base64, another method is percent encoding.

There are several possibilities to encode our image data in base64 :

Here comes the code for the javascript btoa() conversion :

<!DOCTYPE HTML>
<html>
<head>
 <meta charset="utf-8">
 <title>Display mysynth.png with dataURI</title>
 </head>
<body>
<h1>Display mysynth.png with dataURI</h1>
<div id="main"></div>
 <script type="text/javascript" >
var signature = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]; 
var ihdr = [0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 
0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0xEC, 
0x74, 0x83, 0x26];
var idat = [0x00, 0x00, 0x00, 0x15, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9C, 
0x63, 0xA8, 0x63, 0x68, 0x64, 0x58, 0x0A, 0xC4, 0x33, 0x81, 0xF8, 0x39, 
0x83, 0x0D, 0x00, 
0x23, 0x44, 0x04, 0x63, 0xEC, 0x01, 0x89, 0x73];
var iend = [0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 
0x60, 0x82];
var mysynthPNG = signature.concat(ihdr).concat(idat).concat(iend);
var imageStringBase64 = btoa(String.fromCharCode.apply(null, mysynthPNG));
var mysynthImg=document.createElement("img");
mysynthImg.setAttribute('src', 'data:image/png;base64,' + imageStringBase64);
mysynthImg.setAttribute('alt', 'mysynthPNG');
mysynthImg.setAttribute('height', '8px');
mysynthImg.setAttribute('width', '8px');
document.body.appendChild(mysynthImg);
</script>
</body>
</html>

Click the following base64 link to see the result. The pixel colors are inverted, 1 is white and 0 is black.

Links

The following list provides links to websites with additional informations about image pixel manipulations :