private BitmapSource ReadDicomFile(string fileName, int minWin, int maxWin) { dd.DicomFileName = fileName; List <ushort> pixels16 = new List <ushort>(); int imageWidth; int imageHeight; int bitDepth; int samplesPerPixel; TypeOfDicomFile typeOfDicomFile = dd.typeofDicomFile; if (typeOfDicomFile == TypeOfDicomFile.Dicom3File || typeOfDicomFile == TypeOfDicomFile.DicomOldTypeFile) { imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; samplesPerPixel = dd.samplesPerPixel; if (samplesPerPixel == 1 && bitDepth == 16) { pixels16.Clear(); dd.GetPixels16(ref pixels16); return(BitmapHelper.ToBitmapImage(pixels16.ToArray(), imageWidth, imageHeight, minWin, maxWin)); } else { MessageBox.Show("Unsupported bits per pixel number (only 16bpp supported)"); } } else { if (typeOfDicomFile == TypeOfDicomFile.DicomUnknownTransferSyntax) { MessageBox.Show("Invalid dicom file"); } else { MessageBox.Show("Invalid file"); } return(null); } return(null); }
private BitmapSource ReadDicomFile(string fileName, out int minWin, out int maxWin) { dd.DicomFileName = fileName; List <ushort> pixels16 = new List <ushort>(); int imageWidth; int imageHeight; int bitDepth; int samplesPerPixel; double winCentre; double winWidth; maxWin = 0; minWin = 0; TypeOfDicomFile typeOfDicomFile = dd.typeofDicomFile; if (typeOfDicomFile == TypeOfDicomFile.Dicom3File || typeOfDicomFile == TypeOfDicomFile.DicomOldTypeFile) { imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; samplesPerPixel = dd.samplesPerPixel; if (samplesPerPixel == 1 && bitDepth == 16) { pixels16.Clear(); dd.GetPixels16(ref pixels16); int minPixelValue = pixels16.Min(); int maxPixelValue = pixels16.Max(); if (Math.Abs(winWidth) < 0.001) { winWidth = maxPixelValue - minPixelValue; } if ((winCentre == 0) || (minPixelValue > winCentre) || (maxPixelValue < winCentre)) { winCentre = (maxPixelValue + minPixelValue) / 2; } maxWin = Convert.ToInt32(winCentre + 0.5 * winWidth); minWin = maxWin - Convert.ToInt32(winWidth); return(BitmapHelper.ToBitmapImage(pixels16.ToArray(), imageWidth, imageHeight, minWin, maxWin)); } else { MessageBox.Show("Unsupported bits per pixel number (only 16bpp supported)"); } } else { if (typeOfDicomFile == TypeOfDicomFile.DicomUnknownTransferSyntax) { MessageBox.Show("Invalid dicom file"); } else { MessageBox.Show("Invalid file"); } return(null); } return(null); }