private static IEnumerable <Meta> Meta(Stream str) { var d = new DicomDecoder(); d.Init(str); return(d.GetMeta()); }
public MainWindow() { InitializeComponent(); DataContext = this; dd = new DicomDecoder(); }
public Task <Stream> Render(Stream dicomStream) { var decoder = new DicomDecoder(); decoder.Init(dicomStream); var stream = new MemoryStream(); decoder.CreateImage16().Save(stream, ImageFormat.Png); stream.Position = 0; return(Task.FromResult <Stream>(stream)); }
public MainForm() { InitializeComponent(); dd = new DicomDecoder(); pixels8 = new List <byte>(); pixels16 = new List <ushort>(); pixels24 = new List <byte>(); imageOpened = false; signedImage = false; maxPixelValue = 0; minPixelValue = 65535; }
public static Task <Stream> Render(Stream dicomStream, out IEnumerable <Meta> meta) { var decoder = new DicomDecoder(); decoder.Init(dicomStream); var stream = new MemoryStream(); decoder.CreateImage16().Save(stream, ImageFormat.Png); stream.Position = 0; meta = decoder.GetMeta(); return(Task.FromResult <Stream>(stream)); }
protected void Page_Load(object sender, EventArgs e) { pixels16 = new List <ushort>(); Imagemri im = new Imagemri(); DicomDecoder dd = new DicomDecoder(); dd.DicomFileName = "C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\IM_0076"; imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; bool result = dd.dicomFileReadSuccess; if (result == true) { im.NewImage = true; if (bitDepth == 16) { pixels16.Clear(); dd.GetPixels16(ref pixels16); byte[] buffer = new byte[pixels16.Count * 2]; byte[] temp; ByteConverter d = new ByteConverter(); int j = 0; for (int i = 0; i < pixels16.Count; i++) { temp = System.BitConverter.GetBytes(pixels16[i]); buffer[j++] = temp[0]; buffer[j++] = temp[1]; } if (winCentre == 0 && winWidth == 0) { winWidth = 4095; winCentre = 4095 / 2; } } im.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true); Response.ContentType = "image/png"; im.bmp.Save("C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\m.jpeg", ImageFormat.Png); Response.WriteFile("C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\m.jpeg"); } }
static void Main(string[] args) { var decoder = new DicomDecoder(); decoder.Init(File.OpenRead(@"C:\Users\Reality_Shift\Desktop\0.dcm")); decoder.dicomInfo. Zip(decoder.GetMeta(), (f, second) => $">>{f}<< >>{second}<<") .ToList() .ForEach(Console.WriteLine); var bmp = decoder.CreateImage16(); try { bmp.Save("lol.png", ImageFormat.Png); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } Console.ReadKey(); }
public int SaveImage(string Path, string path) { DirectoryInfo d = new DirectoryInfo(Path); FileInfo[] files = d.GetFiles(); int i = 1; foreach (FileInfo f in files) { string PathSave = HttpContext.Current.Server.MapPath("~/DicomImage/" + path); if (!Directory.Exists(PathSave)) { Directory.CreateDirectory(PathSave); } Class.File file = new Class.File(); file.NameFile = f.Name; file.TypeFile = f.Extension; DicomDecoder dd = new DicomDecoder(); dd.DicomFileName = f.FullName; double winCentre = dd.windowCentre; double winWidth = dd.windowWidth; int samplesPerPixel = dd.samplesPerPixel; bool signedImage = dd.signedImage; int minPixelValue = 1; int maxPixelValue = 0; PathSave += i + ".png"; TypeOfDicomFile typeOfDicomFile = dd.typeofDicomFile; int imageWidth = dd.width; int imageHeight = dd.height; bmp = new Bitmap(imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); dd.GetPixels8(ref pixels8); dd.GetPixels16(ref pixels16); dd.GetPixels24(ref pixels24); if (pixels8 != null) { minPixelValue = pixels8.Min(); maxPixelValue = pixels8.Max(); // Bug fix dated 24 Aug 2013 - for proper window/level of signed images // Thanks to Matias Montroull from Argentina for pointing this out. if (dd.signedImage) { winCentre -= char.MinValue; } if (Math.Abs(winWidth) < 0.001) { winWidth = maxPixelValue - minPixelValue; } if ((winCentre == 0) || (minPixelValue > winCentre) || (maxPixelValue < winCentre)) { winCentre = (maxPixelValue + minPixelValue) / 2; } ResetValues(winWidth, winCentre); pix8 = pixels8; ComputeLookUpTable8(); CreateImage8(imageWidth, imageHeight); } else if (pixels16 != null) { minPixelValue = pixels16.Min(); maxPixelValue = pixels16.Max(); // Bug fix dated 24 Aug 2013 - for proper window/level of signed images // Thanks to Matias Montroull from Argentina for pointing this out. if (dd.signedImage) { winCentre -= short.MinValue; } if (Math.Abs(winWidth) < 0.001) { winWidth = maxPixelValue - minPixelValue; } if ((winCentre == 0) || (minPixelValue > winCentre) || (maxPixelValue < winCentre)) { winCentre = (maxPixelValue + minPixelValue) / 2; } ResetValues(winWidth, winCentre); pix16 = pixels16; ComputeLookUpTable16(); CreateImage16(imageWidth, imageHeight); } else if (pixels24 != null) { minPixelValue = pixels8.Min(); maxPixelValue = pixels8.Max(); // Bug fix dated 24 Aug 2013 - for proper window/level of signed images // Thanks to Matias Montroull from Argentina for pointing this out. if (dd.signedImage) { winCentre -= char.MinValue; } if (Math.Abs(winWidth) < 0.001) { winWidth = maxPixelValue - minPixelValue; } if ((winCentre == 0) || (minPixelValue > winCentre) || (maxPixelValue < winCentre)) { winCentre = (maxPixelValue + minPixelValue) / 2; } ResetValues(winWidth, winCentre); pix24 = pixels24; ComputeLookUpTable8(); CreateImage24(imageWidth, imageHeight); } i++; if (bmp != null) { bmp.Save(PathSave, ImageFormat.Png); } } return(i); }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (FileUpload1.HasFile) { string filename = "C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\" + FileUpload1.FileName; string filedir = "C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\"; FileUpload1.SaveAs("C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\" + FileUpload1.FileName); pixels16 = new List <ushort>(); Imagemri im = new Imagemri(); DicomDecoder dd = new DicomDecoder(); dd.DicomFileName = filename; imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; bool result = dd.dicomFileReadSuccess; if (result == true) { im.NewImage = true; if (bitDepth == 16) { pixels16.Clear(); dd.GetPixels16(ref pixels16); byte[] buffer = new byte[pixels16.Count * 2]; byte[] temp; ByteConverter d = new ByteConverter(); int j = 0; for (int i = 0; i < pixels16.Count; i++) { temp = System.BitConverter.GetBytes(pixels16[i]); buffer[j++] = temp[0]; buffer[j++] = temp[1]; } if (winCentre == 0 && winWidth == 0) { winWidth = 4095; winCentre = 4095 / 2; } } im.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true); string index = ""; foreach (string stt in dd.dicomInfo) { if (stt.Contains("Patient's Weight")) { index = stt; } } string wii = index.Split(':')[1]; foreach (string stt in dd.dicomInfo) { if (stt.Contains("Patient's Name")) { index = stt; } } string pn = index.Split(':')[1];; AForge.Imaging.Filters.Grayscale g1 = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap imagew = g1.Apply(im.bmp); int thresholding = (int)((dd.windowWidth - dd.windowCentre) * 255 / dd.windowWidth); AForge.Imaging.Filters.Threshold thf = new AForge.Imaging.Filters.Threshold(thresholding); Bitmap ther = thf.Apply(imagew); BlobCounter blobCounter = new BlobCounter(ther); Blob[] blobs = blobCounter.GetObjects(ther, false); ImageStatistics img; AForge.Imaging.Filters.GrayscaleToRGB d1 = new GrayscaleToRGB(); Bitmap bm = d1.Apply(imagew); Edges s = new Edges(); Graphics gg = Graphics.FromImage(bm); string ss = null; Bitmap myImage = null; Blob b; int count = 0; string locc = ""; foreach (Blob blob in blobs) { img = new ImageStatistics(blob.Image); double perc = ((double)img.PixelsCountWithoutBlack / (double)img.PixelsCount) * 100; if (blob.Image.Size.Height > 20 && blob.Image.Size.Width > 20 && perc > 35) { b = blob; ImageStatistics st = new ImageStatistics(b.Image); Bitmap pp = s.Apply(b.Image); ChannelFiltering c = new ChannelFiltering(new IntRange(0, 255), new IntRange(0, 0), new IntRange(0, 0)); Bitmap pp2 = d1.Apply(pp); c.ApplyInPlace(pp2); pp2.MakeTransparent(Color.Black); gg.DrawImage(pp2, b.Rectangle); gg.Flush(); myImage = im.bmp.Clone(b.Rectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb); ss = ((double)(st.PixelsCountWithoutBlack) * (double)dd.pixelHeight * dd.pixelWidth).ToString(); locc = (b.Rectangle.Location.X * dd.pixelWidth).ToString() + "mm," + (b.Rectangle.Location.Y * dd.pixelHeight).ToString() + "mm"; count++; } }//end foreach bm.Save(filedir + FileUpload1.FileName + ".png", ImageFormat.Png); records r = new records(); recordsTableAdapters.recordsTableAdapter ta = new recordsTableAdapters.recordsTableAdapter(); ta.InsertRecord(pn, wii, FileUpload1.FileName, FileUpload1.FileName + ".png", "", ss, locc); } } }