How to convert Dicom to BMP image in C#? - c#

I am currently using the evil-dicom library for opening DICOM files in c#. I am able to access the dicom file with:
var dcm = DICOMObject.Read('dicomfilename');
Then open up the pixel stream using
dcm.PixelStream
How can I save the pixelstream as a bmp image?

I never used the toolkit; but at least till Oct-2014, author of the toolkit was saying following:
Evil DICOM does not have any image classes to help with this. While that might seem strange to not include image tools in a DICOM library, it is not the original intent of the the library. Evil DICOM is more for manipulating and analysis of DICOM data. I used to have some image parts in the old library which I believe is still available on SourceForge. You can take a look, but the PixelData tag has the raw bits to put together an image. .NET has several classes that can help with that, but I don't have anything to write here in this post. If I get some time, I will write a blog post about how to do it on the website (rexcardan.com).
Source: GitHub
Apparently, it was not original intent of the toolkit to include imaging support in toolkit. Not sure if this is changed since then. Author was planning to write an article to achieve this through DotNet; not sure if he wrote any then after. Old library from SourceForge may create other issues as it might not have been updated since long.
You can find some example code here.

Related

Converting pdf to tiff using C# .net 3.0 or less without 3rd party libraries?

There are several SO posts and googling which did not really help much with my question. So here I go again.
I need to convert a PDF to a single tiff image (multi-page tiff obviously). I have figured out the tiff creation part. But the issue is with extracting a image/bitmap from pdf. Of course c# .net does not have the functions, but there should be way to do it.
On why I dont want to use third party libraries, its because they are not free - some may be, but for security reasons it may not be usable in all environments. And more than everything just curious how to do it and in some posts this question is being treated as a sin :).
Any proper methods/ideas or where to start would be helpful. I would prefer WPF based solutions than GDI+ based, as I have seen issues with GDI+ tiff creation solution on windows servers . I was of the idea that creating pdf is more difficult and of course I can understand if it was easy it should have been in .net already.
Edit: Also for a starter, a pdf which contains a simple format would be nice. Not necessary that it should support every type of pdf.
Even with 3rd party it's not going to be easy :) Convert a PDF into a series of images using C# and GhostScript

Is there any alternate way to processing DICOM images using WPF in C# without any third party/Library?

I started working in a new project with a big challenge. I am working in a medical project and in that I have to read DICOM images and process the image with its properties. I gathered some basic knowledge on DICOM and PACS. As I worked on WPF around 2 years of my career so I choose to do this project using C# and WPF. I googled a lot and even I went through many articles in SO and also in codeproject, every where I found they used some libraries/ third party tools like:
gdcm , LEADTOOLS , ClearCanvas
Can any body suggest me any alternate way of doing DICOM Image processing without using any third party/library or is it impossible without using libraries/third party ?
I have gone through the link for choose a best suitable library for DICOM image processing, but looking for an alternate way to solving this.Please feel free to suggest which is the best and more flexible library from the above list only if there is not any alternate way to achieve the task.
Any idea, link, suggestion or any initiation will be appreciated, thanks in advance.
In one way or another the third-party libraries are also created from scratch, so of course it is possible to create a DICOM image processing solution without relying on any third-party libraries. Using whole or parts of an open-source library will most certainly take you to a functional solution in considerably shorter time, though.
One third-party library that is mentioned in the link you are referring to is mdcm. This is a relatively light-weight open-source library with support for WPF (and Silverlight). If you want to, I am pretty sure you should be able to extract those parts from this library that are relevant to your project.
Another light-weight library is Evil DICOM. I am not completely sure that this library has very much image processing functionality, though.
UPDATE MAY 31: SUMMARY OF DISCUSSION
mdcm is an open-source library under the LGPL license. An example of image rendering usage is given in the SL.DicomToXml (Silverlight) application, equally applicable to WPF applications. In the code-behind of the MainPage, fileNameButton_Click method, there is code to demonstrate DICOM image file loading and rendering.
There is currently no up-to-date binary distribution of mdcm available, but it should be fairly easy to build required libraries from the solution in the mdcm repository. Source code can either be obtained using a Git client or by downloading the latest revision by clicking on the ZIP button on the repository home page.
If you need to get more acquainted with DICOM image processing details, it is probably good to start by having a look at the DICOM Standard itself, and also to parse a DICOM image file to get the feeling for what information it contains. A good starting point is the official DICOM homepage. A quick introduction with links to software is given here. There is also a general, more lengthy tutorial available here.

Decoding a PCX image in c# to display as bitmap

I have been trying to create a decoder that will stream through a pcx file and display it on screen as a bitmap. I have managed to get the information from the image header by using a binary reader, but I have now reached the part that seems to take the least amount of code, yet is also the hardest: creating an array of pixels.
I understand that i may need to add two embeddded for loops to process the data. I have looked at some C and C++ examples, but struggle to understand them. I also need to get the array to display it. if you need more code then I will share it.
I have searched far and wide and read the spec, but I don't know how to approach this. If anyone could help me, I would be very grateful.
Regards.
The .NET does not support PCX images natively, you have two choices. Read the specification and decode the image by yourself or use some library.
As suggested on bytes.com you can use Dot Net Fireball (a Free Image wrapper) and load the image like this:
Fireball.Drawing.FreeImage freeImage = new FreeImage(#"c:\test.pcx");
Image image = freeImage.GetBitmap();
http://magick.codeplex.com/
a nice wrapper working with http://imagemagick.codeplex.com/
easy to setup and get going, see samples at the bottom of the page here:
http://magick.codeplex.com/documentation

.NET Tiff Issues C#

I'm having issues with TIFFs
Here is what I have to do, we have tiff images saved into the database, these images are CCITT4 compressed with a number of required tags, these include:
RowsPerStrip must be the ImageLength
Photometric Interpreation must be MinIsWhite
Multi-strip image format is not allowed
My problem is, I'm using the built in System.Drawing.Bitmap/Image objects, which happen to change the values of these when I put it into the object, I've tested this by saving the byte[] to a tiff directly from the database, checked the tags, they are fine.. but when i put the bytes into an Image object then save to file, they are modified.
To make things worse, I'm needing to add a text to the image before saving it.
So I need a component that will allow me more control with TIFF (and they must be tiff), and be able to add text to an image or be able to use the Graphics object.
I've tried using LibTiff but I have yet to see any examples on how to use this component,
any suggestions?
You can use our free and open-source LibTiff.Net library for this. It is freely available for all uses under a BSD license. The just released version 2.0 contains good documentation and number of samples.
There are samples that show how to convert any non-tiled TIFF image to the TIFF image which have all data written in a single strip and how to convert a System.Drawing.Bitmap to 1-bit CCITT single strip TIFF image.
I have never used the built int System.Drawing.Bitmap objects to do this. I personally use LeadTools, but it isn't free. It is however a robust and fairly straightforward API. I primarily use it for GEOTiff which contain specific data tags for image location data.
There is a 60 day evaluation if you would like to try it out.
I use FreeImage. There's a C# .NET wrapper available too.
The IEvolution component set from HiComponents is now totally free (no source) - http://www.hicomponents.com. A very powerful .NET imaging toolkit.

How to load .dds files into a picturebox?

How do I load .dds texture files as an Image in C#? There's nothing useful on google that I could find.
The more information with samples you give me,the better it will be for me to understand it.
I had the same issue. Here is a good solution.
Source: http://www.mastropaolo.com/devildotnet/
Download Version 1.3 from that link (bottom of page)
Add the Devil.NET.dll as a reference to your application
Use the code that I have supplied below.
PictureBox1.Image = DevIL.DevIL.LoadBitmap(DDS_File_Path)
It's really that easy. We owe the DevIL .NET Wrapper creator a beer.
I think the short answer is that you don't. The documentation says that the supported formats are BMP, GIF, EXIG, JPG, PNG and TIFF.
Update: there seem to be a number of converters to be found through Google, that might help you out. Also, as Wayne suggests, look at XNA (if you didn't already). The Texture2D.FromFile method seems to handle the .dds files, but I never used it myself so I can't say if it is what you are looking for or not...
You might want to take a look at the Microsoft's XNA Game Studio SDK to load the textures in memory and possibly capture the images in a System.Drawing.Graphics usable way.

Categories

Resources