public unsafe static DataSet GetImage(Bitmap bitmap) { DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); int width = (ushort)bitmap.Width; int height = (ushort)bitmap.Height; dicom.Add(t.Columns, width); dicom.Add(t.Rows, height); dicom.Add(t.PhotometricInterpretation, "MONOCHROME2"); dicom.Add(t.BitsAllocated, 16); dicom.Add(t.BitsStored, 12); short[] pixels = new short[width * height]; System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); PixelData *BitmapPtr = (PixelData *)data.Scan0.ToPointer(); int spacing = data.Stride; int n = 0; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { PixelData *pRGBPixel = (PixelData *)(BitmapPtr + c); pixels[n++] = (short)((int)(pRGBPixel->blue * 0.11 + pRGBPixel->red * 0.3 + pRGBPixel->green * 0.59) << 4); } BitmapPtr = (PixelData *)((byte *)BitmapPtr + spacing); } dicom.Add(t.PixelData, pixels); return(dicom); }
public ucTagAndImage() { InitializeComponent(); var testFile = @"D:\Documents\Dose Report\1.2.840.113564.10001.2016033015344433716-dose report-CBCT.dcm"; var stream = new FileStream(testFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); var dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(stream); foreach (Element element in dicom) { // do not show group length tags if (element.element == 0) { continue; } var node = new TreeListNode { Text = element.GetPath() }; node.SubItems.Add(element.Description); tagTreeList.Nodes.Add(node); FillElement(element, node); } }
public Bitmap LoadBitmap(string fileName) { try { // we should either have a fileName or dataset if (fileName != null && fileName.Length > 0) { Cursor.Current = Cursors.WaitCursor; try { dicom = OtherImageFormats.Read(fileName); } finally { //SetStatus(""); Cursor.Current = Cursors.Default; } } if (dicom == null) { throw new ArgumentException("No fileName or dataset."); } return(LoadBitmap(dicom)); } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } return(null); }
public Bitmap LoadBitmap(EK.Capture.Dicom.DicomToolKit.DataSet elements) { try { dicom = elements; SetIsCtImage(); SetPixelRepresentation(); voilut = GetVOILUT(dicom.Elements); attributes = Utilities.GetAttributes(dicom.Elements); // extract overlays, if any overlay = ExtractOverlays(dicom.Elements); overlays = (overlay != null); return(GetPicture()); } catch (Exception ex) { Logging.Log(ex); throw ex; } return(null); }
private bool SendStorageCommit(string path, ApplicationEntity host, int status) { bool result = true; try { StorageCommitServiceSCU commit = new StorageCommitServiceSCU(); commit.Syntaxes.Add(Syntax.ImplicitVrLittleEndian); commit.Role = Role.Scp; Association association = new Association(); association.AddService(commit); if (association.Open(host)) { if (commit.Active) { try { EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(path); if (status != 0) { dicom.Add(t.RetrieveAETitle, host.Title); // add the FailedSOPSequence Sequence sequence = new Sequence(t.FailedSOPSequence); dicom.Add(sequence); Elements item = sequence.NewItem(); item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPClassUID]); item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPInstanceUID]); item.Add(t.FailureReason, 274); // remove the ReferencedSOPSequence dicom.Remove(t.ReferencedSOPSequence); } result = commit.Report(dicom); Debug.WriteLine("commit done!"); } catch (Exception ex) { result = false; Debug.WriteLine(ex.Message); } } } else { result = false; Debug.WriteLine("\ncan't Open."); } association.Close(); } catch { } RefreshControls(); return(result); }
private void NewBrowser(EK.Capture.Dicom.DicomToolKit.DataSet dicom) { Browser child = new Browser(dicom); child.MdiParent = this; child.WindowState = FormWindowState.Maximized; child.Show(); }
public Viewer(FilmBox page) : this("") { try { this.dicom = OtherImageFormats.RenderPage(page, PictureBox.Size); } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } }
public Viewer(EK.Capture.Dicom.DicomToolKit.DataSet dicom) : this("") { try { this.dicom = dicom; } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } }
private void Browser_Load(object sender, EventArgs e) { try { if (dicom == null) { if (filename != null && filename.Length > 0) { try { if (filename != null && filename.Length > 0) { stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(stream); } } catch (Exception ex) { if (!dicom.Part10Header) { System.Windows.Forms.MessageBox.Show("Unable to parse dicom fragment, " + ex.Message); } else { System.Windows.Forms.MessageBox.Show("Valid Dicom header found. Unable to parse dicom file, " + ex.Message); } } finally { if (stream != null) { stream.Close(); stream.Dispose(); stream = null; } } } else { dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Part10Header = true; } } FillTreeView(); } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } }
private void Export(string path) { try { using (StreamWriter writer = new StreamWriter(path)) { // header writer.Write("\"Filename\""); foreach (String text in mapping) { string[] strings = text.Split(":".ToCharArray()); writer.Write(",\"" + ((strings.Length > 1) ? strings[1] : Dictionary.Instance[strings[0]].Description) + "\""); } writer.WriteLine(); // rows foreach (FileInfo file in files) { EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(file.FullName, 0x7F00); writer.Write("\"" + file.FullName + "\""); foreach (String text in mapping) { string[] strings = text.Split(":".ToCharArray()); string value = String.Empty; try { value = (dicom.ValueExists(strings[0])) ? ToString(dicom[strings[0]]) : String.Empty; } catch (Exception ex) { Logging.Log(LogLevel.Error, String.Format("Export Value: {0}", ex.Message)); } writer.Write(",\"" + value + "\""); } writer.WriteLine(); } } } catch (Exception ex) { Logging.Log(LogLevel.Error, String.Format("Export: {0}", ex.Message)); } }
private void Shift(string filename) { using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)) { EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(stream); stream.Close(); // apply the shift to the image pixels ushort[] pixels = (ushort[])dicom[t.PixelData].Value; for (int n = 0; n < pixels.Length; n++) { pixels[n] = lut[pixels[n]]; } if (AddPixelValuesCheckBox.Checked) { pixels[0] = 0; pixels[1] = (ushort)(maxvalue - 1); } dicom.Set(t.BitsStored, N); dicom.Set(t.HighBit, N - 1); if (AddPixelValuesCheckBox.Checked) { pixels[0] = 0; pixels[1] = (ushort)(maxvalue - 1); dicom.Set(t.SmallestImagePixelValue, (ushort)0); dicom.Set(t.LargestImagePixelValue, (ushort)(maxvalue - 1)); } else { dicom.Set(t.SmallestImagePixelValue, (ushort)(maxvalue / 4)); dicom.Set(t.LargestImagePixelValue, maxvalue - maxvalue / 4); } dicom.Set(t.WindowWidth, maxvalue / 2); dicom.Set(t.WindowCenter, maxvalue / 2); FileInfo info = new FileInfo(filename); String text = filename.Replace(info.Extension, ""); text += "a" + info.Extension; dicom.Write(text); } }
private string ReadDicom(FileInfo file) { string error = "\uFFFD"; StringBuilder line = new StringBuilder(); try { EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(file.FullName, 0x5000); for (int n = 0; n < mapping.Count; n++) { String text = mapping[n]; string[] strings = text.Split(":".ToCharArray()); string value = String.Empty; try { value = (dicom.ValueExists(strings[0])) ? ToString(dicom[strings[0]]) : String.Empty; } catch (Exception ex) { value = error; Logging.Log(LogLevel.Error, String.Format("ReadDicom Value: {0}", ex.Message)); } if (n > 0) { line.Append("|"); } line.Append(value); } } catch (Exception ex) { line = new StringBuilder(""); for (int n = 0; n < mapping.Count; n++) { if (n > 0) { line.Append("|"); } line.Append(error); } Logging.Log(LogLevel.Error, String.Format("ReadDicom: {0}", ex.Message)); } return(line.ToString()); }
private void Viewer_Load(object sender, EventArgs e) { try { // we should either have a filename or dataset if (filename != null && filename.Length > 0) { Cursor.Current = Cursors.WaitCursor; try { dicom = OtherImageFormats.Read(filename); } finally { SetStatus(""); Cursor.Current = Cursors.Default; } } if (dicom == null) { throw new ArgumentException("No filename or dataset."); } SetIsCtImage(); SetPixelRepresentation(); voilut = GetVOILUT(dicom.Elements); attributes = Utilities.GetAttributes(dicom.Elements); // if the image is large, lets reduce memory consumption and decimate the source if (attributes.buffer.Length > 20000000) { ReduceImage(dicom.Elements); } // extract overlays, if any overlay = ExtractOverlays(dicom.Elements); overlays = (overlay != null); GetPicture(); } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } }
private void Form1_Load(object sender, EventArgs e) { var testFile = @"D:\Documents\Dose Report\1.2.840.113564.10001.2016033015344433716-dose report-CBCT.dcm"; var stream = new FileStream(testFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); var dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(stream); foreach (Element element in dicom) { // do not show group length tags if (element.element == 0) { continue; } //TreeNode node = root.Nodes.Add(element.GetPath() + " tag", Title(element)); //FillElement(element, node); } }
private void LoadTagList(EK.Capture.Dicom.DicomToolKit.DataSet elements) { try { foreach (Element element in elements) { // do not show group length tags if (element.element == 0) { continue; } var node = CreateSimpleNode(element); doseReportTreeList.Nodes.Add(node); AddChild(element, node); node.ExpandAll(); } } catch (Exception ex) { MessageBox.Show((ex.Message)); } }
public Browser(string filename) { try { this.filename = filename; if (File.Exists(filename)) { FileInfo info = new FileInfo(filename); if (".txt" == info.Extension.ToLower()) { dicom = BatchEditor.ProcessFile(filename); dicom.Part10Header = true; dicom.TransferSyntaxUID = Syntax.ExplicitVrLittleEndian; } } InitializeComponent(); // set the Title after the component is initialized. SetTitles(); } catch (Exception ex) { MessageBox.Show(Logging.Log(ex)); } }