3
votes

I am trying to apply widow width and level filter to JPEG Image which I extracted from DICOM file.

Here is logic I use to process Each Channel of RGB Image fore example I manipulate Red Channel Like below code in Render-Script in android

Example code where I shown how I manipulate Red Channel of Image. (I do same for Green and Blue Channels)

It does manipulate the JPEG Image Widow Width and Level but not sure if its correct way to manipulate DICOM JPEGS if some body know correct way to manipulate RGB JPEGS Window Width and Level with correct pixel processing math please help me as Its result some what (20%) differs from Windows Based DicomViewers ( I know Window Level and Width is for Monochrome Images Only but Some DicomViewers Such as "ShowCase" they do apply such filters on RGB )

    displayMin = (windowLevel- windowWidth/2);
    displayMax = (windowLevel+ windowWidth/2);

    /*Manipulate Red Channel */
    if(current.r < displayMin)
    {
      current.r = 0;
    }
    else if(current.r > displayMax)
    {
       current.r = 1;
    } 
1

1 Answers

3
votes

Your current approach simply truncates the input data to fit the window, which can certainly be useful. However, it doesn't really let you see see the benefit of the window/level, particularly on images greater than 8bpp, because it doesn't enhance any of the details.

You'd typically want to remap the windowed input range (displayMin to displayMax) onto the output range (0 to 1) in some way. I don't think there is a definitive 'correct' approach, although here's a simple linear mapping that I find useful:

if (current.r <= displayMin || displayMin == displayMax)
{
    current.r = 0;
}
else if (current.r >= displayMax)
{
    current.r = 1;
}
else
{
    current.r = (current.r - displayMin) / (displayMax - displayMin);
}

What that's doing is simply taking your restricted window, and expanding it to use the entire colour-space. You can think of it like zooming-in on the details.

(The displayMin == displayMax condition is simply guarding against division-by-zero.)