Slow Dicom->BMP rendering

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Slow Dicom->BMP rendering

#1 Post by bluergost »

Hi,
I am trying to render dicom into bmp using dcm2pnm.exe and dcmdjp2k_e.exe. But the rendering is slow(2 sec 83 millisecond). It is fast for test files that I found online but in the actual image, it is quite slow.
After closer inspection, I found that most of the render time is taken by the dcmdjp2k converting into <dicom file with decompressed JPEG 2000 image>.
I was using an 8.06 MB CR modality image. An application named Stella takes less than 1 second to open this image. So, my goal is also to render within that amount of time. I was wondering whether there is a way to make dcmdjp2k faster Or skip it.
Since I still do not have the full paid package I can not say for sure. But to me, it seems like the conversion to decompressed dicom file by dcmdjp2k for unsupported formats is a mandatory step for DCMTK.


The rendering steps are:
<dicom file with compressed JPEG 2000 image> → dcmdjp2k → <dicom file with decompressed JPEG 2000 image> → dcm2pnm → <bmp file>
Here is the batch file content that I am using for rendering and measuring the execution time.

Code: Select all

@echo off
setlocal

rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%


cd /D "%~dp0"

set dicomFilesDirectory=DicomFiles
set decompressedFilesDirectory=DecompressedFiles
set renderedFilesDirectory=RenderedFiles

set dicomFilePath=%dicomFilesDirectory%\tf-1.dcm
set decompressedFilePath=%decompressedFilesDirectory%\tf-1.dcm
set renderedFilePath=%renderedFilesDirectory%\tf-1.bmp

del %decompressedFilePath%
del %renderedFilePath%

rem here begins the command you want to measure
dir /s > nul

dcmdjp2k_e.exe %dicomFilePath% %decompressedFilePath%

dcm2pnm.exe --write-bmp %decompressedFilePath% %renderedFilePath%

rem here ends the command you want to measure

set ENDTIME=%TIME%

rem output as time
echo STARTTIME: %STARTTIME%
echo ENDTIME: %ENDTIME%

rem convert STARTTIME and ENDTIME to centiseconds
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)
set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)

rem calculating the duratyion is easy
set /A DURATION=%ENDTIME%-%STARTTIME%

rem we might have measured the time inbetween days
if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME%

rem now break the centiseconds down to hors, minutes, seconds and the remaining centiseconds
set /A DURATIONH=%DURATION% / 360000
set /A DURATIONM=(%DURATION% - %DURATIONH%*360000) / 6000
set /A DURATIONS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000) / 100
set /A DURATIONHS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000 - %DURATIONS%*100)

rem some formatting
if %DURATIONH% LSS 10 set DURATIONH=0%DURATIONH%
if %DURATIONM% LSS 10 set DURATIONM=0%DURATIONM%
if %DURATIONS% LSS 10 set DURATIONS=0%DURATIONS%
if %DURATIONHS% LSS 10 set DURATIONHS=0%DURATIONHS%

rem outputing
echo STARTTIME: %STARTTIME% centiseconds
echo ENDTIME: %ENDTIME% centiseconds
echo DURATION: %DURATION% in centiseconds
echo %DURATIONH%:%DURATIONM%:%DURATIONS%,%DURATIONHS%



pause

endlocal
goto :EOF
Screenshot of the folder structure:
Image

Screenshot of the rendering time:
Image

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1437
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Slow Dicom->BMP rendering

#2 Post by Marco Eichelberg »

Well, the reason why JPEG 2000 has never achieved widespread usage is the fact that the compression algorithm requires much more memory and time than, for example, classic JPEG. So in comparison to JPEG, JPEG 2000 will always be slow, and there is no way to avoid that.
Of course there are faster and slower implementations of the JPEG 2000 encoder and decoder. DCMJP2K supports two different decoders, one based on the JasPer library and one based on the OpenJPEG library. If another product is much faster in opening the image, then it is probably using a different JPEG 2000 encoder, most likely "Kakadu", which is known for its performance. Unfortunately, DCMJP2K does not support Kakadu.

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

Re: Slow Dicom->BMP rendering

#3 Post by J. Riesmeier »

Also, decompressing the JPEG 2000-compressed image first to an uncompressed DICOM image and storing it as a DICOM file in the file system before processing the uncompressed DICOM file with dcm2pnm is probably not the most efficient way of doing it.

bluergost
Posts: 7
Joined: Wed, 2023-01-25, 12:59

Re: Slow Dicom->BMP rendering

#4 Post by bluergost »

J. Riesmeier wrote: Thu, 2023-02-02, 12:46 Also, decompressing the JPEG 2000-compressed image first to an uncompressed DICOM image and storing it as a DICOM file in the file system before processing the uncompressed DICOM file with dcm2pnm is probably not the most efficient way of doing it.
Is it possible to chain the process in the console app without saving the intermediary file in the storage?
I assume it is possible via source code/library.

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

Re: Slow Dicom->BMP rendering

#5 Post by J. Riesmeier »

I assume it is possible via source code/library.
This is one option. Another one would be to write the output of dcmdjp2k to stdout and pipe the data to dcm2pnm, but this would require the latest development snapshot of both tools.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest