How to load colors from a .lut file?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
gmbros
Posts: 5
Joined: Sat, 2011-08-20, 04:00

How to load colors from a .lut file?

#1 Post by gmbros »

Dear ladies and gentlemen,

We have noticed that there are several .lut files shipped with DICOMScope, such as "darken256us.lut". We want to get the colors info from these .lut files with Delphi code, so first we need to find the code in DICOMScope that for loading these color data from .lut file, and then translate these code to Delphi Pascal code.

Unfortunately, we can hardly find the code for loading these files in DICOMScope. And we noticed that these .lut files used presentation lut encoding algorithm. Isn't it?

Please point us how to load these .lut files, that is, loading the colors that in a .lut file and store these RGB components in an array. It is better if you could show us some code, or point us which source code file in DICOMScope contains such algorithm.

Thanks in advance.

Best regards,

gmbros

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

#2 Post by J. Riesmeier »

These are LUT files are in fact DICOM files, so you can use dcmdump to show their contents. For example:

Code: Select all

# dcmdump (1/1): darken256us.lut

# Dicom-File-Format

# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 194                                      #   4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
(0002,0002) UI [1.2.276.0.7230010.3.1.0.1]              #  26, 1 MediaStorageSOPClassUID
(0002,0003) UI [1.2.276.0.7230010.3.4.2139363186.4680.938003119.1] #  50, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =LittleEndianExplicit                    #  20, 1 TransferSyntaxUID
(0002,0012) UI [1.2.276.0.7230010.3.0.3.4.0]            #  28, 1 ImplementationClassUID
(0002,0013) SH [OFFIS_DCMTK_340]                        #  16, 1 ImplementationVersionName

# Dicom-Data-Set
# Used TransferSyntax: Little Endian Explicit
(2050,0010) SQ (Sequence with undefined length #=1)     # u/l, 1 PresentationLUTSequence
  (fffe,e000) na (Item with undefined length #=3)         # u/l, 1 Item
    (0028,3002) US 256\0\12                                 #   6, 3 LUTDescriptor
    (0028,3003) LO [Presentation LUT with descriptor 256/0/12] #  42, 1 LUTExplanation
    (0028,3006) US 16\16\16\16\16\32\32\48\48\48\64\64\80\96\96\112\112\128\144\160... # 512,256 LUTData
  (fffe,e00d) na (ItemDelimitationItem)                   #   0, 0 ItemDelimitationItem
(fffe,e0dd) na (SequenceDelimitationItem)               #   0, 0 SequenceDelimitationItem
Btw, these LUTs do not contain any colors (but monochrome/gray values only).

gmbros
Posts: 5
Joined: Sat, 2011-08-20, 04:00

#3 Post by gmbros »

Hello Mr. Riesmeier,

Many thanks for your reply.

Yes, we could viewing the content of these .lut files with dcmdump.exe. But how can we extract these grayscale values from such files?

We have noticed that in the content that shown by dcmdump.exe, there was a one:

(0028,3006) US 16\16\16\16\16\32\32\48\48\48\64\64\80\96\96\112\112\128\144\160... # 512,256

They are seems like the grayscale values, but not the complete list of them. How can we write code to extract them out to an array to store them?

We found that in source file "dcmmklut.cxx" from dcmtk toolkit, there are some code for manipulating lookup tables. Can we extract those grayscale values out with these code? To a Delphi programmer, the code is difficult to translate. We just know basic of C/C++. We want to translate the C/C++ code to Delphi Pascal.

Could you please give us some suggestions on how to extract the grayscale values from a .lut file and save these values in an array? We need to extract them and save them in another file format to disk.

Thank you very much.

Best regards,

gmbros

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

#4 Post by J. Riesmeier »

In order to load a DICOM file (like this LUT file) with DCMTK, you can simply use DcmFileFormat::loadFile(). The complete code that is used for DICOMscope can be found in DVInterface::selectDisplayPresentationLUT().
They are seems like the grayscale values, but not the complete list of them.
No, because dcmdump by default shortens long elements values. Use option +L in order to also dump long element values completely.

gmbros
Posts: 5
Joined: Sat, 2011-08-20, 04:00

#5 Post by gmbros »

Hello Mr. Riesmeier,

Many thanks for your help. We will try to translate the code. If we encounter any problems, we will be back for finding helps.

Best regards,

gmbros

gmbros
Posts: 5
Joined: Sat, 2011-08-20, 04:00

#6 Post by gmbros »

Hi,
J. Riesmeier wrote: Btw, these LUTs do not contain any colors (but monochrome/gray values only).
You have said that these LUTs contain monochrome/gray values only. And we have noticed that these values are from 16 to 4031. These values are weird to us. Because as far as we are concerned, a gray value should be from 0 to 255, it has 256 levels of grayscale. But these values are out of range from our understanding.

Even if we have extract these data out from the .lut file, we don't know how to convert them to corresponding RGB values.

The encoding of RGB values should be #BBGGRR in hexidecimal. So if the R, G, B components have same values then we got a gray color. For example:

R = 255 / G = 255 / B = 255, we got a grayscale of white, the color value should be #FFFFFF,

R = 127 / G = 127 / B = 127, we got a grayscale of gray, the color value should be #7F7F7F,

etc.

If we got a value from .lut, such as 16, 32, 48, 64, ... 4015 or 4031, what gray color of this value stands for?

Thanks in advance.

Best regards,

gmbros

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

#7 Post by J. Riesmeier »

First of all, the stucture of these LUT tables is described in part 3 of the DICOM standard. You should really read that!
You have said that these LUTs contain monochrome/gray values only. And we have noticed that these values are from 16 to 4031. These values are weird to us. Because as far as we are concerned, a gray value should be from 0 to 255, it has 256 levels of grayscale. But these values are out of range from our understanding.
The number of bits per entry is defined by the third value of the LUT Descriptor, i.e. in this case 12.
Even if we have extract these data out from the .lut file, we don't know how to convert them to corresponding RGB values.
Usually, gray values are converted to RGB values by setting the individual RGB components of a value to the gray value (e.g. 128/128/128). Of course, if the input value has more that 8 bit you will probably have to down-scale the input value ...

gmbros
Posts: 5
Joined: Sat, 2011-08-20, 04:00

#8 Post by gmbros »

Hi,

Many thanks for you helps. We will read the standard of DICOM carefully.

Best regards,

gmbros

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest