I am not an experienced programmer, just need to add a DICOM viewer to my VS2010 project. I can display the image in Windows Forms, however can't figure out how to change the window center and width. Here is my script:
DicomImage image = new DicomImage(_filename);
int maxV = image.NumberOfFrames;
sbSlice.Maximum = maxV - 1;
image.WindowCenter = 7.0;
double wc = image.WindowCenter;
double ww = image.WindowWidth;
Image result = image.RenderImage(0);
DisplayImage(result);
It did not work. I don't know if this is the right approach.
I looked at the code and it looked extremely buggy. https://github.com/rcd/fo-dicom/blob/master/DICOM/Imaging/DicomImage.cs
In the current buggy implementation setting the
WindowCenterorWindowWidthproperties has no effect unless Dataset.Get(DicomTag.PhotometricInterpretation) is eitherMonochrome1orMonochrome2duringLoad(). This is already ridiculous, but it still cannot be used because the_renderOptionsvariable is only set in a single place and is immediately used for the_pipelinecreation (not giving you chance to change it using theWindowCenterproperty). Your only chance is the grayscale_renderOptionsinitialization:_renderOptions = GrayscaleRenderOptions.FromDataset(Dataset);.The current solution: Your dataset should have
DicomTag.WindowCenterset appropriatelyDicomTag.WindowWidth != 0.0DicomTag.PhotometricInterpretation == Monochrome1orMonochrome2The following code accomplishes that:
The best solution: Wait while this buggy library is fixed.