You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using fo-dicom to render images and change the window width and center of the images. All works great.
I have a scenario where i dont have the dicom file and yet, and i need to apply the window width and center.
I have looked at the fo-dicom code and I see that we have Modality LUT class that overrides indexer that transforms the pixel value by applying rescale slope and intercept..
This is then used while rendering the image.
public void Render(ILUT lut, int[] output)
{
var data = Data;
if (lut == null)
{
//.........
}
else
{
Parallel.For(0, Height, y =>
{
for (int i = Width * y, e = i + Width; i < e; i++)
{
output[i] = (int)lut[data[i]];
}
}
);
}
}
I would like to know where exactly the window width and center are applied?
I would have expected following code somewhere to apply ww/wl..
public byte[] AdjustWindowWidthAndLevel(byte[] image, int width, int height, ushort newWindowWidth, ushort newWindowLevel, ushort maxPixelValue)
{
byte[] adjustedImage = new byte[image.Length];
// Calculate the scaling factor for adjusting pixel values
double scalingFactor = (double)newWindowWidth / (double)maxPixelValue;
// Adjust the pixel values based on the new window width and level
for (int i = 0; i < image.Length; i += 2)
{
ushort pixelValue = BitConverter.ToUInt16(image, i);
// Apply window level adjustment
int adjustedPixelValue = pixelValue - newWindowLevel;
// Apply window width adjustment
adjustedPixelValue = (int)Math.Round(adjustedPixelValue * scalingFactor);
// Clamp the adjusted pixel value within the valid range
adjustedPixelValue = Math.Max(0, Math.Min(adjustedPixelValue, maxPixelValue));
byte[] adjustedPixelBytes = BitConverter.GetBytes((ushort)adjustedPixelValue);
adjustedImage[i] = adjustedPixelBytes[0];
adjustedImage[i + 1] = adjustedPixelBytes[1];
}
return adjustedImage;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using fo-dicom to render images and change the window width and center of the images. All works great.
I have a scenario where i dont have the dicom file and yet, and i need to apply the window width and center.
I have looked at the fo-dicom code and I see that we have Modality LUT class that overrides indexer that transforms the pixel value by applying rescale slope and intercept..
This is then used while rendering the image.
I would like to know where exactly the window width and center are applied?
I would have expected following code somewhere to apply ww/wl..
Where can i find this in fo-dicom code??
Beta Was this translation helpful? Give feedback.
All reactions